add/edit/delete sectors and participants in campaign

This commit is contained in:
Maxime Réaux 2026-01-30 00:34:22 +01:00
parent 495a5adb98
commit 2816da010c
22 changed files with 1799 additions and 923 deletions

View file

@ -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())