warchron_app/src/warchron/model/round.py

68 lines
2.5 KiB
Python
Raw Normal View History

2026-01-30 10:52:19 +01:00
from __future__ import annotations
2026-01-21 07:43:04 +01:00
from uuid import uuid4
2026-01-19 18:55:07 +01:00
class Round:
2026-01-21 07:43:04 +01:00
def __init__(self):
self.id: str = str(uuid4())
2026-01-30 15:32:44 +01:00
self.choices: dict[str, Choice] = {}
self.battles: dict[str, Battle] = {}
self.is_over: bool = False
2026-01-19 18:55:07 +01:00
def set_id(self, new_id: str):
2026-01-21 07:43:04 +01:00
self.id = new_id
2026-01-19 18:55:07 +01:00
def set_state(self, new_state: bool):
2026-01-19 18:55:07 +01:00
self.is_over = new_state
2026-01-30 10:52:19 +01:00
def set_choice(self, participant_id: str, priority_sector_id: str | None, secondary_sector_id: str | None):
2026-01-30 15:32:44 +01:00
self.choices[participant_id] = Choice(participant_id, priority_sector_id, secondary_sector_id)
2026-01-30 10:52:19 +01:00
2026-01-19 18:55:07 +01:00
def toDict(self):
return {
2026-01-21 08:31:48 +01:00
"id": self.id,
# "sectors" : self.sectors,
# "choices" : self.choices,
# "battles" : self.battles,
2026-01-19 18:55:07 +01:00
"is_over": self.is_over
}
@staticmethod
2026-01-21 08:31:48 +01:00
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))
2026-01-30 10:52:19 +01:00
return rnd
# Choices methods
2026-01-30 15:32:44 +01:00
def get_choice(self, participant_id: str) -> Choice | None:
2026-01-30 10:52:19 +01:00
return self.choices.get(participant_id)
2026-01-30 15:32:44 +01:00
def create_choice(self, participant_id: str) -> Choice:
if participant_id not in self.choices:
choice = Choice(
participant_id=participant_id,
priority_sector_id=None,
secondary_sector_id=None
)
self.choices[participant_id] = choice
return self.choices[participant_id]
2026-01-30 10:52:19 +01:00
2026-01-30 15:32:44 +01:00
def remove_choice(self,participant_id: str):
del self.choices[participant_id]
class Choice:
2026-01-30 10:52:19 +01:00
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
2026-01-30 15:32:44 +01:00
class Battle:
def __init__(self, sector_id: str, player_1_id: str | None = None, player_2_id: str | None = None):
self.sector_id: str = sector_id # ref to Campaign.sector
self.player_1_id: str | None = player_1_id # ref to Campaign.participants
self.player_2_id: str | None = player_2_id # ref to Campaign.participants