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