auto create & edit choice

This commit is contained in:
Maxime Réaux 2026-01-30 15:32:44 +01:00
parent 723723dea1
commit 9f676f6b9d
6 changed files with 166 additions and 59 deletions

View file

@ -4,8 +4,8 @@ from uuid import uuid4
class Round:
def __init__(self):
self.id: str = str(uuid4())
self.choices: dict[str, RoundChoice] = {}
self.battles = {}
self.choices: dict[str, Choice] = {}
self.battles: dict[str, Battle] = {}
self.is_over: bool = False
def set_id(self, new_id: str):
@ -15,7 +15,7 @@ class Round:
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)
self.choices[participant_id] = Choice(participant_id, priority_sector_id, secondary_sector_id)
def toDict(self):
return {
@ -38,12 +38,30 @@ class Round:
# Choices methods
def get_choice(self, participant_id: str) -> RoundChoice | None:
def get_choice(self, participant_id: str) -> Choice | None:
return self.choices.get(participant_id)
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]
class RoundChoice:
def remove_choice(self,participant_id: str):
del self.choices[participant_id]
class Choice:
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
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