130 lines
3.9 KiB
Python
Raw Normal View History

from typing import List, Optional
2023-10-10 12:01:34 +08:00
from .collection import CollectionAttr
from .start import StartAttr
from .action import ActionAttr
from .progress import ProgressAttr
from .constants import AbilityType, CardColor, CardType, FrameType
class Ability:
type: AbilityType
effect: str
2023-10-23 23:35:02 +08:00
effect_tran: str
2023-10-23 23:35:02 +08:00
def __init__(self, type: AbilityType, effect: str, effect_tran: str) -> None:
self.type = type
self.effect = effect
2023-10-23 23:35:02 +08:00
self.effect_tran = effect_tran
def __json__(self):
2023-10-23 23:35:02 +08:00
return {
"type": self.type.value,
"effect": self.effect,
"effect_tran": self.effect_tran,
}
2023-10-10 12:01:34 +08:00
class Card:
name: str
2023-10-23 23:35:02 +08:00
name_tran: str
2023-10-10 12:01:34 +08:00
type: CardType
level: int
color: Optional[CardColor]
# Will automatic generate
text: str
abilities: List[Ability]
2023-10-10 12:01:34 +08:00
progress_attr: Optional[ProgressAttr]
action_attr: Optional[ActionAttr]
frame_attr: Optional[FrameType]
atk_value: Optional[int]
def_value: Optional[int]
stk_value: Optional[int]
flavor_text: Optional[str]
2023-10-23 23:35:02 +08:00
flavor_text_tran: Optional[str]
2023-10-10 12:01:34 +08:00
collection_attr: CollectionAttr
def __init__(
self,
name: str,
2023-10-23 23:35:02 +08:00
name_tran: str,
2023-10-10 12:01:34 +08:00
type: CardType,
level: int,
color: Optional[CardColor],
abilities: List[Ability],
2023-10-10 12:01:34 +08:00
progress_attr: Optional[ProgressAttr],
action_attr: Optional[ActionAttr],
frame_attr: Optional[FrameType],
atk_value: Optional[int],
def_value: Optional[int],
stk_value: Optional[int],
flavor_text: Optional[str],
2023-10-23 23:35:02 +08:00
flavor_text_tran: Optional[str],
2023-10-10 12:01:34 +08:00
collection_attr: CollectionAttr,
) -> None:
self.name = name
2023-10-23 23:35:02 +08:00
self.name_tran = name_tran
2023-10-10 12:01:34 +08:00
self.type = type
self.level = level
self.color = color
self.abilities = abilities
2023-10-10 12:01:34 +08:00
self.progress_attr = progress_attr
self.action_attr = action_attr
self.frame_attr = frame_attr
self.frame_attr = frame_attr
self.atk_value = atk_value
self.def_value = def_value
self.stk_value = stk_value
self.flavor_text = flavor_text
2023-10-23 23:35:02 +08:00
self.flavor_text_tran = flavor_text_tran
2023-10-10 12:01:34 +08:00
self.collection_attr = collection_attr
text = ""
for ability in self.abilities:
if ability.type == AbilityType.Persistent:
type_text = "[常]"
elif ability.type == AbilityType.Automatic:
type_text = "[自]"
elif ability.type == AbilityType.Activated:
type_text = "[起]"
text += f"{type_text} {ability.effect}\n"
2023-10-23 23:35:02 +08:00
if self.action_attr:
text += self.action_attr.__text__()
2023-10-10 12:01:34 +08:00
elif self.frame_attr:
text += self.frame_attr.value
2023-10-10 12:01:34 +08:00
elif self.progress_attr:
text += self.progress_attr.__text__()
self.text = text
2023-10-10 12:01:34 +08:00
def __json__(self):
return {
"name": self.name,
2023-10-23 23:35:02 +08:00
"name_tran": self.name_tran,
2023-10-10 12:01:34 +08:00
"type": self.type.value,
"level": self.level,
"color": self.color.value if self.color else None,
"text": self.text,
"abilities": [ability.__json__() for ability in self.abilities],
2023-10-10 12:01:34 +08:00
"progress_attr": self.progress_attr.__json__()
if self.progress_attr
else None,
"action_attr": self.action_attr.__json__() if self.action_attr else None,
"frame_attr": self.frame_attr.value if self.frame_attr else None,
"atk": self.atk_value if self.atk_value else None,
"def": self.def_value if self.def_value else None,
"stk": self.stk_value if self.stk_value else None,
"flavor_text": self.flavor_text if self.flavor_text else None,
2023-10-23 23:35:02 +08:00
"flavor_text_tran": self.flavor_text_tran
if self.flavor_text_tran
else None,
2023-10-10 12:01:34 +08:00
"collection_attr": self.collection_attr.__json__(),
}