From c0adcef396efeeae953146af25eab8809a615213 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 3 Jun 2020 15:05:36 +0200 Subject: [PATCH] Create Mannequin and HatRack classes --- lihzahrd/chests/__init__.py | 4 +-- lihzahrd/chests/clothingdisplay.py | 56 ++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/lihzahrd/chests/__init__.py b/lihzahrd/chests/__init__.py index 55e999c..ad57620 100644 --- a/lihzahrd/chests/__init__.py +++ b/lihzahrd/chests/__init__.py @@ -1,7 +1,7 @@ from .itemtype import ItemType from .itemstack import ItemStack from .chest import Chest -from .clothingdisplay import ClothingDisplay +from .clothingdisplay import ClothingDisplay, Mannequin, HatRack from .singleitemdisplay import SingleItemDisplay -__all__ = ["ItemType", "ItemStack", "Chest", "ClothingDisplay", "SingleItemDisplay"] +__all__ = ["ItemType", "ItemStack", "Chest", "ClothingDisplay", "SingleItemDisplay", "Mannequin", "HatRack"] diff --git a/lihzahrd/chests/clothingdisplay.py b/lihzahrd/chests/clothingdisplay.py index d49479b..97bcc51 100755 --- a/lihzahrd/chests/clothingdisplay.py +++ b/lihzahrd/chests/clothingdisplay.py @@ -1,32 +1,50 @@ import typing from .itemstack import ItemStack -class ClothingDisplay: - """Data pertaining to an item to display clothing. - Currently this is a Womannequin/Mannequin (https://terraria.gamepedia.com/Womannequin) - and hat rack (https://terraria.gamepedia.com/Hat_Rack). - """ - __slots__ = "item_flags", "dye_flags", "wearing_items", "wearing_dyes", "display_type" +class ClothingDisplay: + """Data pertaining to an item to display clothing.""" + + __slots__ = "wearing_items", "wearing_dyes", "display_type" def __init__(self, - item_flags: typing.List[bool], - dye_flags: typing.List[bool], - wearing_items: typing.List[ItemStack], - wearing_dyes: typing.List[ItemStack], - display_type: str,): + wearing_items: typing.List[ItemStack], + wearing_dyes: typing.List[ItemStack]): - self.item_flags: typing.List[bool] = item_flags - """Which slots have items in them.""" - self.dye_flags: typing.List[bool] = dye_flags - """Which slots have dyes in them.""" self.wearing_items: typing.List[ItemStack] = wearing_items """What items is the mannequin wearing.""" self.wearing_dyes: typing.List[ItemStack] = wearing_dyes """What dyes is the mannequin wearing.""" - self.display_type: str = display_type - """What type of display is this?""" - def __repr__(self): - return f"ClothingDisplay(type={self.display_type}, dyes={len(self.wearing_dyes)}, )" + return f"<{self.__class__.__qualname__} with {self.total_count} items inside>" + + @property + def items_count(self): + return len(list(filter(lambda x: x is not None, self.wearing_items))) + + @property + def dyes_count(self): + return len(list(filter(lambda x: x is not None, self.wearing_dyes))) + + @property + def total_count(self): + return self.items_count + self.dyes_count + + +class Mannequin(ClothingDisplay): + """A `Mannequin `_ + / `Womannequin `_ containing up to 3 dyed armor pieces and up + to 5 dyed accessories.""" + def __init__(self, wearing_items: typing.List[ItemStack], wearing_dyes: typing.List[ItemStack]): + super().__init__(wearing_items, wearing_dyes) + assert len(wearing_items) == 8 + assert len(wearing_dyes) == 8 + + +class HatRack(ClothingDisplay): + """A `Hat Rack `_ containing up to 2 dyed helmets.""" + def __init__(self, wearing_items: typing.List[ItemStack], wearing_dyes: typing.List[ItemStack]): + super().__init__(wearing_items, wearing_dyes) + assert len(wearing_items) == 2 + assert len(wearing_dyes) == 2