forked from Limero/mulle.js
-
Notifications
You must be signed in to change notification settings - Fork 9
/
mulle.py
186 lines (113 loc) · 3.42 KB
/
mulle.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys, getopt, struct, math
from subprocess import Popen, PIPE, STDOUT
import json
from ShockwaveParser import ShockwaveParser, CastType
#from listparser import ShockwaveListParser
rawData = {
"objects": [],
"maps": [],
"missions": [],
"parts": [],
"worlds": []
}
parsedData = {
"objects": [],
"maps": [],
"missions": [],
"parts": [],
"worlds": []
}
hashData = {
"objects": {},
"maps": {},
"missions": {},
"parts": {},
"worlds": {}
}
def addFile( p, l ):
print("add file: " + str(p) )
with open(p, "r") as data_file:
lingoList = data_file.read()
l.append( lingoList )
print("start work")
bpath = 'cst_out_new/CDDATA.CXT'
mpath = bpath + '/metadata.json'
with open(mpath) as data_file:
data = json.load( data_file )
for lib in data['libraries']:
for num in lib['members']:
mem = lib['members'][num]
fpath = bpath + "/" + lib['name'] + "/" + num + ".txt"
if mem['name'][:4] == "part":
addFile(fpath, rawData["parts"])
if mem['name'][:7] == "mission":
addFile(fpath, rawData["missions"])
if mem['name'][:6] == "object":
addFile(fpath, rawData["objects"])
if mem['name'][:3] == "map":
addFile(fpath, rawData["maps"])
if mem['name'][:5] == "world":
addFile(fpath, rawData["worlds"])
# print( rawData )
fRawOut = open( "gamedata/all_raw.json", "w")
fRawOut.write( json.dumps( rawData ) )
fRawOut.close()
for sec, data in rawData.items():
i = 1
for lingo in data:
cmd = "node node-listparser.js"
p = Popen(cmd, stdout=PIPE, stdin=PIPE, stderr=STDOUT)
grep_stdout = p.communicate( input = bytes(lingo, 'utf-8') )[0]
parsed = json.loads( grep_stdout )
parsedData[sec].append(parsed)
print( "parsed: " + str(sec) + " - " + str(i) + " (" + str( round( ( i / len(data) ) * 100 ) ) + "%)" )
i += 1
fArrayOut = open( "gamedata/" + str(sec) + ".array.json", "w")
fArrayOut.write( json.dumps( parsedData[sec] ) )
fArrayOut.close()
for parsed in parsedData[sec]:
if 'MapId' in parsed:
hashData[sec][ parsed['MapId'] ] = parsed
if 'MissionId' in parsed:
hashData[sec][ parsed['MissionId'] ] = parsed
if 'ObjectId' in parsed:
hashData[sec][ parsed['ObjectId'] ] = parsed
if 'partId' in parsed:
hashData[sec][ parsed['partId'] ] = parsed
if 'WorldId' in parsed:
hashData[sec][ parsed['WorldId'] ] = parsed
fHashOut = open( "gamedata/" + str(sec) + ".hash.json", "w")
fHashOut.write( json.dumps( hashData[sec] ) )
fHashOut.close()
fParsedOut = open( "gamedata/all_parsed.json", "w")
fParsedOut.write( json.dumps( parsedData ) )
fParsedOut.close()
print("finished")
# t = rawData['objects'][0]
# lp = ShockwaveListParser()
# print( lp.parseList( t ) )
files = ['CDDATA.CXT', '03.DXR', '04.DXR', '05.DXR', '00.CXT']
offsets = {}
for f in files:
fpath = 'cst_out_new/' + f + '/metadata.json'
with open(fpath) as data_file:
data = json.load( data_file )
# print( data )
for lib in data['libraries']:
for num in lib['members']:
mem = lib['members'][num]
if 'imageRegY' in mem:
if len(mem['name']) <= 3:
continue
if mem['name'] in offsets:
print("Collision with '" + str( mem['name'] ) + "' (" + f + ")")
offsets[ mem['name'] ] = { 'x': mem['imageRegX'], 'y': mem['imageRegY'] }
# print(mem)
# print(lib)
# print(fpath)
offOut = open( "offsets.json", "w")
offOut.write( json.dumps( offsets ) )
offOut.close()
#print(offsets)