35 lines
977 B
Python
35 lines
977 B
Python
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 Model.players
|
|
self.faction: str = faction
|
|
|
|
def set_id(self, new_id: str) -> None:
|
|
self.id = new_id
|
|
|
|
def set_player(self, new_player_id: str) -> None:
|
|
self.player_id = new_player_id
|
|
|
|
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
|