manage deleted refered player, participant, objective, sector
This commit is contained in:
parent
7afbb5ea1d
commit
7fbdacf97c
6 changed files with 322 additions and 81 deletions
|
|
@ -3,6 +3,7 @@ from uuid import uuid4
|
|||
from datetime import datetime
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from warchron.model.exception import DeletionForbidden
|
||||
from warchron.model.war_participant import WarParticipant
|
||||
from warchron.model.objective import Objective
|
||||
from warchron.model.campaign_participant import CampaignParticipant
|
||||
|
|
@ -82,7 +83,16 @@ class War:
|
|||
obj.set_description(description)
|
||||
|
||||
def remove_objective(self, objective_id: str) -> None:
|
||||
# TODO manage sectors referring to it
|
||||
camp_using_obj: List[str] = []
|
||||
for camp in self.campaigns:
|
||||
if camp.has_sector_with_objective(objective_id):
|
||||
camp_using_obj.append(camp.name)
|
||||
if camp_using_obj:
|
||||
camps_str = ", ".join(camp_using_obj)
|
||||
raise DeletionForbidden(
|
||||
f"This objective is used in campaign(s) sector(s): {camps_str}.\n"
|
||||
"Remove it from campaign(s) first."
|
||||
)
|
||||
del self.objectives[objective_id]
|
||||
|
||||
# War participant methods
|
||||
|
|
@ -109,14 +119,23 @@ class War:
|
|||
def get_all_war_participants(self) -> List[WarParticipant]:
|
||||
return list(self.participants.values())
|
||||
|
||||
def update_war_participant(self, player_id: str, *, faction: str) -> None:
|
||||
part = self.get_war_participant(player_id)
|
||||
def update_war_participant(self, participant_id: str, *, faction: str) -> None:
|
||||
part = self.get_war_participant(participant_id)
|
||||
# Can't change referred Model.players
|
||||
part.set_faction(faction)
|
||||
|
||||
def remove_war_participant(self, player_id: str) -> None:
|
||||
# TODO manage campaign_participants referring to it
|
||||
del self.participants[player_id]
|
||||
def remove_war_participant(self, participant_id: str) -> None:
|
||||
camp_using_part: List[str] = []
|
||||
for camp in self.campaigns:
|
||||
if camp.has_war_participant(participant_id):
|
||||
camp_using_part.append(camp.name)
|
||||
if camp_using_part:
|
||||
camps_str = ", ".join(camp_using_part)
|
||||
raise DeletionForbidden(
|
||||
f"This war participant is used in campaign(s): {camps_str}.\n"
|
||||
"Remove it from campaign(s) first."
|
||||
)
|
||||
del self.participants[participant_id]
|
||||
|
||||
# Campaign methods
|
||||
|
||||
|
|
@ -139,6 +158,7 @@ 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:
|
||||
|
|
@ -146,6 +166,7 @@ class War:
|
|||
return camp
|
||||
return None
|
||||
|
||||
# TODO replace multiloops by internal has_* method
|
||||
def get_campaign_by_sector(self, sector_id: str) -> Campaign:
|
||||
for camp in self.campaigns:
|
||||
for sect in camp.sectors.values():
|
||||
|
|
@ -185,6 +206,7 @@ class War:
|
|||
camp = self.get_campaign(campaign_id)
|
||||
return camp.add_sector(name, round_id, major_id, minor_id, influence_id)
|
||||
|
||||
# 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():
|
||||
|
|
@ -232,6 +254,7 @@ 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():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue