summaryrefslogtreecommitdiff
path: root/tools/genunits.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/genunits.js')
-rw-r--r--tools/genunits.js114
1 files changed, 65 insertions, 49 deletions
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(`<svg xmlns="http://www.w3.org/2000/svg" width="510" height="510" version="1.2" viewBox="0 0 510 510">
<defs>
@@ -62,9 +66,10 @@ print(`<svg xmlns="http://www.w3.org/2000/svg" width="510" height="510" version=
</symbol>
</defs>
-<g font-family="Arial,Helvetica,sans-serif" font-weight="bold">`);
+<g font-family="Arial,Helvetica,sans-serif" font-weight="bold">`)
+}
-SYMBOLS = {
+const SYMBOLS = {
"armor": `
<path fill="#ccc" stroke="#111" stroke-linejoin="round" stroke-width="1.5" d="M38.3 38.3H12.8V12.9h25.5zm0 0"/>
@@ -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(`<g transform="translate(${x},${y})">`);
-
- 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(`<use href="#cv${u.steps}e" fill="${black}"/>`);
- else
- print(`<use href="#cv${u.steps}" fill="${black}"/>`);
-
- print(`<g fill="${black}">`);
- print(`<text text-anchor="start" font-size="7" x="2" y="8">${u.appearance}</text>`);
- print(`<text text-anchor="start" font-size="7" x="2" y="48">${a}</text>`);
+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(`<g transform="translate(${x},${y})">`);
+
+ 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(`<use href="#cv${u.steps}e" fill="${black}"/>`);
+ else
+ print(`<use href="#cv${u.steps}" fill="${black}"/>`);
+
+ if (show_text) {
+ print(`<g fill="${black}">`);
+ print(`<text text-anchor="start" font-size="7" x="2" y="8">${u.appearance}</text>`);
+ print(`<text text-anchor="start" font-size="7" x="2" y="48">${a}</text>`);
+
+ if (b) {
+ if (b.length > 1) {
+ print(`<text text-anchor="end" font-size="7" x="49" y="43">${b[0]}</text>`);
+ print(`<text text-anchor="end" font-size="7" x="49" y="49">${b[1]}</text>`);
+ } else {
+ print(`<text text-anchor="end" font-size="7" x="48" y="48">${b[0]}</text>`);
+ }
+ }
+
+ print(`</g>`);
+ }
- if (b) {
- if (b.length > 1) {
- print(`<text text-anchor="end" font-size="7" x="49" y="43">${b[0]}</text>`);
- print(`<text text-anchor="end" font-size="7" x="49" y="49">${b[1]}</text>`);
- } else {
- print(`<text text-anchor="end" font-size="7" x="48" y="48">${b[0]}</text>`);
+ print(`</g>`);
+ x += 51;
+ if (x >= 510) {
+ y += 51;
+ x = 0;
}
}
-
print(`</g>`);
- print(`</g>`);
- x += 51;
- if (x >= 510) {
- y += 51;
- x = 0;
- }
+ print(`</svg>`);
+ return out.join("\n")
}
-print(`</g>`);
-print(`</svg>`);
+
+fs.writeFileSync("units.svg", print_units(true))
+fs.writeFileSync("units-simple.svg", print_units(false))