wip close round/campaign/war + refacto json None
This commit is contained in:
parent
4c8086caf4
commit
6cbb7c6534
26 changed files with 474 additions and 108 deletions
|
|
@ -40,26 +40,30 @@ class Battle:
|
|||
def set_comment(self, new_comment: str | None) -> None:
|
||||
self.comment = new_comment
|
||||
|
||||
# TODO improve draw detection
|
||||
def is_draw(self) -> bool:
|
||||
return self.winner_id is None and self.score is not None
|
||||
|
||||
def toDict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"sector_id": self.sector_id,
|
||||
"player_1_id": self.player_1_id,
|
||||
"player_2_id": self.player_2_id,
|
||||
"winner_id": self.winner_id,
|
||||
"score": self.score,
|
||||
"victory_condition": self.victory_condition,
|
||||
"comment": self.comment,
|
||||
"player_1_id": self.player_1_id or None,
|
||||
"player_2_id": self.player_2_id or None,
|
||||
"winner_id": self.winner_id or None,
|
||||
"score": self.score or None,
|
||||
"victory_condition": self.victory_condition or None,
|
||||
"comment": self.comment or None,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def fromDict(data: Dict[str, Any]) -> Battle:
|
||||
battle = Battle(
|
||||
data["sector_id"],
|
||||
data.get("player_1_id"),
|
||||
data.get("player_2_id"),
|
||||
data.get("player_1_id") or None,
|
||||
data.get("player_2_id") or None,
|
||||
)
|
||||
battle.winner_id = data.get("winner_id")
|
||||
battle.score = data.get("score")
|
||||
battle.victory_condition = data.get("victory_condition")
|
||||
battle.comment = data.get("comment")
|
||||
battle.winner_id = data.get("winner_id") or None
|
||||
battle.score = data.get("score") or None
|
||||
battle.victory_condition = data.get("victory_condition") or None
|
||||
battle.comment = data.get("comment") or None
|
||||
return battle
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue