1
Fork 0
mirror of https://github.com/Steffo99/lihzahrd.git synced 2024-11-25 01:24:21 +00:00

Create Mannequin and HatRack classes

This commit is contained in:
Steffo 2020-06-03 15:05:36 +02:00
parent 101fdf0da9
commit c0adcef396
2 changed files with 39 additions and 21 deletions

View file

@ -1,7 +1,7 @@
from .itemtype import ItemType from .itemtype import ItemType
from .itemstack import ItemStack from .itemstack import ItemStack
from .chest import Chest from .chest import Chest
from .clothingdisplay import ClothingDisplay from .clothingdisplay import ClothingDisplay, Mannequin, HatRack
from .singleitemdisplay import SingleItemDisplay from .singleitemdisplay import SingleItemDisplay
__all__ = ["ItemType", "ItemStack", "Chest", "ClothingDisplay", "SingleItemDisplay"] __all__ = ["ItemType", "ItemStack", "Chest", "ClothingDisplay", "SingleItemDisplay", "Mannequin", "HatRack"]

View file

@ -1,32 +1,50 @@
import typing import typing
from .itemstack import ItemStack 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, def __init__(self,
item_flags: typing.List[bool], wearing_items: typing.List[ItemStack],
dye_flags: typing.List[bool], wearing_dyes: typing.List[ItemStack]):
wearing_items: typing.List[ItemStack],
wearing_dyes: typing.List[ItemStack],
display_type: str,):
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 self.wearing_items: typing.List[ItemStack] = wearing_items
"""What items is the mannequin wearing.""" """What items is the mannequin wearing."""
self.wearing_dyes: typing.List[ItemStack] = wearing_dyes self.wearing_dyes: typing.List[ItemStack] = wearing_dyes
"""What dyes is the mannequin wearing.""" """What dyes is the mannequin wearing."""
self.display_type: str = display_type
"""What type of display is this?"""
def __repr__(self): 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 <https://terraria.gamepedia.com/Mannequin>`_
/ `Womannequin <https://terraria.gamepedia.com/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 <https://terraria.gamepedia.com/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