-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_undead_creatures_xml.py
98 lines (91 loc) · 6.4 KB
/
create_undead_creatures_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
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
98
import pathlib
import re
if __name__ == '__main__':
# creatures_considered = ["Templar", "Bat", "Pig", "Boar", "Cave Spider", "Ray Cat", "Croc", "Dog", "Electrofuge",
# "Giant Beetle", "Giant Centipede", "GiantDragonfly", "Glowfish", "Goat", "Horned Chameleon",
# "Qudzu", "Salamander", "Scorpiock", "Snapjaw", "Chute Crab", "Eyeless Crab", "Feral Lah",
# "Girshling", "Glowmoth", "Knollworm", "Leech", "Salthopper", "Seedsprout Worm",
# "Worm of the Earth", "Naphtaali", "BaseHindren", "Albino ape", "Barkbiter",
# "Chitinous Puma", "Dawnglider", "Equimax", "Fire ant", "Fire Snout", "Ghost Perch",
# "Ice frog", "Quillipede", "Rustacean", "Spark Tick", "Voider", "Goatfolk", "Electric Snail",
# "Eyeless King Crab", "BaseBreather", "FireBreather", "IceBreather", "CorrosiveBreather",
# "NormalityBreather", "PoisonBreather", "SleepBreather", "StunBreather", "ConfusionBreather",
# "Troll", "Agolzvuv", "Bloated Pearlfrog", "Cyclopean Gibbon", "Mimic", "Molting Basilisk",
# "Quartz Baboon", "Snailmother", "Urchin Belcher", "Bone Worm", "Goatfolk Qlippoth",
# "Greater Voider", "Madpole", "Ogre Ape", "Rhinox", "BaseElderBreather", "ElderFireBreather",
# "ElderIceBreather", "ElderCorrosiveBreather", "ElderNormalityBreather",
# "ElderPoisonBreather", "ElderSleepBreather", "ElderStunBreather", "ElderConfusionBreather",
# "Enigma Snail", "Great Saltback", "Kaleidoslug", "Memory Eater", "Sultan Croc", "Svardym",
# "Saltwurm", "Unimax", "Urshiib", "Dromad", "GolgothaSlog", "BaseBiomech", ]
#
# print('''<?xml version="1.0" encoding="utf-8"?>
# <!-- Undead versions of all creatures that can be reanimated -->
# <objects>''')
#
# for creature in creatures_considered:
# print(f'\t<object Name="ChebGonaz Undead {creature}" Inherits="{creature}">\n'
# f'\t\t<removepart Name="Corpse" />\n'
# f'\t</object>')
# print('</objects>')
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
creatures_considered = ['"Templar"', '"Bat"', '"Pig"', '"Boar"', '"Cave Spider"', '"Ray Cat"', '"Croc"', '"Dog"',
'"Electrofuge"', '"Giant Beetle"', '"Giant Centipede"', '"GiantDragonfly"', '"Glowfish"',
'"Goat"', '"Horned Chameleon"', '"Qudzu"', '"Salamander"', '"Scorpiock"', '"Snapjaw"',
'"Chute Crab"', '"Eyeless Crab"', '"Feral Lah"', '"Girshling"', '"Glowmoth"', '"Knollworm"',
'"Leech"', '"Salthopper"', '"Seedsprout Worm"', '"Worm of the Earth"', '"Naphtaali"',
'"BaseHindren"', '"Albino ape"', '"Barkbiter"', '"Chitinous Puma"', '"Dawnglider"',
'"Equimax"', '"Fire ant"', '"Fire Snout"', '"Ghost Perch"', '"Ice frog"', '"Quillipede"',
'"Rustacean"', '"Spark Tick"', '"Voider"', '"Goatfolk"', '"Electric Snail"',
'"Eyeless King Crab"', '"BaseBreather"', '"FireBreather"', '"IceBreather"',
'"CorrosiveBreather"', '"NormalityBreather"', '"PoisonBreather"', '"SleepBreather"',
'"StunBreather"', '"ConfusionBreather"', '"Troll"', '"Agolzvuv"', '"Bloated Pearlfrog"',
'"Cyclopean Gibbon"', '"Mimic"', '"Molting Basilisk"', '"Quartz Baboon"', '"Snailmother"',
'"Urchin Belcher"', '"Bone Worm"', '"Goatfolk Qlippoth"', '"Greater Voider"', '"Madpole"',
'"Ogre Ape"', '"Rhinox"', '"BaseElderBreather"', '"ElderFireBreather"',
'"ElderIceBreather"', '"ElderCorrosiveBreather"', '"ElderNormalityBreather"',
'"ElderPoisonBreather"', '"ElderSleepBreather"', '"ElderStunBreather"',
'"ElderConfusionBreather"', '"Enigma Snail"', '"Great Saltback"', '"Kaleidoslug"',
'"Memory Eater"', '"Sultan Croc"', '"Svardym"', '"Saltwurm"', '"Unimax"', '"Urshiib"',
'"Dromad"', '"GolgothaSlog"', '"BaseBiomech"', ]
result = {}
last_key = ''
lines = []
with open(path_to_xml, 'r', encoding='utf-8') as f:
object_begin_pattern = '<object Name=("[A-Za-z0-9 ]+")'
object_end_pattern = '</object>'
for line in f.readlines():
object_match = re.search(object_begin_pattern, line)
if object_match and object_match.group(1) in creatures_considered:
last_key = object_match.group(1)
if last_key == '':
continue
elif object_end_pattern in line:
lines.append(line)
result[last_key] = lines
lines = []
last_key = ''
else:
lines.append(line)
print('''<?xml version="1.0" encoding="utf-8"?>
<!-- Undead versions of all creatures that can be reanimated -->
<objects>''')
# <part Name="Render" DisplayName="snapjaw" Tile="Assets_Content_Textures_Creatures_sw_snapjaw.bmp" RenderString="s" ColorString="&w" DetailColor="R" />
def find_and_replace(vals):
for val in vals:
m = re.search(r'(<part Name="Render" )(DisplayName=")(.*?)(")( .+)\n', val)
if m:
return m.group(1) + m.group(2) + f'Undead {m.group(3)}' + m.group(4) + m.group(5)
return ''
for key, value in result.items():
# string_value = "".join(value)
# print(string_value)
print(f'\t<object Name="ChebGonaz Undead {key[1:-1]}" Inherits="{key[1:-1]}">\n'
f'\t\t<removepart Name="Corpse" />\n'
f'\t\t{find_and_replace(value)}\n'
f'\t</object>')
print('</objects>')