manage deleted refered player, participant, objective, sector

This commit is contained in:
Maxime Réaux 2026-02-05 16:17:18 +01:00
parent 7afbb5ea1d
commit 7fbdacf97c
6 changed files with 322 additions and 81 deletions

View file

@ -43,6 +43,18 @@ class Round:
def get_choice(self, participant_id: str) -> Choice | None:
return self.choices.get(participant_id)
def has_choice_with_sector(self, sector_id: str) -> bool:
return any(
choice.priority_sector_id == sector_id
or choice.secondary_sector_id == sector_id
for choice in self.choices.values()
)
def has_choice_with_participant(self, participant_id: str) -> bool:
return any(
choice.participant_id == participant_id for choice in self.choices.values()
)
def create_choice(self, participant_id: str) -> Choice:
if participant_id not in self.choices:
choice = Choice(
@ -66,6 +78,13 @@ class Round:
choice.set_secondary(secondary_sector_id)
choice.set_comment(comment)
def clear_sector_references(self, sector_id: str) -> None:
for choice in self.choices.values():
if choice.priority_sector_id == sector_id:
choice.priority_sector_id = None
if choice.secondary_sector_id == sector_id:
choice.secondary_sector_id = None
def remove_choice(self, participant_id: str) -> None:
del self.choices[participant_id]
@ -74,6 +93,15 @@ class Round:
def get_battle(self, sector_id: str) -> Battle | None:
return self.battles.get(sector_id)
def has_battle_with_sector(self, sector_id: str) -> bool:
return any(bat.sector_id == sector_id for bat in self.battles.values())
def has_battle_with_participant(self, participant_id: str) -> bool:
return any(
bat.player_1_id == participant_id or bat.player_2_id == participant_id
for bat in self.battles.values()
)
def create_battle(self, sector_id: str) -> Battle:
if sector_id not in self.battles:
battle = Battle(sector_id=sector_id, player_1_id=None, player_2_id=None)
@ -99,5 +127,14 @@ class Round:
bat.set_victory_condition(victory_condition)
bat.set_comment(comment)
def clear_participant_references(self, participant_id: str) -> None:
for battle in self.battles.values():
if battle.player_1_id == participant_id:
battle.player_1_id = None
if battle.player_2_id == participant_id:
battle.player_2_id = None
if battle.winner_id == participant_id:
battle.winner_id = None
def remove_battle(self, sector_id: str) -> None:
del self.battles[sector_id]