-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsm_xml.py
65 lines (46 loc) · 1.7 KB
/
sm_xml.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
class XMLError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
class XML:
def __init__(self, xml_file):
self.filename = xml_file
self.xml_contents = []
self.attacks = []
self.parse_xml(xml_file)
def parse_xml(self, xml_file):
try:
xml_raw = open(xml_file, "rb").read()
except:
raise XMLError("Cannot open \"%s\"" % xml_file)
# Convert to UNIX format
xml_raw = xml_raw.replace(b"\r\n", b"\n")
xml_raw = xml_raw.replace(b"\r", b"\n")
xml_raw = xml_raw.decode()
# Create params dictionary
i = 0
i = xml_raw.find("<ActorFrame", i)
j = xml_raw.find("><children>", i+1)
self.xml_contents.append(xml_raw[:i+11])
self.xml_contents.append(xml_raw[j:])
def barf(self, LF="\r\n", mc=1, noteSkin="cybercouples", globalOffset=0.000):
s = ""
s+=self.xml_contents[0].replace("\n", "\r\n")
s+=LF
s+="InitCommand=\"%function(self)"+LF
s+="offset = PREFSMAN:GetPreference('GlobalOffsetSeconds');"+LF
s+="player = (GAMESTATE:IsPlayerEnabled(0) and 1 or 2);"+LF
for i in range(len(self.attacks)):
(a, b, c) = self.attacks[i]
s += "GAMESTATE:LaunchAttack(%.6f-offset,%.6f,'%s',player);" % (a, b, c) + LF
s+="end\""+LF
s+=self.xml_contents[1].replace("\n", "\r\n")
return s
# Static Methods
@staticmethod
def list_use_nums(ls):
new = []
for a, b in ls:
new.append((float(a), float(b)))
return new