fix round listing from different wars

This commit is contained in:
Maxime Réaux 2026-02-05 10:19:14 +01:00
parent 019e62565f
commit 4593400fd4
2 changed files with 35 additions and 26 deletions

View file

@ -139,12 +139,12 @@ class War:
return camp
raise KeyError(f"Campaign {campaign_id} not found in War {self.id}")
def get_campaign_by_round(self, round_id: str) -> Campaign:
def get_campaign_by_round(self, round_id: str) -> Campaign | None:
for camp in self.campaigns:
for rnd in camp.rounds:
if rnd.id == round_id:
return camp
raise KeyError(f"Round {round_id} not found in any Campaign")
return None
def get_campaign_by_sector(self, sector_id: str) -> Campaign:
for camp in self.campaigns:
@ -255,19 +255,18 @@ class War:
camp = self.get_campaign(campaign_id)
return camp.add_round()
def add_battle(self, campaign_id: str) -> Round:
camp = self.get_campaign(campaign_id)
return camp.add_round()
def remove_round(self, round_id: str) -> None:
camp = self.get_campaign_by_round(round_id)
camp.remove_round(round_id)
if camp is not None:
camp.remove_round(round_id)
# Choice methods
def create_choice(self, round_id: str, participant_id: str) -> Choice:
camp = self.get_campaign_by_round(round_id)
return camp.create_choice(round_id, participant_id)
if camp is not None:
return camp.create_choice(round_id, participant_id)
raise KeyError("Campaign with round {round_id} doesn't exist")
def update_choice(
self,
@ -278,19 +277,27 @@ class War:
comment: str | None,
) -> None:
camp = self.get_campaign_by_round(round_id)
camp.update_choice(
round_id, participant_id, priority_sector_id, secondary_sector_id, comment
)
if camp is not None:
camp.update_choice(
round_id,
participant_id,
priority_sector_id,
secondary_sector_id,
comment,
)
def remove_choice(self, round_id: str, participant_id: str) -> None:
camp = self.get_campaign_by_round(round_id)
camp.remove_choice(round_id, participant_id)
if camp is not None:
camp.remove_choice(round_id, participant_id)
# Battle methods
def create_battle(self, round_id: str, sector_id: str) -> Battle:
camp = self.get_campaign_by_round(round_id)
return camp.create_battle(round_id, sector_id)
if camp is not None:
return camp.create_battle(round_id, sector_id)
raise KeyError("Campaign with round {round_id} doesn't exist")
def update_battle(
self,
@ -304,17 +311,19 @@ class War:
comment: str | None,
) -> None:
camp = self.get_campaign_by_round(round_id)
camp.update_battle(
round_id,
sector_id,
player_1_id,
player_2_id,
winner_id,
score,
victory_condition,
comment,
)
if camp is not None:
camp.update_battle(
round_id,
sector_id,
player_1_id,
player_2_id,
winner_id,
score,
victory_condition,
comment,
)
def remove_battle(self, round_id: str, sector_id: str) -> None:
camp = self.get_campaign_by_round(round_id)
camp.remove_battle(round_id, sector_id)
if camp is not None:
camp.remove_battle(round_id, sector_id)