-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_sprites.py
122 lines (106 loc) · 2.89 KB
/
build_sprites.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from blend import *
from string import Template
import os
sub_file = "src/spritesets.pynml"
with open(sub_file, "r") as f:
sub_string = f.read()
files_to_blend = [
"gfx/platform/wood.png",
# "gfx/platform/tiles.png",
"gfx/platform/cement.png",
]
init_dict = {_:_ for _ in range(256)}
recolour_substitutes = {
"cement": {
"target": "cement",
"mode": "amend",
"era1": {**init_dict.copy(), **{
0x40: 0x07,
0x41: 0x08,
0x42: 0x08,
}},
"era2": {**init_dict.copy(), **{
0x40: 0x0B,
0x41: 0x0C,
0x42: 0x0D,
}},
"era3": init_dict.copy()
},
"wood": {
"target": "wood",
"mode": "amend",
"era1": init_dict.copy(),
"era2": init_dict.copy(),
"era3": init_dict.copy()
},
"asphalt": {
"target": "cement",
"mode": "new",
"era1": {**init_dict.copy(), **{
0x40: 16,
0x41: 17,
0x42: 17,
7: 16,
8: 17,
9: 18,
10: 19,
}},
"era2": {**init_dict.copy(), **{
0x40: 21,
0x41: 22,
0x42: 23,
7: 16,
8: 17,
9: 18,
10: 19,
}},
"era3": {**init_dict.copy(), **{
0x40: 0x40,
0x41: 0x41,
0x42: 0x42,
7: 16,
8: 17,
9: 18,
10: 19,
}}
},
"tiles": {
"target": "cement",
"mode": "new",
"era1": init_dict.copy(),
"era2": init_dict.copy(),
"era3": init_dict.copy()
}
}
final_image, palette, recolour_sprites = process_image(files_to_blend)
write_image("gfx/platform/real.png", final_image, palette)
new_recoulour_sprites = recolour_substitutes.copy()
"""
dict = {
"this": {
"era1": {},
"era2": {},
"era3": {}
}
}
"""
for key, val in recolour_substitutes.items():
deep_dict = val # dict's pizza
target_sprite = None
for dkey, dsprite in recolour_sprites.items():
if deep_dict["target"] in dkey:
target_sprite = dsprite
break
for i in ("era1", "era2", "era3"):
new_recoulour_sprites[key][i] = gen_recolour_sprite(deep_dict[i], target_sprite)
recolour_strings = {}
for key in recolour_substitutes.keys():
recolour_strings[key] = ""
for key, val in new_recoulour_sprites.items():
local_string = format_recolour_data({"era1":val["era1"], "era2":val["era2"], "era3":val["era3"]})
recolour_strings[key] += "".join([value for value in local_string.values()])
template_string = sub_string
my_template = Template(template_string)
out_file = my_template.substitute({f"recolour_{key}": val for key, val in {**recolour_strings}.items()})
with open("src/spritesets.pnml", "w+") as f:
f.write(out_file)