-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstagebuilder.py
More file actions
executable file
·132 lines (117 loc) · 5.3 KB
/
Copy pathstagebuilder.py
File metadata and controls
executable file
·132 lines (117 loc) · 5.3 KB
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
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
"""
Description:
Converts 208x208 .png images of stages into arrays for "Stages.hpp".
Must add base manually.
Dependencies:
pillow
"""
import argparse
from PIL import Image
# Green value of pixel at grid with X offset 1: (1,0), except for ICE
# Offset is necessary because forest pixel at (0,0) is transparent.
BRICK = 7
STEEL = 174
FOREST = 79
WATER = 64
ICE = 102 # !!! at (0,0) - no offset at X
def main(file):
print("File: ", file, "\n")
forest = "Forest: \n{\n"
water = "Water: \n{\n"
ice = "Ice: \n{\n"
walls = "Walls: \n{\n"
for i in range(36):
forest += f"// Stage {i} {{{{{{2\n{{\n"
water += f"// Stage {i} {{{{{{2\n{{\n"
ice += f"// Stage {i} {{{{{{2\n{{\n"
walls += f"// Stage {i} {{{{{{2\n{{\n"
next_file = f"{file.split('_')[0]}_{str(i).zfill(2)}.png"
# Iterates through all files at directory by mask "file_*.png"
try:
with Image.open(next_file) as img:
img = img.convert("RGBA")
for y in range(13):
for x in range(13):
# Skip base
if x > 4 and x < 8 and y > 10:
continue
_, g, _, _ = img.getpixel((x * 16 + 1, y * 16)) # type:ignore
if g == FOREST:
forest += f"{y * 100 + x}, \n"
elif g == WATER:
water += f"{y * 100 + x}, \n"
elif g == STEEL:
_, g, _, _ = img.getpixel((x * 16, y * 16)) # type:ignore
if g == ICE:
ice += f"{y * 100 + x}, \n"
else:
# top left is steel
_, g, _, _ = img.getpixel((x * 16 + 8, y * 16)) # type:ignore
if g == STEEL:
# top right is steel
_, g, _, _ = img.getpixel((x * 16, y * 16 + 8)) # type:ignore
if g == STEEL:
# bottom left is steel
walls += f"{{{100 * y + x}, 7, 0}}, \n"
else:
# bottom left is empty
walls += f"{{{100 * y + x}, 5, 0}}, \n"
else:
# top right is empty
_, g, _, _ = img.getpixel((x * 16, y * 16 + 8)) # type:ignore
if g == STEEL:
# bottom left is steel
walls += f"{{{100 * y + x}, 5, 3}}, \n"
elif g == BRICK:
_, g, _, _ = img.getpixel((x * 16 + 8, y * 16)) # type:ignore
if g == BRICK:
# top right is brick
_, g, _, _ = img.getpixel((x * 16, y * 16 + 8)) # type:ignore
if g == BRICK:
# bottom left is brick
walls += f"{{{100 * y + x}, 3, 0}}, \n"
else:
# bottom left is empty
walls += f"{{{100 * y + x}, 1, 0}}, \n"
else:
# top right is empty
_, g, _, _ = img.getpixel((x * 16, y * 16 + 8)) # type:ignore
if g == BRICK:
# bottom left is brick
walls += f"{{{100 * y + x}, 1, 3}}, \n"
else:
_, g, _, _ = img.getpixel((x * 16, y * 16 + 8)) # type:ignore
if g == STEEL:
# bottom left is steel
walls += f"{{{100 * y + x}, 5, 2}}, \n"
elif g == BRICK:
# bottom left is brick
walls += f"{{{100 * y + x}, 1, 2}}, \n"
else:
_, g, _, _ = img.getpixel((x * 16 + 8, y * 16)) # type:ignore
if g == STEEL:
# top right is steel
walls += f"{{{100 * y + x}, 5, 1}}, \n"
elif g == BRICK:
# top right is brick
walls += f"{{{100 * y + x}, 1, 1}}, \n"
forest += "},\n\n"
water += "},\n\n"
ice += "},\n\n"
walls += "},\n\n"
except FileNotFoundError:
break
forest += "}\n\n"
water += "}\n\n"
ice += "}\n\n"
walls += "}\n\n"
print(forest)
print(water)
print(ice)
print(walls)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("file", type=str, help="Path to image file")
args = parser.parse_args()
main(file=args.file)