fix refresh choice & battle tables + refactor loops
This commit is contained in:
parent
e7e2de9d0a
commit
719b0128ed
5 changed files with 32 additions and 35 deletions
|
|
@ -66,7 +66,7 @@ class RoundController:
|
|||
"Create forbidden",
|
||||
str(e),
|
||||
)
|
||||
else:
|
||||
if choice:
|
||||
priority_name = (
|
||||
camp.get_sector_name(choice.priority_sector_id)
|
||||
if choice.priority_sector_id is not None
|
||||
|
|
@ -124,7 +124,7 @@ class RoundController:
|
|||
"Create forbidden",
|
||||
str(e),
|
||||
)
|
||||
else:
|
||||
if battle:
|
||||
state_icon = Icons.get(IconName.ONGOING)
|
||||
if battle.is_finished():
|
||||
state_icon = Icons.get(IconName.DONE)
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ class RoundClosureWorkflow(Workflow):
|
|||
for tie in ties:
|
||||
bids = bids_map[tie.key()]
|
||||
tie_id = TieBreaker.find_active_tie_id(war, tie) or str(uuid4())
|
||||
# TODO finish tiebreak by group (like choice) not by turn
|
||||
TieBreaker.apply_bids(war, tie, tie_id, bids)
|
||||
TieBreaker.resolve_tie_state(war, tie, tie_id, bids)
|
||||
ties = TieBreaker.find_battle_ties(war, round.id)
|
||||
|
|
@ -45,6 +46,7 @@ class CampaignClosureWorkflow(Workflow):
|
|||
for tie in ties:
|
||||
bids = bids_map[tie.key()]
|
||||
tie_id = TieBreaker.find_active_tie_id(war, tie) or str(uuid4())
|
||||
# TODO finish tiebreak by group (like choice) not by turn
|
||||
TieBreaker.apply_bids(war, tie, tie_id, bids)
|
||||
TieBreaker.resolve_tie_state(war, tie, tie_id, bids)
|
||||
ties = TieBreaker.find_campaign_ties(war, campaign.id)
|
||||
|
|
@ -60,6 +62,7 @@ class CampaignClosureWorkflow(Workflow):
|
|||
for tie in ties:
|
||||
bids = bids_map[tie.key()]
|
||||
tie_id = TieBreaker.find_active_tie_id(war, tie) or str(uuid4())
|
||||
# TODO finish tiebreak by group (like choice) not by turn
|
||||
TieBreaker.apply_bids(war, tie, tie_id, bids)
|
||||
TieBreaker.resolve_tie_state(war, tie, tie_id, bids)
|
||||
ties = TieBreaker.find_campaign_objective_ties(
|
||||
|
|
@ -80,6 +83,7 @@ class WarClosureWorkflow(Workflow):
|
|||
for tie in ties:
|
||||
bids = bids_map[tie.key()]
|
||||
tie_id = TieBreaker.find_active_tie_id(war, tie) or str(uuid4())
|
||||
# TODO finish tiebreak by group (like choice) not by turn
|
||||
TieBreaker.apply_bids(war, tie, tie_id, bids)
|
||||
TieBreaker.resolve_tie_state(war, tie, tie_id, bids)
|
||||
ties = TieBreaker.find_war_ties(war)
|
||||
|
|
@ -94,6 +98,7 @@ class WarClosureWorkflow(Workflow):
|
|||
for tie in ties:
|
||||
bids = bids_map[tie.key()]
|
||||
tie_id = TieBreaker.find_active_tie_id(war, tie) or str(uuid4())
|
||||
# TODO finish tiebreak by group (like choice) not by turn
|
||||
TieBreaker.apply_bids(war, tie, tie_id, bids)
|
||||
TieBreaker.resolve_tie_state(war, tie, tie_id, bids)
|
||||
ties = TieBreaker.find_war_objective_ties(
|
||||
|
|
|
|||
|
|
@ -345,12 +345,10 @@ class Campaign:
|
|||
return index
|
||||
raise KeyError("Round not found in campaign")
|
||||
|
||||
# TODO replace multiloops by internal has_* method
|
||||
def get_round_by_battle(self, sector_id: str) -> Round:
|
||||
for rnd in self.rounds:
|
||||
for bat in rnd.battles.values():
|
||||
if bat.sector_id == sector_id:
|
||||
return rnd
|
||||
if rnd.has_battle_with_sector(sector_id):
|
||||
return rnd
|
||||
raise KeyError(f"Battle {sector_id} not found in any Round")
|
||||
|
||||
def get_all_rounds(self) -> List[Round]:
|
||||
|
|
@ -408,6 +406,12 @@ class Campaign:
|
|||
rnd = self.get_round(round_id)
|
||||
return rnd.create_battle(sector_id)
|
||||
|
||||
def get_battle(self, battle_id: str) -> Battle | None:
|
||||
for rnd in self.rounds:
|
||||
if rnd.has_battle_with_sector(battle_id):
|
||||
return rnd.get_battle(battle_id)
|
||||
return None
|
||||
|
||||
def update_battle(
|
||||
self,
|
||||
round_id: str,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from typing import Any, Dict, List, TYPE_CHECKING
|
|||
if TYPE_CHECKING:
|
||||
from warchron.model.campaign import Campaign
|
||||
from warchron.model.war import War
|
||||
from warchron.constants import ContextType
|
||||
from warchron.constants import ContextType
|
||||
from warchron.model.exception import (
|
||||
ForbiddenOperation,
|
||||
DomainError,
|
||||
|
|
|
|||
|
|
@ -312,20 +312,16 @@ class War:
|
|||
return camp
|
||||
raise KeyError(f"Campaign {campaign_id} not found in War {self.id}")
|
||||
|
||||
# TODO replace multiloops by internal has_* method
|
||||
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
|
||||
if camp.has_round(round_id):
|
||||
return camp
|
||||
return None
|
||||
|
||||
# TODO replace multiloops by internal has_* method
|
||||
def get_campaign_by_sector(self, sector_id: str) -> Campaign | None:
|
||||
for camp in self.campaigns:
|
||||
for sect in camp.sectors.values():
|
||||
if sect.id == sector_id:
|
||||
return camp
|
||||
if camp.has_sector(sector_id):
|
||||
return camp
|
||||
return None
|
||||
|
||||
def get_campaign_by_campaign_participant(
|
||||
|
|
@ -383,12 +379,10 @@ class War:
|
|||
name, round_id, major_id, minor_id, influence_id, mission, description
|
||||
)
|
||||
|
||||
# TODO replace multiloops by internal has_* method
|
||||
def get_sector(self, sector_id: str) -> Sector:
|
||||
for camp in self.campaigns:
|
||||
for sect in camp.sectors.values():
|
||||
if sect.id == sector_id:
|
||||
return sect
|
||||
if camp.has_sector(sector_id):
|
||||
return camp.get_sector(sector_id)
|
||||
raise KeyError("Sector not found")
|
||||
|
||||
def update_sector(
|
||||
|
|
@ -439,12 +433,10 @@ class War:
|
|||
camp = self.get_campaign(campaign_id)
|
||||
return camp.add_campaign_participant(participant_id, leader, theme)
|
||||
|
||||
# TODO replace multiloops by internal has_* method
|
||||
def get_campaign_participant(self, participant_id: str) -> CampaignParticipant:
|
||||
for camp in self.campaigns:
|
||||
for part in camp.participants.values():
|
||||
if part.id == participant_id:
|
||||
return part
|
||||
if camp.has_participant(participant_id):
|
||||
return camp.get_campaign_participant(participant_id)
|
||||
raise KeyError("Participant not found")
|
||||
|
||||
def update_campaign_participant(
|
||||
|
|
@ -461,12 +453,10 @@ class War:
|
|||
|
||||
# Round methods
|
||||
|
||||
# TODO replace multiloops by internal has_* method
|
||||
def get_round(self, round_id: str) -> Round:
|
||||
for camp in self.campaigns:
|
||||
for rnd in camp.rounds:
|
||||
if rnd.id == round_id:
|
||||
return rnd
|
||||
if camp.has_round(round_id):
|
||||
return camp.get_round(round_id)
|
||||
raise KeyError("Round not found")
|
||||
|
||||
def add_round(self, campaign_id: str) -> Round:
|
||||
|
|
@ -484,7 +474,7 @@ class War:
|
|||
camp = self.get_campaign_by_round(round_id)
|
||||
if camp is not None:
|
||||
return camp.create_choice(round_id, participant_id)
|
||||
raise KeyError("Campaign with round {round_id} doesn't exist")
|
||||
raise KeyError(f"Campaign with round {round_id} doesn't exist")
|
||||
|
||||
def update_choice(
|
||||
self,
|
||||
|
|
@ -511,20 +501,18 @@ class War:
|
|||
|
||||
# Battle methods
|
||||
|
||||
# TODO replace multiloops by internal has_* method
|
||||
def get_battle(self, battle_id: str) -> Battle:
|
||||
for camp in self.campaigns:
|
||||
for rnd in camp.rounds:
|
||||
for bat in rnd.battles.values():
|
||||
if bat.sector_id == battle_id:
|
||||
return bat
|
||||
raise KeyError("Battle not found")
|
||||
battle = camp.get_battle(battle_id)
|
||||
if battle is not None:
|
||||
return battle
|
||||
raise KeyError(f"War did not find Battle {battle_id}")
|
||||
|
||||
def create_battle(self, round_id: str, sector_id: str) -> Battle:
|
||||
camp = self.get_campaign_by_round(round_id)
|
||||
if camp is not None:
|
||||
return camp.create_battle(round_id, sector_id)
|
||||
raise KeyError("Campaign with round {round_id} doesn't exist")
|
||||
raise KeyError(f"Campaign with round {round_id} doesn't exist")
|
||||
|
||||
def update_battle(
|
||||
self,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue