-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdilogueview_fixer.py
57 lines (42 loc) · 1.46 KB
/
dilogueview_fixer.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
import argparse
import os
from tkinter import filedialog
from xml.etree import ElementTree as et
PATH_TO_TOOLTIP = 'Nodes/Node/ToolTip'
COUNT = 2
new_id = '07'
def check_is_hexadecimal(value: str):
try:
int(value, 16)
except ValueError:
print(f'{value} is not hexadecimal!')
exit()
def absoluteFilePaths(directory):
"""Yields next dialogue view tuple (abs path,
filename) in specified directory.
"""
for dirpath, _, filenames in os.walk(directory):
for filename in filenames:
if os.path.splitext(filename)[1] == '.xml':
yield os.path.abspath(os.path.join(dirpath)), filename
def fix_dialogue_view(view_tuple: tuple, new_id: str):
tree = et.parse(os.path.join(*view_tuple))
all_tooltips = tree.findall(PATH_TO_TOOLTIP)
for tooltip in all_tooltips:
tooltip.text = tooltip.text.replace(
tooltip.text[:COUNT], new_id, COUNT)
tree.write(os.path.join(view_tuple[0], new_id + view_tuple[1][2:]))
def agrgument_parser():
parser = argparse.ArgumentParser(description='CK dialogue view fixer')
parser.add_argument('newid', help='New id (masters count) in HEX')
args = parser.parse_args()
check_is_hexadecimal(args.newid)
global new_id
new_id = args.newid
def main():
path = filedialog.askdirectory()
for file in absoluteFilePaths(path):
fix_dialogue_view(file, new_id)
if __name__ == '__main__':
agrgument_parser()
main()