-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_physics.py
executable file
·125 lines (113 loc) · 3.81 KB
/
find_physics.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
123
124
125
#!/usr/bin/python3
import re
import sys
map_name = sys.argv[1]
#print("Paste the arg1.setTileProperties() calls now:")
text = sys.stdin.read()
pattern = (
# simple version
r'arg1\.setTileProperties\((\d+), (.*?)(?:, (.*?)(?:, (.*?)(?:, (.*?))?)?)?\)' + '|' +
# for loop version
r'loc1 = (\d+);\s+' +
r'while \(loc1 < (\d+)\)\s+\{\s+' +
r'arg1\.setTileProperties\(loc1, (.*?)(?:, (.*?)(?:, (.*?))?)?\);\s+' +
r'\+\+loc1;\s+' +
r'}'
)
matches = re.findall(pattern, text)
sanity_matches = re.findall('setTileProperties', text)
if len(matches) != len(sanity_matches):
sys.exit("ERROR: regex didn't match everything")
#print("\n".join(repr(x) for x in matches));
conveyer_data = {
"REDCAVE": {16: ">", 17: "v", 18: "<", 19: "^", 20: "w", 26: "w", 28: "w"},
"TERMINAL": " ",
"GO": {130: "w", 194: "w"}, # default leave it alone
"APARTMENT": {206: "w", 231: "w"}, # default leave it alone
"FIELDS": {250: "w", 270: ">", 271: "v", 272: "<", 273: "^"},
"BEACH": " ",
"HOTEL": {180: ">", 181: "v", 182: "<", 183: "^", 131: "w"},
"CIRCUS": {110: "w", 111: ">", 112: "v", 113: "<", 114: "^"},
"FOREST": {110: "w", 134: ">", 135: "v", 136: "<", 137: "^"},
"WINDMILL": " ",
}
conveyer_data["DEBUG"] = conveyer_data["REDCAVE"]
conveyer_overrides = conveyer_data.get(map_name, {})
physics = {0: " "}
for match in matches:
if match[0] != "":
# simple version
start = int(match[0])
collision_flags = match[1]
callback = match[2]
entity_filter = match[3]
end = start + int(match[4] or "1")
else:
# for loop version
start = int(match[5])
end = int(match[6])
collision_flags = match[7]
callback = match[8]
entity_filter = match[9]
if collision_flags == "org.flixel.FlxObject.NONE":
char_code = " "
elif collision_flags == "org.flixel.FlxObject.ANY":
char_code = "#"
elif collision_flags == "org.flixel.FlxObject.LEFT":
char_code = "5"
elif collision_flags == "org.flixel.FlxObject.UP":
char_code = "6"
elif collision_flags == "org.flixel.FlxObject.RIGHT":
char_code = "7"
elif collision_flags == "org.flixel.FlxObject.DOWN":
char_code = "8"
else:
print("WARNING: unknown collision_flags: {}".format(repr(collision_flags)))
continue
if callback in ("", "null"):
pass
elif callback == "ladder":
assert(char_code == " ")
char_code = "l"
elif callback == "data.TileData.slow":
assert(char_code == " ")
char_code = ","
elif callback in ("hole", "data.TileData.hole"):
assert(char_code == " ")
char_code = "h"
elif callback == "data.TileData.thin_left":
assert(char_code == " ")
char_code = "1"
elif callback == "data.TileData.thin_up":
assert(char_code == " ")
char_code = "2"
elif callback == "data.TileData.thin_right":
assert(char_code == " ")
char_code = "3"
elif callback == "data.TileData.thin_down":
assert(char_code == " ")
char_code = "4"
elif callback in ("data.TileData.conveyer", "conveyer"):
assert(char_code == " ")
if conveyer_overrides != " ":
char_code = "w"
elif callback in ("data.TileData.spike", "spike"):
assert(char_code == " ")
if map_name == "REDCAVE" and start == 31:
# not it's not. it's jut air.
char_code = " "
else:
char_code = "s"
else:
print("WARNING: unknown callback: {}".format(repr(callback)))
continue
if entity_filter not in ("", "null", "entity.player.Player"):
print("WARNING: unknown entity_filter: {}".format(repr(entity_filter)))
for i in range(start, end):
physics[i] = char_code
# these override everything else
if conveyer_overrides != " ":
for tile_index, char_code in conveyer_overrides.items():
if physics.get(tile_index, "w") != "w": continue
physics[tile_index] = char_code
print('"{}"'.format("".join(physics.get(i, "#") for i in range(max(physics.keys()) + 1))))