auto create & edit choice
This commit is contained in:
parent
723723dea1
commit
9f676f6b9d
6 changed files with 166 additions and 59 deletions
|
|
@ -6,7 +6,7 @@ from datetime import datetime
|
|||
from warchron.model.player import Player
|
||||
from warchron.model.war import War, Objective, WarParticipant
|
||||
from warchron.model.campaign import Campaign, Sector, CampaignParticipant
|
||||
from warchron.model.round import Round
|
||||
from warchron.model.round import Round, Choice, Battle
|
||||
|
||||
class Model:
|
||||
def __init__(self):
|
||||
|
|
@ -76,6 +76,7 @@ class Model:
|
|||
return list(self.players.values())
|
||||
|
||||
def remove_player(self, player_id: str):
|
||||
# TODO manage war_participants referring to it
|
||||
del self.players[player_id]
|
||||
|
||||
# War methods
|
||||
|
|
@ -100,6 +101,22 @@ class Model:
|
|||
return war
|
||||
raise KeyError(f"Campaign {campaign_id} not found in any War")
|
||||
|
||||
def get_war_by_sector(self, sector_id: str) -> Campaign:
|
||||
for war in self.wars.values():
|
||||
for camp in war.campaigns:
|
||||
for sect in camp.sectors.values():
|
||||
if sect.id == sector_id:
|
||||
return camp
|
||||
raise KeyError(f"Sector {sector_id} not found in any War")
|
||||
|
||||
def get_war_by_round(self, round_id: str) -> Campaign:
|
||||
for war in self.wars.values():
|
||||
for camp in war.campaigns:
|
||||
for rnd in camp.rounds:
|
||||
if rnd.id == round_id:
|
||||
return camp
|
||||
raise KeyError(f"Round {round_id} not found in any War")
|
||||
|
||||
def get_war_by_objective(self, objective_id: str) -> War:
|
||||
for war in self.wars.values():
|
||||
for obj in war.objectives.values():
|
||||
|
|
@ -107,6 +124,7 @@ class Model:
|
|||
return war
|
||||
raise KeyError(f"Objective {objective_id} not found in any War")
|
||||
|
||||
# TODO don't use this method as participant with same ID (player) can be in several wars!
|
||||
def get_war_by_war_participant(self, participant_id: str) -> War:
|
||||
for war in self.wars.values():
|
||||
for part in war.participants.values():
|
||||
|
|
@ -199,6 +217,7 @@ class Model:
|
|||
return camp
|
||||
raise KeyError(f"Round {round_id} not found")
|
||||
|
||||
# TODO don't use this method as participant with same ID (player) can be in several campaigns!
|
||||
def get_campaign_by_campaign_participant(self, participant_id: str) -> Campaign:
|
||||
for war in self.wars.values():
|
||||
camp = war.get_campaign_by_campaign_participant(participant_id)
|
||||
|
|
@ -236,8 +255,8 @@ class Model:
|
|||
raise KeyError("Sector not found")
|
||||
|
||||
def update_sector(self, sector_id: str, *, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str):
|
||||
camp = self.get_campaign_by_sector(sector_id)
|
||||
camp.update_sector(sector_id, name=name, round_id=round_id, major_id=major_id, minor_id=minor_id, influence_id=influence_id)
|
||||
war = self.get_war_by_sector(sector_id)
|
||||
war.update_sector(sector_id, name=name, round_id=round_id, major_id=major_id, minor_id=minor_id, influence_id=influence_id)
|
||||
|
||||
def remove_sector(self, sector_id: str):
|
||||
camp = self.get_campaign_by_sector(sector_id)
|
||||
|
|
@ -286,13 +305,29 @@ class Model:
|
|||
def get_round_index(self, round_id: str) -> int:
|
||||
camp = self.get_campaign_by_round(round_id)
|
||||
return camp.get_round_index(round_id)
|
||||
|
||||
def get_round_sectors(self, round_id: str) -> list[Sector]:
|
||||
camp = self.get_campaign_by_round(round_id)
|
||||
return [s for s in camp.sectors.values() if s.round_id == round_id]
|
||||
|
||||
def get_round_participants(self, round_id: str) -> list[CampaignParticipant]:
|
||||
camp = self.get_campaign_by_round(round_id)
|
||||
return list(camp.participants.values())
|
||||
|
||||
def remove_round(self, round_id: str):
|
||||
camp = self.get_campaign_by_round(round_id)
|
||||
camp.remove_round(round_id)
|
||||
war = self.get_war_by_round(round_id)
|
||||
war.remove_round(round_id)
|
||||
|
||||
# Choices methods
|
||||
|
||||
def create_choice(self, round_id: str, participant_id: str) -> Choice:
|
||||
war = self.get_war_by_round(round_id)
|
||||
return war.create_choice(round_id, participant_id)
|
||||
|
||||
def remove_choice(self, round_id: str, participant_id: str):
|
||||
war = self.get_war_by_round(round_id)
|
||||
war.remove_choice(round_id, participant_id)
|
||||
|
||||
def get_round_choices_data(self, round_id: str):
|
||||
camp = self.get_campaign_by_round(round_id)
|
||||
rnd = self.get_round(round_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue