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