-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathnew_fighter_param.py
executable file
·53 lines (43 loc) · 1.59 KB
/
new_fighter_param.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
#!/usr/bin/python3.9
from os import write
from xml import etree
import xml.etree.ElementTree as ET
import xml.dom.minidom
import pathlib
import sys, getopt
path = pathlib.Path(__file__).parent.parent.resolve()
romfs_src_path = path.joinpath("romfs/source")
if len(sys.argv) < 2:
print('new_fighter_param.py -t <param_type> -d <default_value> <param_name>')
sys.exit(2)
try:
opts, args = getopt.getopt(sys.argv[1::], "ht:d:", ["type=", "default="])
except getopt.GetoptError:
print('new_fighter_param.py -t <param_type> -d <default_value> <param_name>')
sys.exit(2)
p_type = None
p_value = None
for o, a in opts:
if o == 'h':
print('new_fighter_param.py -t <param_type> -d <default_value> <param_name>')
sys.exit()
elif o in ('-t', '--type'):
p_type = a
elif o in ('-d', '--default'):
p_value = a
if p_type == None or p_value == None:
print('new_fighter_param.py -t <param_type> -d <default_value> <param_name>')
sys.exit(2)
if len(args) == 0:
print('new_fighter_param.py -t <param_type> -d <default_value> <param_name>')
sys.exit(2)
param_name = args[0]
tree = ET.parse(romfs_src_path.joinpath("fighter/common/hdr/param/fighter_param.xml"))
root = tree.getroot()
fighter_param_table = root[0]
for i in range(0, int(fighter_param_table.attrib.get("size"))):
new_el = ET.Element(p_type, {"hash": param_name})
new_el.text = p_value
fighter_param_table[i].append(new_el)
ET.indent(tree, space=" ", level=0)
tree.write(romfs_src_path.joinpath("fighter/common/hdr/param/fighter_param.xml"), encoding="utf-8", xml_declaration=True)