summaryrefslogtreecommitdiff
path: root/tools/genhex.js
blob: c0e8812d5998c02e8bdc940a76e430c0bcad1fe8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// hexagonal counters with embedded image and outline

const fs = require('fs')

function print_hex(output, input, hi, lo, bd) {
	let image = fs.readFileSync(input).toString('base64')
	let svg = []

	let img_w = 50
	let img_h = 58 // 57.735

	let svg_w = img_w + 4
	let svg_h = img_h + 6

	svg.push(`<svg xmlns="http://www.w3.org/2000/svg" width="${svg_w}" height="${svg_h}">`)

	let iw = img_w / 2
	let ih = iw / Math.sqrt(3)
	let iy = (svg_h - ih * 4) / 2

	let ow = img_w / 2 + 2
	let oh = ow / Math.sqrt(3)
	let oy = (svg_h - oh * 4) / 2

	svg.push('<clipPath id="ic">')
	svg.push(`<path d="M 1 ${iy} m 0 ${3*ih} v -${2*ih} l ${iw} -${ih} l ${iw} ${ih} v ${2*ih} l -${iw} ${ih} z"/>`)
	svg.push('</clipPath>')

	svg.push('<clipPath id="oc">')
	svg.push(`<path d="M 0 ${oy} m 0 ${oh*3} v -${oh*2} l ${ow} -${oh} l ${ow} ${oh} z"/>`)
	svg.push('</clipPath>')

	svg.push(`<path fill="${bd}" d="M 0 ${oy} m 0 ${3*oh} v -${2*oh} l ${ow} -${oh} l ${ow} ${oh} v ${2*oh} l -${ow} ${oh} z"/>`)

	svg.push(`<image x="2" y="3" width="${img_w}" height="${img_h}" clip-path="url(#ic)" href="data:image/png;base64,${image}"/>`)

	svg.push(`<path fill="none" stroke="${lo}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"`)
	svg.push(`  d="M 2 ${iy} m ${2*iw} ${ih} v ${ih*2} l -${iw} ${ih} l -${iw} -${ih}"/>`)
	svg.push(`<path fill="none" stroke="${hi}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" clip-path="url(#oc)"`)
	svg.push(`  d="M 2 ${iy} m 0 ${ih*3} v -${ih*2} l ${iw} -${ih} l ${iw} ${ih}"/>`)

	svg.push('</svg>')

	fs.writeFileSync(output, svg.join("\n") + "\n")
}

print_hex("images/castra.svg", "images/castra.png", "#ffffff", "#b2b2b2", "#434343")
print_hex("images/quaestor.svg", "images/quaestor.png", "#ffffff", "#b2b2b2", "#434343")

print_hex("images/mob.svg", "images/mob.png", "#eaebc7", "#888968", "#323214")
print_hex("images/mob_x2.svg", "images/mob_x2.png", "#eaebc7", "#888968", "#323214")

print_hex("images/blue_breakaway.svg", "images/blue_breakaway.png", "#d5ffff", "#6e96b6", "#113854")
print_hex("images/blue_seat_of_power.svg", "images/blue_seat_of_power.png", "#d5ffff", "#6e96b6", "#113854")

print_hex("images/green_breakaway.svg", "images/green_breakaway.png", "#ace48f", "#568837", "#033600")
print_hex("images/green_seat_of_power.svg", "images/green_seat_of_power.png", "#ace48f", "#568837", "#033600")

print_hex("images/red_breakaway.svg", "images/red_breakaway.png", "#ff5455", "#c00000", "#680000")
print_hex("images/red_seat_of_power.svg", "images/red_seat_of_power.png", "#ff5455", "#c00000", "#680000")

print_hex("images/yellow_breakaway.svg", "images/yellow_breakaway.png", "#fffe92", "#c3a634", "#553a00")
print_hex("images/yellow_seat_of_power.svg", "images/yellow_seat_of_power.png", "#fffe92", "#c3a634", "#553a00")