summaryrefslogtreecommitdiff
path: root/tools/gendata.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-11-22 01:55:38 +0100
committerTor Andersson <tor@ccxvii.net>2024-01-08 16:36:47 +0100
commitb2c68b84481e4393fd13d78184318bbe22ff427c (patch)
tree214a3baf9e01ea171d69331355b72ab360753eda /tools/gendata.js
parent95b90a9b4c21d6fd0805177d5193a8a62fa217ad (diff)
downloadtable-battles-b2c68b84481e4393fd13d78184318bbe22ff427c.tar.gz
lotsa stuff
Diffstat (limited to 'tools/gendata.js')
-rw-r--r--tools/gendata.js253
1 files changed, 233 insertions, 20 deletions
diff --git a/tools/gendata.js b/tools/gendata.js
index 764f011..d1c6e1b 100644
--- a/tools/gendata.js
+++ b/tools/gendata.js
@@ -1,27 +1,35 @@
const fs = require("fs")
const { parse } = require("csv-parse/sync")
-var card_buffer = fs.readFileSync("tools/cards.csv", "utf-8")
-var card_records = parse(card_buffer, { columns: true, skip_empty_lines: true })
-
-// console.log(card_records)
+var card_records = parse(fs.readFileSync("tools/cards.csv", "utf-8"), { columns: true, records_with_empty_values: true })
+var scenario_records = parse(fs.readFileSync("tools/scenarios.csv", "utf-8"), { columns: true, skip_records_with_empty_values: true })
var result = [
`<!doctype html>
+<html lang="en">
+<head>
<title>Table Battle Cards</title>
<link rel="stylesheet" href="/fonts/fonts.css">
<link rel="stylesheet" href="/table-battles/cards.css">
<style>
-body{background-color:silver;max-width:1600px;margin:0 auto;padding:20px;background-image:url(../texture.png)}
+body{background-color:dimgray;color:whitesmoke;max-width:1600px;margin:0 auto;padding:20px;background-image:url(../background.png)}
+h1{color: white}
.list{display:flex;flex-wrap:wrap;gap:20px;}
</style>
+</head>
+<body>
<div>`
]
-for (let c of card_records) {
- if (!c.scenario)
- continue
+const WING = { red: 0, pink: 1, blue: 2, dkblue: 3 }
+const WING_ICON = [ "\u2666", "\u2665", "\u2663", "\u2660" ]
+
+var cards = [ ]
+var card_index = {}
+var cards_show = [ ]
+var scenarios = []
+for (let c of card_records) {
if (!c.number) {
result.push(`</div><h2>${c.scenario}</h2><div class="list">`)
continue
@@ -30,24 +38,63 @@ for (let c of card_records) {
if (!c.name)
continue
- if (c.strength.endsWith("*")) {
- c.strength = parseInt(c.strength)
- c.star = true
+ let card = {
+ scenario: parseInt(c.scenario),
+ number: c.number,
+ name: c.name,
+ wing: WING[c.wing],
+ }
+
+ card_index[c.number] = cards.length
+
+ cards.push(card)
+
+ if (c.strength === "I") {
+ card.special = 1
+ }
+ else if (c.strength === "II") {
+ card.special = 2
+ }
+ else if (c.strength === "III") {
+ card.special = 3
}
+ else if (c.strength.endsWith("*")) {
+ card.strength = parseInt(c.strength)
+ card.star = 1
+ }
+ else {
+ card.strength = parseInt(c.strength)
+ }
+
+ card.dice = c.dice
+ card.actions = []
- result.push(`<div class="card">`)
- result.push(`<div class="formation ${c.wing}">${c.name}</div>`)
- if (c.strength)
+ result.push(`<div class="formation card">`)
+ result.push(`<div class="name ${c.wing}">${c.name}</div>`)
+
+ if (card.strength)
+ result.push(`<div class="strength">${card.strength}</div>`)
+ else
result.push(`<div class="strength">${c.strength}</div>`)
+
if (c.dice) {
- if (c.star)
+ if (card.star)
result.push(`<div class="dice_area">${c.dice}<div class="star">&#x2605;</div></div>`)
else
result.push(`<div class="dice_area">${c.dice}</div>`)
}
+ function make_action(type, requirement, target, effect) {
+ let a = { type }
+ if (requirement) a.requirement = requirement
+ if (target) a.target = target
+ if (effect) a.effect = effect
+ return a
+ }
+
if (c.action1_type) {
+ card.actions.push(make_action(c.action1_type, c.action1_req, c.action1_target, c.action1_effect))
result.push(`<div class="action_row">`)
result.push(`<div class="action_type">${c.action1_type}</div>`)
result.push(`<div class="action_requirement">${c.action1_req}</div>`)
@@ -58,6 +105,7 @@ for (let c of card_records) {
}
if (c.action2_type || c.action2_effect) {
+ card.actions.push(make_action(c.action2_type, c.action2_req, c.action2_target, c.action2_effect))
result.push(`<div class="action_row">`)
result.push(`<div class="action_type reaction">${c.action2_type}</div>`)
result.push(`<div class="action_requirement">${c.action2_req}</div>`)
@@ -67,20 +115,185 @@ for (let c of card_records) {
result.push(`</div>`)
}
- if (c.flavor)
- result.push(`<div class="flavor">${c.flavor}</div>`)
+ if (c.rule)
+ card.rule = c.rule_tag
+
+ if (c.rule_text) {
+ card.rule_text = c.rule_text
+ result.push(`<div class="rule_text">${c.rule_text}</div>`)
+ }
+
+ if (c.lore_text) {
+ card.lore_text = c.lore_text
+ result.push(`<div class="lore_text">${c.lore_text}</div>`)
+ }
if (c.reserve) {
+ if (c.reserve === "RETIRE")
+ card.retire = 1
+ else if (c.reserve === "PURSUIT")
+ card.pursuit = 1
+ else if (c.reserve === "Commanded")
+ card.reserve = []
+ else
+ card.reserve = c.reserve.split(" or ")
+
if (c.reserve === "RETIRE" || c.reserve === "PURSUIT")
result.push(`<div class="reserve">${c.reserve}</div>`)
else
result.push(`<div class="reserve">IN RESERVE (${c.reserve})</div>`)
}
- result.push(`<div class="card_number">${c.number}</div>`)
- result.push(`<div class="wing_name">${c.wing}</div>`)
+ result.push(`<div class="number">${c.number}</div>`)
+ result.push(`<div class="extra">${WING_ICON[card.wing]}</div>`)
result.push(`</div>`)
}
-console.log(result.join("\n"))
+function find_card(scenario, name) {
+ name = name.replace(" out of reserve", "")
+ for (let c of cards)
+ if (c.scenario === scenario && c.name === name)
+ return card_index[c.number]
+ throw new Error("CARD NOT FOUND: " + scenario + " " + name)
+}
+
+function find_enemy_cards(scenario, wing) {
+ let w1, w2
+ if (wing === 0 || wing === 1)
+ w1 = 2, w2 = 3
+ if (wing === 2 || wing === 3)
+ w1 = 0, w2 = 1
+ let list = []
+ for (let c of cards)
+ if (c.scenario === scenario && (c.wing === w1 || c.wing === w2))
+ list.push(card_index[c.number])
+ return list
+}
+
+function find_friendly_cards(scenario, wing) {
+ let w1, w2
+ if (wing === 0 || wing === 1)
+ w1 = 0, w2 = 1
+ if (wing === 2 || wing === 3)
+ w1 = 2, w2 = 3
+ let list = []
+ for (let c of cards)
+ if (c.scenario === scenario && (c.wing === w1 || c.wing === w1))
+ list.push(card_index[c.number])
+ return list
+}
+
+function find_wing_cards(scenario, wing) {
+ let list = []
+ for (let c of cards)
+ if (c.scenario === scenario && c.wing === wing)
+ list.push(card_index[c.number])
+ return list
+}
+
+/* process action and reserve targets */
+for (let c of cards) {
+ for (let a of c.actions) {
+ if (a.target) {
+ if (a.target === "Any enemy attack" || a.target === "Any enemy formation")
+ a.target_list = find_enemy_cards(c.scenario, c.wing)
+ else if (a.target === "Any friendly formation")
+ a.target_list = find_friendly_cards(c.scenario, c.wing)
+ else if (a.target === "Any friendly Pink formation")
+ a.target_list = find_wing_cards(c.scenario, WING.pink)
+ else
+ a.target_list = a.target.split(", ").map(name => find_card(c.scenario, name))
+ }
+ }
+ if (c.reserve)
+ c.reserve = c.reserve.map(name => find_card(c.scenario, name))
+}
+
+fs.writeFileSync("info/all-cards.html", result.join("\n"))
+
+result = [
+`<!doctype html>
+<html lang="en">
+<head>
+<title>Table Battle Cards</title>
+<link rel="stylesheet" href="/fonts/fonts.css">
+<link rel="stylesheet" href="/table-battles/cards.css">
+<style>
+body{background-color:dimgray;color:whitesmoke;max-width:1600px;margin:0 auto;padding:20px;background-image:url(../background.png)}
+.list{display:flex;flex-wrap:wrap;gap:20px;}
+</style>
+</head>
+<body>
+<div class="list">`
+]
+
+function parse_cards(text) {
+ let out = []
+ let list = text.split(",")
+ for (let range of list) {
+ let [a, b] = range.split("-")
+ a = card_index[a]
+ b = card_index[b]
+ if (a === undefined || b === undefined)
+ throw new Error("MISSING CARDS FOR " + text)
+ for (let i = a; i <= b; ++i)
+ out.push(i)
+ }
+ return out
+}
+
+let last_exp = null
+for (let s of scenario_records) {
+ if (!s.name)
+ continue
+ if (last_exp !== s.expansion) {
+ result.push(`</div><h1>${s.expansion}</h1><div class="list">`)
+ last_exp = s.expansion
+ }
+ try {
+ scenarios.push({
+ number: parseInt(s.number),
+ name: s.name,
+ date: s.date,
+ players: [
+ { name: s.player1, cards: parse_cards(s.cards1), morale: parseInt(s.morale1) },
+ { name: s.player2, cards: parse_cards(s.cards2), morale: parseInt(s.morale2) },
+ ],
+ rule: s.rule || undefined
+ })
+ result.push(`
+ <div class="scenario card">
+ <div class="scenario_title">
+ <div class="battle_name">${s.name}</div>
+ <div class="battle_date">${s.date}</div>
+ </div>
+ <div class="scenario_player">
+ <div class="scenario_player_name">${s.player1}</div>
+ <div class="scenario_cards">Cards ${s.cards1}</div>
+ <div class="scenario_morale">Morale: ${s.morale1}</div>
+ </div>
+ <div class="scenario_player">
+ <div class="scenario_player_name">${s.player2}</div>
+ <div class="scenario_cards">Cards ${s.cards2}</div>
+ <div class="scenario_morale">Morale: ${s.morale2}</div>
+ </div>
+ <div class="rule_text">${s.rule_text}</div>
+ <div class="lore_text">${s.lore_text}</div>
+ <div class="number">${s.number}</div>
+ </div>
+ `)
+ } catch (err) {
+ console.log(err)
+ }
+}
+
+fs.writeFileSync("info/scenarios.html", result.join("\n"))
+
+result = []
+result.push("const data = {")
+result.push("scenarios: " + JSON.stringify(scenarios,0,"\t") + ",")
+result.push("cards: " + JSON.stringify(cards,0,"\t") + ",")
+result.push("}")
+result.push("if (typeof module!=='undefined') module.exports = data")
+fs.writeFileSync("data.js", result.join("\n"))