Repository navigation
Expand file tree
/
Copy pathskillStringXmlEditor.py
More file actions
97 lines (78 loc) · 2.96 KB
/
Copy pathskillStringXmlEditor.py
File metadata and controls
97 lines (78 loc) · 2.96 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
#!/usr/bin/env python3
"""
Python 3.x.x
Used for modifying the string XML for skills, to change skill values
(integers found in each level description).
Supports adding/subtracting, multiplying, setting,
but could easily be tweaked for a lot of things.
Prints the number of individual values changed, for verification purposes.
"""
numerics = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', ',']
filename = input(
"Enter the filename, or absolute/relative file path " +
"if not in this folder, of the String XML: ")
skillid = int(input("Enter the ID of the skill you wish to edit: "))
attribute = input(
"Enter the string after which the next number will be modified: ")
add = int(input(
"Enter how much you would like to add to the attribute " +
"at every level of the skill (can be negative): "))
multi = float(input(
"Enter how much you would like to " +
"multiply the attribute by at every level: "))
setto = 0
try:
setto = int(input(
"Enter what you would like to set the attribute to at all levels " +
"(enter anything that is not an integer to ignore): "))
except:
setto = -60001 # Magic number that I assume no one will enter
out = ""
attributeschangedcount = 0
line = ""
with open(filename, "r") as f:
lines = f.readlines()
if len(lines) > 1:
raise IOError("XML file is not all in one line.")
line = lines[0]
skillstartindex = line.find("<imgdir name=\"" + str(skillid).zfill(7) + "\">")
if skillstartindex == -1:
raise ValueError("Could not find specified skill ID.")
skillendindex = line.find("</imgdir>", skillstartindex)
currentindex = line.find("<string name=\"h1\"", skillstartindex)
currentindex = line.find(attribute, currentindex) + len(attribute)
while currentindex > skillstartindex and currentindex < skillendindex:
thevalue = ""
valuefirstindex = -1
while True:
if line[currentindex] in numerics and currentindex < skillendindex:
thevalue += line[currentindex]
valuefirstindex = currentindex
currentindex += 1
break
else:
currentindex += 1
while line[currentindex] in numerics:
thevalue += line[currentindex]
currentindex += 1
thevalue = thevalue.replace(",", "")
newvalue = 0
if setto != -60001:
newvalue = setto
else:
newvalue = int(int(thevalue) * multi)
newvalue += add
newvalue = str(newvalue)
beginning = line[:valuefirstindex]
end = line[currentindex:]
line = beginning + newvalue + end
attributeschangedcount += 1
if len(newvalue) != len(thevalue):
difference = len(newvalue) - len(thevalue)
skillendindex += difference
currentindex += difference
currentindex = line.find(attribute, currentindex) + len(attribute)
out = line
with open(filename, "w") as f:
f.write(out)
print(attributeschangedcount)