summaryrefslogtreecommitdiff
path: root/tools/gendata.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-11-20 02:58:24 +0100
committerTor Andersson <tor@ccxvii.net>2024-01-08 16:36:47 +0100
commit95b90a9b4c21d6fd0805177d5193a8a62fa217ad (patch)
treecbbe969cf9b3e392da9ee80e4e67192885a33192 /tools/gendata.js
parentea85d06093090d417d60a01e3bbe637931c4544d (diff)
downloadtable-battles-95b90a9b4c21d6fd0805177d5193a8a62fa217ad.tar.gz
data processing
Diffstat (limited to 'tools/gendata.js')
-rw-r--r--tools/gendata.js86
1 files changed, 86 insertions, 0 deletions
diff --git a/tools/gendata.js b/tools/gendata.js
new file mode 100644
index 0000000..764f011
--- /dev/null
+++ b/tools/gendata.js
@@ -0,0 +1,86 @@
+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 result = [
+`<!doctype html>
+<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)}
+.list{display:flex;flex-wrap:wrap;gap:20px;}
+</style>
+<div>`
+]
+
+for (let c of card_records) {
+ if (!c.scenario)
+ continue
+
+ if (!c.number) {
+ result.push(`</div><h2>${c.scenario}</h2><div class="list">`)
+ continue
+ }
+
+ if (!c.name)
+ continue
+
+ if (c.strength.endsWith("*")) {
+ c.strength = parseInt(c.strength)
+ c.star = true
+ }
+
+ result.push(`<div class="card">`)
+ result.push(`<div class="formation ${c.wing}">${c.name}</div>`)
+ if (c.strength)
+ result.push(`<div class="strength">${c.strength}</div>`)
+
+ if (c.dice) {
+ if (c.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>`)
+ }
+
+ if (c.action1_type) {
+ 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>`)
+ result.push(`<div class="action_target">${c.action1_target}</div>`)
+ if (c.action1_effect)
+ result.push(`<div class="action_effect">${c.action1_effect}</div>`)
+ result.push(`</div>`)
+ }
+
+ if (c.action2_type || 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>`)
+ result.push(`<div class="action_target">${c.action2_target}</div>`)
+ if (c.action2_effect)
+ result.push(`<div class="action_effect">${c.action2_effect}</div>`)
+ result.push(`</div>`)
+ }
+
+ if (c.flavor)
+ result.push(`<div class="flavor">${c.flavor}</div>`)
+
+ if (c.reserve) {
+ 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>`)
+}
+
+console.log(result.join("\n"))