save/load participants, objectives, sectors, choices & battles
This commit is contained in:
parent
7fbdacf97c
commit
6cd3a060c7
9 changed files with 152 additions and 11 deletions
|
|
@ -1,11 +1,12 @@
|
|||
from __future__ import annotations
|
||||
from typing import Any, Dict
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
class WarParticipant:
|
||||
def __init__(self, *, player_id: str, faction: str):
|
||||
self.id: str = str(uuid4())
|
||||
self.player_id: str = player_id # ref to WarModel.players
|
||||
self.player_id: str = player_id # ref to Model.players
|
||||
self.faction: str = faction
|
||||
|
||||
def set_id(self, new_id: str) -> None:
|
||||
|
|
@ -16,3 +17,19 @@ class WarParticipant:
|
|||
|
||||
def set_faction(self, new_faction: str) -> None:
|
||||
self.faction = new_faction
|
||||
|
||||
def toDict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"id": self.id,
|
||||
"player_id": self.player_id,
|
||||
"faction": self.faction,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def fromDict(data: Dict[str, Any]) -> WarParticipant:
|
||||
part = WarParticipant(
|
||||
player_id=data["player_id"],
|
||||
faction=data["faction"],
|
||||
)
|
||||
part.set_id(data["id"])
|
||||
return part
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue