Skip to content

Commit

Permalink
Repair of more invalid XML to allow for newlines in description output
Browse files Browse the repository at this point in the history
Minor config formatting
  • Loading branch information
syntaxaire committed Jul 11, 2019
1 parent 47026be commit 362dd6e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
25 changes: 13 additions & 12 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,36 @@ Interface:
# Interface options
Initial expansion targets:
# These object category IDs will be expanded when the tree is initialized:
[Food, MeleeWeapon, MissileWeapon, Armor, Shield, Token, LightSource, Tool, Tonic, Trinket, Energy Cell, Security Card, Barathrumite, SapientMutatedFlower]
[Food, MeleeWeapon, MissileWeapon, Armor, Shield, Token, LightSource, Tool, Tonic, Trinket,
Energy Cell, Security Card, Barathrumite, SapientMutatedFlower]

Templates:
# Options controlling the generation of wiki infobox templates
Fields:
# The fields that (if applicable) will be generated for each item, in this order:
# (title comes first, but is not listed here)
[image, lv, pv, maxpv, vibro, pvpowered, hp, av, dv,
ma, tohit, ammo, accuracy, shots, maxammo, maxvol,
liquidgen, liquidtype, maxcharge, charge, weight, commerce,
complexity, tier, bits, canbuild, skill, colorstr, renderstr, id,
bookid, lightradius, hunger, thirst, twohanded, metal,
lightprojectile, extra, strength, agility, toughness,
intelligence, willpower, ego, acid, electric, cold, heat,
desc]
[image, lv, pv, maxpv, vibro, pvpowered, hp, av, dv, ma, tohit, ammo, accuracy, shots, maxammo,
maxvol, liquidgen, liquidtype, maxcharge, charge, weight, commerce, complexity, tier, bits,
canbuild, skill, colorstr, renderstr, id, bookid, lightradius, hunger, thirst, twohanded,
metal, lightprojectile, extra, strength, agility, toughness, intelligence, willpower, ego,
acid, electric, cold, heat, desc]
Image overrides:
# If the image for an object was uploaded under a different name than in the
# game data, override it here:
Asphodel: Earl_asphodel.png

Wiki:
Categories:
# Each wiki category is followed by a list of nodes in the inheritance tree whose child objects
# should be in that category. Objects may also be explicitly specified.
Items: [Item]
Weapons: [MeleeWeapon, MissileWeapon]
Equipment: [Armor, Shield]
Energy cells: [Energy Cell]
Thrown weapons: [BaseThrownWeapon]
Plants: [Plant]
Creatures: [Creature]
Characters: [Phinae Hoshaiah, Barathrumite, Argyve, ElderBob, Mehmet, Warden Ualraig, Warden Esthers,
Eskhind, Meyehind, Liihart, Isahind, Neelahind, Keh, Kesehind, Angohind, Lulihart, AgateSeveranceStar,
Mayor Nuntu, Oboroqoru, Asphodel, Yurl, Euclid]
Characters: [Phinae Hoshaiah, Barathrumite, Argyve, ElderBob, Mehmet, Warden Ualraig,
Warden Esthers, Eskhind, Meyehind, Liihart, Isahind, Neelahind, Keh, Kesehind,
Angohind, Lulihart, AgateSeveranceStar, Mayor Nuntu, Oboroqoru, Asphodel, Yurl,
Euclid]
27 changes: 21 additions & 6 deletions qud_object_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@

def load(path):
"""Load ObjectBlueprints.xml from the specified filepath and return a reference to the root."""
# Do some repair of invalid XML
pattern = re.compile("()|()")
repaired = []
# Do some repair of invalid XML:
# First, delete some invalid characters
pat_invalid = re.compile("()|()")
with open(path, 'r', encoding='utf-8') as f:
for line in f:
repaired.append(pattern.sub('', line))
raw = et.fromstringlist(repaired)
contents = f.read()
contents = re.sub(pat_invalid, '', contents)

# Second, replace line breaks inside attributes with proper XML line breaks
# ^\s*<[^!][^>]*\n[^>]*>
pat_linebreaks = r"^\s*<[^!][^>]*\n.*?>"
match = re.search(pat_linebreaks, contents, re.MULTILINE)
while match:
before = match.string[:match.start()]
fixed = match.string[match.start():match.end()].replace('\n', '&#10;')
after = match.string[match.end():]
contents = before + fixed + after
match = re.search(pat_linebreaks, contents, re.MULTILINE)
# Uncomment to have a diff-able file to double check XML repairs.
# with open('test_output.xml', 'w', encoding='utf-8') as f:
# f.write(contents)

raw = et.fromstring(contents)

# Build the Qud object hierarchy from the XML data
for element in raw:
Expand Down

0 comments on commit 362dd6e

Please sign in to comment.