add missing to_json mehods

This commit is contained in:
Maximilian Keßler 2023-08-08 14:10:17 +02:00
parent 511c3bc7c6
commit 9200371e3a
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -25,6 +25,12 @@ class DeckCard:
raise ParseError("No rank specified in deck_card") raise ParseError("No rank specified in deck_card")
return DeckCard(suit_index, rank) return DeckCard(suit_index, rank)
def to_json(self):
return {
"suitIndex": self.suitIndex,
"rank": self.rank
}
def colorize(self): def colorize(self):
color = ["green", "blue", "magenta", "yellow", "white", "cyan"][self.suitIndex] color = ["green", "blue", "magenta", "yellow", "white", "cyan"][self.suitIndex]
return colored(str(self), color) return colored(str(self), color)
@ -84,6 +90,13 @@ class Action:
action_value action_value
) )
def to_json(self):
return {
"type": self.type.value,
"target": self.target,
"value": self.value
}
def __repr__(self): def __repr__(self):
match self.type: match self.type:
case ActionType.Play: case ActionType.Play: