Refactor Action as data class

Action is now a frozen data class.

All properties of Action now have type hints, and __slots__ are used
for properties without default values (that is, name).
This commit is contained in:
Jeremy Saklad 2021-09-18 17:13:57 -05:00
parent 79dd51c1c2
commit 21ea715dd1
Signed by: Jeremy Saklad
GPG Key ID: 9CA2149583EDBF84
1 changed files with 44 additions and 40 deletions

View File

@ -1,68 +1,72 @@
__all__ = ['Action'] __all__ = ['Action']
__author__ = "Jeremy Saklad" __author__ = "Jeremy Saklad"
from dataclasses import dataclass, field
@dataclass(frozen=True)
class Action: class Action:
"""An action that affects a skeleton's qualities.""" """An action that affects a skeleton's qualities."""
def __init__(self, name, cost, torso_style = None, value = 0, skulls_needed = 0, limbs_needed = 0, tails_needed = 0, skulls = 0, arms = 0, legs = 0, tails = 0, wings = 0, fins = 0, tentacles = 0, amalgamy = 0, antiquity = 0, menace = 0, implausibility = 0, counter_church = 0, exhaustion = 0): __slots__ = '__dict__', 'name'
self.name = name
# Cost in pennies of using this action, including the value of the actions spent name: str
self.cost = cost
# Skeleton: Torso Style # Cost in pennies of using this action, including the value of the actions spent
self.torso_style = torso_style cost: float = field(metadata={'unit': 'pennies'})
# Approximate Value of Your Skeleton in Pennies # Skeleton: Torso Style
self.value = value torso_style: int = None
# Skeleton: Skulls Needed # Approximate Value of Your Skeleton in Pennies
self.skulls_needed = skulls_needed value: int = field(default=0, metadata={'unit': 'pennies'})
# Skeleton: Limbs Needed # Skeleton: Skulls Needed
self.limbs_needed = limbs_needed skulls_needed: int = 0
# Skeleton: Tails Needed # Skeleton: Limbs Needed
self.tails_needed = tails_needed limbs_needed: int = 0
# Skeleton: Skulls # Skeleton: Tails Needed
self.skulls = skulls tails_needed: int = 0
# Skeleton: Arms # Skeleton: Skulls
self.arms = arms skulls: int = 0
# Skeleton: Legs # Skeleton: Arms
self.legs = legs arms: int = 0
# Skeleton: Tails # Skeleton: Legs
self.tails = tails legs: int = 0
# Skeleton: Wings # Skeleton: Tails
self.wings = wings tails: int = 0
# Skeleton: Fins # Skeleton: Wings
self.fins = fins wings: int = 0
# Skeleton: Tentacles # Skeleton: Fins
self.tentacles = tentacles fins: int = 0
# Skeleton: Amalgamy # Skeleton: Tentacles
self.amalgamy = amalgamy tentacles: int = 0
# Skeleton: Antiquity # Skeleton: Amalgamy
self.antiquity = antiquity amalgamy: int = 0
# Skeleton: Menace # Skeleton: Antiquity
self.menace = menace antiquity: int = 0
# Skeleton: Self-Evident Implausibility # Skeleton: Menace
self.implausibility = implausibility menace: int = 0
# Skeleton: Support for a Counter-church Theology # Skeleton: Self-Evident Implausibility
self.counter_church = counter_church implausibility: int = 0
# Bone Market Exhaustion # Skeleton: Support for a Counter-church Theology
self.exhaustion = exhaustion counter_church: int = 0
# Bone Market Exhaustion
exhaustion: int = 0
def __str__(self): def __str__(self):
return str(self.name) return str(self.name)