From 4e92007e7a7e7e2c5a432ccb38f235abe67236b5 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 29 Jul 2022 13:03:47 +0200 Subject: Data arrays. --- tools/genunits.js | 114 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 49 deletions(-) (limited to 'tools/genunits.js') diff --git a/tools/genunits.js b/tools/genunits.js index 4e0f30e..820de56 100644 --- a/tools/genunits.js +++ b/tools/genunits.js @@ -1,5 +1,9 @@ -const { units } = require("../data.js"); -const print = console.log; +const fs = require('fs') +const { units } = require("../rawdata.js"); +var out = [] +function print(s) { out.push(s) } + +function print_defs() { print(` @@ -62,9 +66,10 @@ print(` -`); +`) +} -SYMBOLS = { +const SYMBOLS = { "armor": ` @@ -175,53 +180,64 @@ const BLACK = { allied: "#5c3a1e" } -let x = 0, y = 0; -for (let u of units) { - let type = TYPEMAP[u.type]; - let black = BLACK[u.nationality]; - let fill = COLORMAP[u.nationality]; - - let [a, b] = u.name.split('/'); - if (b) - b = b.split('+'); - - for (let n in COLORMAP) - if (a.endsWith(n) || (b && b[0] === n)) - fill = COLORMAP[n]; - - print(``); - - if (type === 'armor' && u.elite && u.nationality === 'allied') - type = 'armor_elite'; - - let symbol = SYMBOLS[type]; - print(symbol.replace(/#ccc/g, fill).replace(/#111/g, black).trim()); - - if (u.elite) - print(``); - else - print(``); - - print(``); - print(`${u.appearance}`); - print(`${a}`); +function print_units(show_text) { + out = [] + print_defs() + let x = 0, y = 0; + for (let u of units) { + let type = TYPEMAP[u.type]; + let black = BLACK[u.nationality]; + let fill = COLORMAP[u.nationality]; + + let [a, b] = u.name.split('/'); + if (b) + b = b.split('+'); + + for (let n in COLORMAP) + if (a.endsWith(n) || (b && b[0] === n)) + fill = COLORMAP[n]; + + print(``); + + if (type === 'armor' && u.elite && u.nationality === 'allied') + type = 'armor_elite'; + + let symbol = SYMBOLS[type]; + print(symbol.replace(/#ccc/g, fill).replace(/#111/g, black).trim()); + + if (u.elite) + print(``); + else + print(``); + + if (show_text) { + print(``); + print(`${u.appearance}`); + print(`${a}`); + + if (b) { + if (b.length > 1) { + print(`${b[0]}`); + print(`${b[1]}`); + } else { + print(`${b[0]}`); + } + } + + print(``); + } - if (b) { - if (b.length > 1) { - print(`${b[0]}`); - print(`${b[1]}`); - } else { - print(`${b[0]}`); + print(``); + x += 51; + if (x >= 510) { + y += 51; + x = 0; } } - print(``); - print(``); - x += 51; - if (x >= 510) { - y += 51; - x = 0; - } + print(``); + return out.join("\n") } -print(``); -print(``); + +fs.writeFileSync("units.svg", print_units(true)) +fs.writeFileSync("units-simple.svg", print_units(false)) -- cgit v1.2.3