-
Notifications
You must be signed in to change notification settings - Fork 2
/
convert_tiles.py
42 lines (37 loc) · 1.45 KB
/
convert_tiles.py
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
from PIL import Image
img = Image.open("tiles.png")
rows = [
("dot", 9),
("bamboo", 9),
("char", 9),
("honor", 7),
("bonus", 8),
]
lines = []
lines.append("@s-blank")
lines.append(" 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")
lines.append(" 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")
lines.append(" 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")
lines.append(" 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")
lines.append(" 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")
lines.append(" 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00")
for y, (row_name, tile_count) in enumerate(rows):
for x in range(tile_count):
lines.append(f"( @s-{row_name}-{x+1} )")
img.putpixel((16*x, 24*y+1), 0)
img.putpixel((16*x+15, 24*y+1), 0)
for ty in range(3):
for tx in range(2):
bs = []
for bit in [1, 2]:
for by in range(8):
byte = 0
for bx in range(8):
xx = 16*x + 8*tx + bx
yy = 24*y + 8*ty + by
if img.getpixel((xx, yy)) & bit:
byte |= 1 << 7-bx
bs.append(byte)
lines.append(" " + " ".join("%02x" % b for b in bs))
with open("tiles.tal", "w") as f:
f.write("\n".join(lines) + "\n")