add/edit/delete sectors and participants in campaign
This commit is contained in:
parent
495a5adb98
commit
2816da010c
22 changed files with 1799 additions and 923 deletions
|
|
@ -1,6 +1,5 @@
|
|||
from __future__ import annotations
|
||||
from uuid import uuid4
|
||||
from datetime import datetime
|
||||
|
||||
from warchron.model.round import Round
|
||||
|
||||
|
|
@ -9,8 +8,8 @@ class Campaign:
|
|||
self.id: str = str(uuid4())
|
||||
self.name: str = name
|
||||
self.month: int = month
|
||||
self.participants = {}
|
||||
self.sectors = {}
|
||||
self.participants: dict[str, CampaignParticipant] = {}
|
||||
self.sectors: dict[str, Sector] = {}
|
||||
self.rounds = []
|
||||
self.is_over = False
|
||||
|
||||
|
|
@ -46,6 +45,61 @@ class Campaign:
|
|||
camp.set_state(data.get("is_over", False))
|
||||
return camp
|
||||
|
||||
# Campaign participant methods
|
||||
|
||||
def get_all_campaign_participants_ids(self) -> set[str]:
|
||||
return set(self.participants.keys())
|
||||
|
||||
def has_participant(self, player_id: str) -> bool:
|
||||
return player_id in self.participants
|
||||
|
||||
def add_campaign_participant(self, player_id: str, leader: str, theme: str) -> CampaignParticipant:
|
||||
if player_id in self.participants:
|
||||
raise ValueError("Player already registered in this campaign")
|
||||
participant = CampaignParticipant(player_id, leader, theme)
|
||||
self.participants[participant.id] = participant
|
||||
return participant
|
||||
|
||||
def get_campaign_participant(self, id: str) -> CampaignParticipant:
|
||||
return self.participants[id]
|
||||
|
||||
def get_all_campaign_participants(self) -> list[CampaignParticipant]:
|
||||
return list(self.participants.values())
|
||||
|
||||
def update_campaign_participant(self, player_id: str, *, leader: str, theme: str):
|
||||
part = self.get_campaign_participant(player_id)
|
||||
part.set_leader(leader)
|
||||
part.set_theme(theme)
|
||||
|
||||
def remove_campaign_participant(self, player_id: str):
|
||||
del self.participants[player_id]
|
||||
|
||||
# Sector methods
|
||||
|
||||
def add_sector(self, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str) -> Sector:
|
||||
sect = Sector(name, round_id, major_id, minor_id, influence_id)
|
||||
self.sectors[sect.id] = sect
|
||||
return sect
|
||||
|
||||
def get_sector(self, id: str) -> Sector:
|
||||
return self.sectors[id]
|
||||
|
||||
def get_all_sectors(self) -> list[Sector]:
|
||||
return list(self.sectors.values())
|
||||
|
||||
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)
|
||||
sect.set_round(round_id)
|
||||
sect.set_major(major_id)
|
||||
sect.set_minor(minor_id)
|
||||
sect.set_influence(influence_id)
|
||||
|
||||
def remove_sector(self, sector_id: str):
|
||||
del self.sectors[sector_id]
|
||||
|
||||
# Round methods
|
||||
|
||||
def has_round(self, round_id: str) -> bool:
|
||||
return any(r.id == round_id for r in self.rounds)
|
||||
|
||||
|
|
@ -66,23 +120,59 @@ class Campaign:
|
|||
self.rounds.remove(rnd)
|
||||
|
||||
def get_round_index(self, round_id: str) -> int:
|
||||
if round_id is None:
|
||||
return None
|
||||
for index, rnd in enumerate(self.rounds, start=1):
|
||||
if rnd.id == round_id:
|
||||
return index
|
||||
raise KeyError("Round not found in campaign")
|
||||
|
||||
def get_round_name(self, round_id: str | None) -> str:
|
||||
if round_id is None:
|
||||
return ""
|
||||
for rnd in self.rounds:
|
||||
if rnd.id == round_id:
|
||||
return rnd.name
|
||||
return ""
|
||||
|
||||
class CampaignParticipant:
|
||||
def __init__(self,war_participant_id: str, leader: str):
|
||||
self.id: str = war_participant_id # ref to War.participants
|
||||
def __init__(self,player_id: str, leader: str, theme: str):
|
||||
self.id: str = player_id # ref to War.participants
|
||||
self.leader: str = leader
|
||||
self.victory_points = 0
|
||||
self.objective_points = {}
|
||||
self.theme: str = theme
|
||||
|
||||
def set_id(self, new_id: str):
|
||||
self.id = new_id
|
||||
|
||||
def set_leader(self, new_faction: str):
|
||||
self.leader = new_faction
|
||||
|
||||
def set_theme(self, new_theme: str):
|
||||
self.theme = new_theme
|
||||
|
||||
class Sector:
|
||||
def __init__(self, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str):
|
||||
self.id: str = str(uuid4())
|
||||
self.name: str = name
|
||||
self.round_id: str = round_id
|
||||
self.major_objective_id: str = major_id
|
||||
self.minor_objective_id: str = minor_id
|
||||
self.influence_objective_id: str = influence_id
|
||||
self.round_id: str = round_id
|
||||
|
||||
def set_id(self, new_id: str):
|
||||
self.id = new_id
|
||||
|
||||
def set_name(self, new_name: str):
|
||||
self.name = new_name
|
||||
|
||||
def set_round(self, new_round_id: str):
|
||||
self.round_id = new_round_id
|
||||
|
||||
def set_major(self, new_major_id: str):
|
||||
self.major_objective_id = new_major_id
|
||||
|
||||
def set_minor(self, new_minor_id: str):
|
||||
self.minor_objective_id = new_minor_id
|
||||
|
||||
def set_influence(self, new_influence_id: str):
|
||||
self.influence_objective_id = new_influence_id
|
||||
|
|
|
|||
|
|
@ -5,7 +5,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
|
||||
from warchron.model.campaign import Campaign, Sector, CampaignParticipant
|
||||
from warchron.model.round import Round
|
||||
|
||||
class Model:
|
||||
|
|
@ -156,7 +156,7 @@ class Model:
|
|||
if not war.has_participant(player.id)
|
||||
]
|
||||
|
||||
def add_war_participant(self, war_id: str, player_id: str, faction: str) -> Objective:
|
||||
def add_war_participant(self, war_id: str, player_id: str, faction: str) -> WarParticipant:
|
||||
war = self.get_war(war_id)
|
||||
return war.add_war_participant(player_id, faction)
|
||||
|
||||
|
|
@ -198,7 +198,21 @@ class Model:
|
|||
if camp is not None:
|
||||
return camp
|
||||
raise KeyError(f"Round {round_id} not found")
|
||||
|
||||
|
||||
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)
|
||||
if camp is not None:
|
||||
return camp
|
||||
raise KeyError(f"Participant {participant_id} not found")
|
||||
|
||||
def get_campaign_by_sector(self, sector_id: str) -> Campaign:
|
||||
for war in self.wars.values():
|
||||
camp = war.get_campaign_by_sector(sector_id)
|
||||
if camp is not None:
|
||||
return camp
|
||||
raise KeyError(f"Sector {sector_id} not found")
|
||||
|
||||
def update_campaign(self, campaign_id: str, *, name: str, month: int):
|
||||
war = self.get_war_by_campaign(campaign_id)
|
||||
war.update_campaign(campaign_id, name=name, month=month)
|
||||
|
|
@ -207,16 +221,64 @@ class Model:
|
|||
war = self.get_war_by_campaign(campaign_id)
|
||||
war.remove_campaign(campaign_id)
|
||||
|
||||
# Sector methods
|
||||
|
||||
def add_sector(self, campaign_id: str, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str) -> Sector:
|
||||
camp = self.get_campaign(campaign_id)
|
||||
return camp.add_sector(name, round_id, major_id, minor_id, influence_id)
|
||||
|
||||
def get_sector(self, sector_id) -> Sector:
|
||||
for war in self.wars.values():
|
||||
for camp in war.campaigns:
|
||||
for sect in camp.sectors.values():
|
||||
if sect.id == sector_id:
|
||||
return sect
|
||||
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)
|
||||
|
||||
def remove_sector(self, sector_id: str):
|
||||
camp = self.get_campaign_by_sector(sector_id)
|
||||
camp.remove_sector(sector_id)
|
||||
|
||||
# Campaign participant methods
|
||||
|
||||
def get_available_war_participants(self, campaign_id: str) -> list[WarParticipant]:
|
||||
war = self.get_war_by_campaign(campaign_id)
|
||||
return war.get_available_war_participants(campaign_id)
|
||||
|
||||
def add_campaign_participant(self, camp_id: str, player_id: str, leader: str, theme: str) -> CampaignParticipant:
|
||||
camp = self.get_campaign(camp_id)
|
||||
return camp.add_campaign_participant(player_id, leader, theme)
|
||||
|
||||
def get_campaign_participant(self, participant_id) -> CampaignParticipant:
|
||||
for war in self.wars.values():
|
||||
for camp in war.campaigns:
|
||||
for part in camp.participants.values():
|
||||
if part.id == participant_id:
|
||||
return part
|
||||
raise KeyError("Participant not found")
|
||||
|
||||
def update_campaign_participant(self, participant_id: str, *, leader: str, theme: str):
|
||||
camp = self.get_campaign_by_campaign_participant(participant_id)
|
||||
camp.update_campaign_participant(participant_id, leader=leader, theme=theme)
|
||||
|
||||
def remove_campaign_participant(self, participant_id: str):
|
||||
camp = self.get_campaign_by_campaign_participant(participant_id)
|
||||
camp.remove_campaign_participant(participant_id)
|
||||
|
||||
# Round methods
|
||||
|
||||
def add_round(self, campaign_id: str) -> Round:
|
||||
campaign = self.get_campaign(campaign_id)
|
||||
return campaign.add_round()
|
||||
camp = self.get_campaign(campaign_id)
|
||||
return camp.add_round()
|
||||
|
||||
def get_round(self, round_id: str) -> Round:
|
||||
for war in self.wars.values():
|
||||
for campaign in war.campaigns:
|
||||
for rnd in campaign.rounds:
|
||||
for camp in war.campaigns:
|
||||
for rnd in camp.rounds:
|
||||
if rnd.id == round_id:
|
||||
return rnd
|
||||
raise KeyError("Round not found")
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
|||
from uuid import uuid4
|
||||
from datetime import datetime
|
||||
|
||||
from warchron.model.campaign import Campaign
|
||||
from warchron.model.campaign import Campaign, Sector, CampaignParticipant
|
||||
|
||||
|
||||
class War:
|
||||
|
|
@ -50,9 +50,9 @@ class War:
|
|||
# Objective methods
|
||||
|
||||
def add_objective(self, name: str, description: str) -> Objective:
|
||||
objective = Objective(name, description)
|
||||
self.objectives[objective.id] = objective
|
||||
return objective
|
||||
obj = Objective(name, description)
|
||||
self.objectives[obj.id] = obj
|
||||
return obj
|
||||
|
||||
def get_objective(self, id: str) -> Objective:
|
||||
return self.objectives[id]
|
||||
|
|
@ -60,6 +60,12 @@ class War:
|
|||
def get_all_objectives(self) -> list[Objective]:
|
||||
return list(self.objectives.values())
|
||||
|
||||
def get_objective_name(self, objective_id: str | None) -> str:
|
||||
if objective_id is None:
|
||||
return ""
|
||||
obj = self.objectives.get(objective_id)
|
||||
return obj.name if obj else ""
|
||||
|
||||
def update_objective(self, objective_id: str, *, name: str, description: str):
|
||||
obj = self.get_objective(objective_id)
|
||||
obj.set_name(name)
|
||||
|
|
@ -126,6 +132,20 @@ class War:
|
|||
return camp
|
||||
raise KeyError(f"Round {round_id} not found in any Campaign")
|
||||
|
||||
def get_campaign_by_sector(self, sector_id: str) -> Campaign:
|
||||
for camp in self.campaigns:
|
||||
for sect in camp.sectors.values():
|
||||
if sect.id == sector_id:
|
||||
return camp
|
||||
raise KeyError(f"Sector {sector_id} not found in any Campaign")
|
||||
|
||||
def get_campaign_by_campaign_participant(self, participant_id: str) -> Campaign:
|
||||
for camp in self.campaigns:
|
||||
for part in camp.participants.values():
|
||||
if part.id == participant_id:
|
||||
return camp
|
||||
raise KeyError(f"Participant {participant_id} not found in any Campaign")
|
||||
|
||||
def update_campaign(self, campaign_id: str, *, name: str, month: int):
|
||||
camp = self.get_campaign(campaign_id)
|
||||
camp.set_name(name)
|
||||
|
|
@ -138,6 +158,52 @@ class War:
|
|||
camp = self.get_campaign(campaign_id)
|
||||
self.campaigns.remove(camp)
|
||||
|
||||
# Sector methods
|
||||
|
||||
def add_sector(self, campaign_id, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str) -> Sector:
|
||||
camp = self.get_campaign(campaign_id)
|
||||
return camp.add_sector(name, round_id, major_id, minor_id, influence_id)
|
||||
|
||||
def get_sector(self, id: str) -> Sector:
|
||||
return self.sectors[id]
|
||||
|
||||
def update_sector(self, objective_id: str, *, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str):
|
||||
obj = self.get_objective(objective_id)
|
||||
obj.set_name(name)
|
||||
|
||||
def remove_sector(self, sector_id: str):
|
||||
camp = self.get_campaign_by_sector(sector_id)
|
||||
camp.remove_sector(sector_id)
|
||||
|
||||
# Campaign participant methods
|
||||
|
||||
def get_available_war_participants(self, campaign_id: str) -> list[WarParticipant]:
|
||||
camp = self.get_campaign(campaign_id)
|
||||
return [
|
||||
part
|
||||
for part in self.participants.values()
|
||||
if not camp.has_participant(part.id)
|
||||
]
|
||||
|
||||
def add_campaign_participant(self, campaign_id: str, player_id: str, leader: str, theme: str) -> CampaignParticipant:
|
||||
camp = self.get_campaign(campaign_id)
|
||||
return camp.add_campaign_participant(player_id, leader, theme)
|
||||
|
||||
def get_campaign_participant(self, participant_id) -> CampaignParticipant:
|
||||
for camp in self.campaigns.values():
|
||||
for part in camp.participants.values():
|
||||
if part.id == participant_id:
|
||||
return part
|
||||
raise KeyError("Participant not found")
|
||||
|
||||
def update_campaign_participant(self, participant_id: str, *, faction: str):
|
||||
camp = self.get_campaign_by_campaign_participant(participant_id)
|
||||
camp.update_campaign_participant(participant_id, faction=faction)
|
||||
|
||||
def remove_campaign_participant(self, participant_id: str):
|
||||
camp = self.get_campaign_by_campaign_participant(participant_id)
|
||||
camp.remove_campaign_participant(participant_id)
|
||||
|
||||
class Objective:
|
||||
def __init__(self, name: str, description: str):
|
||||
self.id: str = str(uuid4())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue