From 47026bead2c87bf475a9083df293230262bd3fd5 Mon Sep 17 00:00:00 2001 From: syntaxaire Date: Tue, 9 Jul 2019 20:12:16 -0400 Subject: [PATCH] Add config: wiki categories, filter out NPC inventory junk --- config.yml | 13 +++++++++++++ qud_object.py | 20 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/config.yml b/config.yml index f3bbbc7..ac157d5 100644 --- a/config.yml +++ b/config.yml @@ -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] \ No newline at end of file diff --git a/qud_object.py b/qud_object.py index ebe2627..1b3c33c 100644 --- a/qud_object.py +++ b/qud_object.py @@ -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'] @@ -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: @@ -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) @@ -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)