Skip to content

Commit

Permalink
Add config: wiki categories, filter out NPC inventory junk
Browse files Browse the repository at this point in the history
  • Loading branch information
syntaxaire committed Jul 10, 2019
1 parent 27f53b3 commit 47026be
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
13 changes: 13 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ Templates:
# 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:
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]
20 changes: 18 additions & 2 deletions qud_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from anytree import NodeMixin

from config import config
from helpers import cp437_to_unicode
from helpers import cp437_to_unicode, parse_svalue

IMAGE_OVERRIDES = config['Templates']['Image overrides']

Expand Down Expand Up @@ -86,7 +86,9 @@ def ui_inheritance_path(self) -> str:
return text

def inherits_from(self, name: str):
"""Returns True if this object inherits from the object named 'name', False otherwise."""
"""Returns True if this object is 'name' or inherits from 'name', False otherwise."""
if self.name == name:
return True
if self.is_root:
return False
if self.parent.name == name:
Expand Down Expand Up @@ -180,8 +182,19 @@ def wikify(self):
if getattr(self, stat) is not None:
output += f"| {stat} = {getattr(self, stat)}\n"
output += "}}\n"
category = self.wiki_category()
if category:
output += "[[Category:" + category + "]]\n"
return output

def wiki_category(self):
cat = None
for config_cat, names in config['Wiki']['Categories'].items():
for name in names:
if self.inherits_from(name):
cat = config_cat
return cat

def __str__(self):
return self.name + ' ' + str(self.attributes)

Expand Down Expand Up @@ -237,6 +250,9 @@ def av(self):
if self.inventoryobject:
# might be wearing armor
for name in list(self.inventoryobject.keys()):
if name[0] in '*#@':
# special values like '*Junk 1'
continue
item = qindex[name]
if item.av:
av += int(item.av)
Expand Down

0 comments on commit 47026be

Please sign in to comment.