from __future__ import annotations from uuid import uuid4 class Round: def __init__(self): self.id: str = str(uuid4()) self.choices: dict[str, RoundChoice] = {} self.battles = {} self.is_over: bool = False def set_id(self, new_id: str): self.id = new_id def set_state(self, new_state: bool): self.is_over = new_state def set_choice(self, participant_id: str, priority_sector_id: str | None, secondary_sector_id: str | None): self.choices[participant_id] = RoundChoice(participant_id, priority_sector_id, secondary_sector_id) def toDict(self): return { "id": self.id, # "sectors" : self.sectors, # "choices" : self.choices, # "battles" : self.battles, "is_over": self.is_over } @staticmethod def fromDict(data: dict): rnd = Round() rnd.set_id(data["id"]) # rnd.sectors = data.get("sectors", {}) # rnd.choices = data.get("choices", {}) # rnd.battles = data.get("battles", {}) rnd.set_state(data.get("is_over", False)) return rnd # Choices methods def get_choice(self, participant_id: str) -> RoundChoice | None: return self.choices.get(participant_id) class RoundChoice: def __init__(self, participant_id: str, priority_sector_id: str | None = None, secondary_sector_id: str | None = None): self.participant_id: str = participant_id # ref to Campaign.participants self.priority_sector_id: str | None = priority_sector_id # ref to Campaign.sectors self.secondary_sector_id: str | None = secondary_sector_id # ref to Campaign.sectors