-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_creatures_and_corpses.py
65 lines (56 loc) · 2.44 KB
/
find_creatures_and_corpses.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
import os
import sys
import pathlib
import xml.etree.ElementTree as ElementTree
import re
class IgnoreErrorsParser(ElementTree.XMLParser):
def _raiseerror(self, value):
pass
if __name__ == '__main__':
path_to_xml = pathlib.Path.home().joinpath('.local/share/Steam/steamapps/common/'
'Caves of Qud/CoQ_Data/StreamingAssets/Base/ObjectBlueprints/'
'Creatures.xml')
# can't parse XML because apparently it's malformed? whatever.
# root = ElementTree.parse(path_to_xml).getroot()
# fish it all out with regex then I guess
inherits = {}
lines = []
last_line = None
with open(path_to_xml, 'r', encoding='utf-8') as f:
inherits_pattern = 'Inherits="[A-Za-z0-9]+'
object_name_pattern = '<object Name="([A-Za-z0-9 ]+)"'# Inherits="BaseHumanoid"'
corpse_name_pattern = '<part Name="Corpse".+CorpseBlueprint="([A-Za-z0-9 ]+)"'
for line in f.readlines():
# inherits_match = re.findall(inherits_pattern, line)
# if len(inherits_match) > 0 and not inherits_match[0] in inherits:
# inherits[inherits_match[0]] = ""
object_match = re.search(object_name_pattern, line)
if object_match:
last_line = object_match.group(1)
corpse_match = re.search(corpse_name_pattern, line)
if corpse_match:
lines.append(f'"{corpse_match.group(1)}" => "{last_line}", ')
for line in lines:
print(line)
# for key in inherits.keys():
# print(key)
# # for event, element in ElementTree.iterparse(f.read()):
# # if element.tag == 'objects':
# # print("objects")
# # Events - signify when to yield a result
# events = ('start', 'end') # Yield on the start and end of a tag
#
# file_contents = f.read()
#
# # Redirect sys.stdout to the null device cuz iterparse is noisy as HELL
# sys.stdout = open(os.devnull, 'w')
#
# # It's important to clear the elements when working with bag datasets
# for event, element in ElementTree.iterparse(file_contents, events=events):
# if event == 'start':
# print(element.tag)
# if event == 'end':
# element.clear()
#
# # Restore the original sys.stdout
# sys.stdout = sys.__stdout__