auto create & edit choice
This commit is contained in:
parent
723723dea1
commit
9f676f6b9d
6 changed files with 166 additions and 59 deletions
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
from uuid import uuid4
|
||||
|
||||
from warchron.model.round import Round
|
||||
from warchron.model.round import Round, Choice, Battle
|
||||
|
||||
class Campaign:
|
||||
def __init__(self, name: str, month: int):
|
||||
|
|
@ -10,7 +10,7 @@ class Campaign:
|
|||
self.month: int = month
|
||||
self.participants: dict[str, CampaignParticipant] = {}
|
||||
self.sectors: dict[str, Sector] = {}
|
||||
self.rounds = []
|
||||
self.rounds: list[Round] = []
|
||||
self.is_over = False
|
||||
|
||||
def set_id(self, new_id: str):
|
||||
|
|
@ -72,6 +72,8 @@ class Campaign:
|
|||
part.set_theme(theme)
|
||||
|
||||
def remove_campaign_participant(self, player_id: str):
|
||||
# TODO manage choices referring to it
|
||||
# TODO manage battles referring to it
|
||||
del self.participants[player_id]
|
||||
|
||||
# Sector methods
|
||||
|
|
@ -81,12 +83,18 @@ class Campaign:
|
|||
self.sectors[sect.id] = sect
|
||||
return sect
|
||||
|
||||
def get_sector(self, id: str) -> Sector:
|
||||
return self.sectors[id]
|
||||
def get_sector(self, sector_id: str) -> Sector:
|
||||
return self.sectors[sector_id]
|
||||
|
||||
def get_sector_name(self, sector_id: str) -> str:
|
||||
if sector_id is None:
|
||||
return ""
|
||||
return self.sectors[sector_id].name
|
||||
|
||||
def get_all_sectors(self) -> list[Sector]:
|
||||
return list(self.sectors.values())
|
||||
|
||||
# TODO manage choices referring to it (round order!)
|
||||
def update_sector(self, sector_id: str, *, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str):
|
||||
sect = self.get_sector(sector_id)
|
||||
sect.set_name(name)
|
||||
|
|
@ -96,6 +104,8 @@ class Campaign:
|
|||
sect.set_influence(influence_id)
|
||||
|
||||
def remove_sector(self, sector_id: str):
|
||||
# TODO manage choices referring to it
|
||||
# TODO manage battles referring to it
|
||||
del self.sectors[sector_id]
|
||||
|
||||
# Round methods
|
||||
|
|
@ -104,7 +114,10 @@ class Campaign:
|
|||
return any(r.id == round_id for r in self.rounds)
|
||||
|
||||
def get_round(self, round_id: str) -> Round:
|
||||
return self.rounds[round_id]
|
||||
for rnd in self.rounds:
|
||||
if rnd.id == round_id:
|
||||
return rnd
|
||||
raise KeyError(f"Round {round_id} not found")
|
||||
|
||||
def get_all_rounds(self) -> list[Round]:
|
||||
return list(self.rounds)
|
||||
|
|
@ -135,6 +148,16 @@ class Campaign:
|
|||
return rnd.name
|
||||
return ""
|
||||
|
||||
# Choice methods
|
||||
|
||||
def create_choice(self, round_id: str, participant_id: str) -> Choice:
|
||||
rnd = self.get_round(round_id)
|
||||
return rnd.create_choice(participant_id)
|
||||
|
||||
def remove_choice(self, round_id: str, participant_id: str) -> Choice:
|
||||
rnd = self.get_round(round_id)
|
||||
rnd.remove_choice(participant_id)
|
||||
|
||||
class CampaignParticipant:
|
||||
def __init__(self,player_id: str, leader: str, theme: str):
|
||||
self.id: str = player_id # ref to War.participants
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue