-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvizzy2txt.py
More file actions
297 lines (264 loc) · 8.97 KB
/
vizzy2txt.py
File metadata and controls
297 lines (264 loc) · 8.97 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import os
import xml.etree.ElementTree as ET
#import ply.lex as lex
#import ply.yacc as yacc
#lexer = lex.lex
#yaccer = yacc.yacc
#print(lexer)
#from lark import Lark
print(os.getcwd())
# Default Vizzy program location.
#vizzyProgramFileDirectory = os.path.expanduser(
# '~') + "/KFTRWI/Android/data/com.jundroo.SimpleRockets2/files/UserData/FlightPrograms/"
vizzyProgramFileDirectory = "/storage/emulated/0/Android/data/com.jundroo.SimpleRockets2/files/UserData/FlightPrograms/"
vizzyProgramName = "parsethis"
# Get Vizzy program name
while len(vizzyProgramName) == 0:
vizzyProgramName = input(
"Please enter the name of the Vizzy program (do not include .xml). \n")
vizzyFile = vizzyProgramFileDirectory + vizzyProgramName + ".xml"
print("Printing out " + vizzyFile)
#vizzyProgram = open(vizzyProgramDirectory, "r").readlines()
#print(vizzyProgram)
#buf = ""
#for line in vizzyProgram:
# buf = buf + line
# line = line.rstrip()
# print(line)
# Creates output directory
try:
# outputPath = str(os.path.expanduser(
# '~')) + "\\AppData\\LocalLow\\Jundroo\\SimpleRockets 2\\Text-Based-Vizzy\\DecimpiledPrograms"
outputPath = "/storage/emulated/0/Download/vizzy"
if os.path.exists(outputPath):
print("output exists")
else:
os.makedirs(outputPath)
except OSError:
print("Creation of the output directory %s failed" % outputPath)
quit()
# Creates output file
#outputFile = open(outputPath + "/" + vizzyProgramName + ".vizzy", "w")
def parseXML(infile):
tree = ET.parse(infile)
root = tree.getroot()
# print(root)
# print(root.tag)
# print(root.attrib)
deep(root,root,0,"","","")
def deep(node, parent, depth, highstyle, highformat, highcall):
if depth>888: return
# if node.tag in separate:
# print("================================")
# print(" "*depth + "[" + node.tag + "]")
# else:
# if node.tag in blocktypes:
# print(" "*depth + "[" + node.tag + "]")
tees[node.tag] = 1
instyle = ""
informat = ""
incall = ""
if (node.tag in ["Variables","Variable","Items","Instructions","Expressions"]):
print(node.tag + " >>> " + "".join(f'{k}: {v}, ' for k,v in node.attrib.items()))
# if ( ("pos" in node.attrib.keys()) ):
# print(node.tag + " >>> " + "".join(f'{k}: {v}, ' for k,v in node.attrib.items()))
for att in node.attrib:
if (att == "style"): instyle = node.attrib[att]
else:
if (att == "format"): informat = node.attrib[att]
else:
if (att == "call"): incall = node.attrib[att]
if ( ("style" in node.attrib.keys()) ):
if (not(node.attrib["style"] in inpstructs["styles"].keys())):
inpstructs["styles"][node.attrib["style"]] = {"tag": node.tag, "attribs": node.attrib}
# functions
if ( ("function" in node.attrib.keys()) ):
print(node.tag + " " + node.attrib["style"] + " " + "".join(f'{k}: {v}, ' for k,v in node.attrib.items()))
if (not(node.tag in inpstructs["fns"].keys())):
inpstructs["fns"][node.tag] = {}
if (not(node.attrib["style"] in inpstructs["fns"][node.tag].keys())):
inpstructs["fns"][node.tag][node.attrib["function"] + ":" + node.attrib["style"]] = "".join(f'{k}: {v}, ' for k,v in node.attrib.items())
# custom instructions
elif ( ("callFormat" in node.attrib.keys()) ):
print(node.tag + " " + node.attrib["style"] + " " + "".join(f'{k}: {v}, ' for k,v in node.attrib.items()))
if (not(node.tag in inpstructs["custinstrs"].keys())):
inpstructs["custinstrs"][node.tag] = {}
if (not(node.attrib["style"] in inpstructs["custinstrs"].keys())):
inpstructs["custinstrs"][node.tag][node.attrib["name"] + ":" + node.attrib["style"]] = "".join(f'{k}: {v}, ' for k,v in node.attrib.items())
# other
else:
if ( (node.attrib["style"].startswith("op-")) or ("-op-" in node.attrib["style"]) ):
if (not(node.tag in inpstructs["ops"].keys())):
inpstructs["ops"][node.tag] = {}
if (not(node.attrib["style"] in inpstructs["ops"][node.tag].keys())):
if ("op" in node.attrib.keys()):
inpstructs["ops"][node.tag][node.attrib["op"] + ":" + node.attrib["style"]] = "".join(f'{k}: {v}, ' for k,v in node.attrib.items())
else:
inpstructs["ops"][node.tag][node.attrib["style"]+ "__:" + node.attrib["style"]] = "".join(f'{k}: {v}, ' for k,v in node.attrib.items())
for ch in node:
deep(ch,node,depth+1,instyle,informat,incall)
separate = {"Event":1,"CustomInstruction":1,"CustomExpression":1}
ownline = {
"Comment": 1,
"UserInput": 1,
"WaitUntil": 1,
"WaitSeconds": 1,
"SetTarget": 1,
"Repeat": 1,
"If": 1,
"ElseIf":1,
"Else":1,
"While":1,
"For":1,
"Not":1,
"Break":1,
"SetVariable":1,
"ChangeVariable":1,
"DisplayMessage":1,
"LogMessage":1,
"LogFlight":1,
"SetInput":1,
"SetTargetHeading":1,
"LockNavSphere":1,
"SetTimeMode":1,
"SetCameraProperty":1,
"SetCraftProperty":1,
"SwitchCraft":1,
"ListOp":1,
"SetList":1,
"BroadcastMessage":1,
"CallCustomInstruction":1,
"SetActivationGroup":1,
}
blocktypes = {
"Variable": 1,
"Event": 1,
"Comment": 1,
"UserInput": 1,
"WaitUntil": 1,
"WaitSeconds": 1,
"SetTarget": 1,
"Repeat": 1,
"If": 1,
"ElseIf":1,
"Else":1,
"While":1,
"For":1,
"Not":1,
"Break":1,
"Constant":1,
"Comparison":1,
"CallCustomExpression":1,
"SetVariable":1,
"BinaryOp":1,
"ChangeVariable":1,
"DisplayMessage":1,
"LogMessage":1,
"BoolOp":1,
"StringOp":1,
"MathFunction":1,
"LogFlight":1,
"Conditional":1,
"CraftProperty":1,
"Vector":1,
"VectorOp":1,
"EvaluateExpression":1,
"ActivationGroup":1,
"Planet":1,
"SetInput":1,
"SetTargetHeading":1,
"LockNavSphere":1,
"SetTimeMode":1,
"SetCameraProperty":1,
"SetCraftProperty":1,
"SwitchCraft":1,
"ListOp":1,
"SetList":1,
"BroadcastMessage":1,
"CallCustomInstruction":1,
"SetActivationGroup":1,
"CustomInstruction":1,
"CustomExpression":1,
}
tees = {}
inpstructs = {
"fns": {},
"ops": {},
"vars": {},
"items": {},
"custinstrs": {},
"custexprs": {},
"exprs": {},
"styles": {},
}
def main():
parseXML(vizzyFile)
# for t in tees.keys():
# if t not in blocktypes:
# print(' "'+t+'":1,')
# print("ops = {")
# for t in ops.keys():
# print(' "'+t+'":{')
# for u in ops[t].keys():
# print(' "'+u+'": ' + ops[t][u])
# print(" }")
# print("}")
# print("fns = {")
# for t in fns.keys():
# print(' "'+t+'":{')
# for u in fns[t].keys():
# print(' "'+u+'": ' + fns[t][u])
# print(" }")
# print("}")
# print("styles = {")
# for t in styles.keys():
# print(' "'+t+'":{')
# for u in styles[t].keys():
# if ( isinstance(styles[t][u], dict) ):
# print(' "'+u+'": {')
# for v in styles[t][u].keys():
# print(' "'+v+'": ' + styles[t][u][v] + ',')
# print(" },")
# else:
# print(' "'+u+'": ' + styles[t][u] + ',')
# print(" }")
# print("}")
prtstructs("styles")
prtstructs("ops")
prtstructs("fns")
prtstructs("custinstrs")
print("unfound:")
for t in blocktypes.keys():
found = 0
for u in inpstructs["styles"].keys():
if (inpstructs["styles"][u]["tag"] == t):
found = 1
break
if (found == 0):
print(t)
# print(' "'+u+'": ' + styles[t][u] + ' >> ' + "".join(f'{k}: {v}, ' for k,v in styles[t]["attribs"].items()))
def prtstructs(structname):
print(structname + " = {")
struct = inpstructs[structname]
for t in struct.keys():
print(' "'+t+'":{')
for u in struct[t].keys():
if ( isinstance(struct[t][u], dict) ):
print(' "'+u+'": {')
for v in struct[t][u].keys():
print(' "' + v + '": "' + struct[t][u][v] + '",')
print(" },")
else:
print(' "'+u+'": "' + struct[t][u] + '",')
print(" }")
print("}")
main()
# ProgramFlow(Instruction): # The blue blocks
# CraftInstructions(Instruction): # The black blocks
# Events(Instruction): # The yellow blocks
# Lists(Instruction): # The purple blocks
# MultifunctionDisplay(Instruction): # The light blue blocks
# Expression:
# Operators(Expression): # The blue capsules
# CraftInformation(Expression): # The black capsules
# ListExpressions(Expression): # The purple capsules