2026-01-28 16:25:40 +01:00
|
|
|
from __future__ import annotations
|
2026-01-19 18:55:07 +01:00
|
|
|
from uuid import uuid4
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from warchron.model.round import Round
|
|
|
|
|
|
|
|
|
|
class Campaign:
|
2026-01-28 16:25:40 +01:00
|
|
|
def __init__(self, name: str, month: int):
|
|
|
|
|
self.id: str = str(uuid4())
|
|
|
|
|
self.name: str = name
|
|
|
|
|
self.month: int = month
|
|
|
|
|
self.participants = {}
|
|
|
|
|
self.sectors = {}
|
2026-01-21 07:43:04 +01:00
|
|
|
self.rounds = []
|
2026-01-19 18:55:07 +01:00
|
|
|
self.is_over = False
|
|
|
|
|
|
2026-01-28 16:25:40 +01:00
|
|
|
def set_id(self, new_id: str):
|
2026-01-19 18:55:07 +01:00
|
|
|
self.id = new_id
|
|
|
|
|
|
2026-01-28 16:25:40 +01:00
|
|
|
def set_name(self, new_name: str):
|
2026-01-19 18:55:07 +01:00
|
|
|
self.name = new_name
|
|
|
|
|
|
2026-01-28 16:25:40 +01:00
|
|
|
def set_month(self, new_month: int):
|
2026-01-19 18:55:07 +01:00
|
|
|
self.month = new_month
|
|
|
|
|
|
2026-01-28 16:25:40 +01:00
|
|
|
def set_state(self, new_state: bool):
|
2026-01-19 18:55:07 +01:00
|
|
|
self.is_over = new_state
|
|
|
|
|
|
|
|
|
|
def toDict(self):
|
|
|
|
|
return {
|
|
|
|
|
"id" : self.id,
|
|
|
|
|
"name" : self.name,
|
|
|
|
|
"month" : self.month,
|
2026-01-28 16:25:40 +01:00
|
|
|
# "participants" : self.participants,
|
2026-01-21 08:31:48 +01:00
|
|
|
"rounds": [rnd.toDict() for rnd in self.rounds],
|
2026-01-19 18:55:07 +01:00
|
|
|
"is_over": self.is_over
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
2026-01-21 08:31:48 +01:00
|
|
|
def fromDict(data: dict):
|
2026-01-22 23:42:47 +01:00
|
|
|
camp = Campaign(name=data["name"], month=data["month"])
|
2026-01-21 08:31:48 +01:00
|
|
|
camp.set_id(data["id"])
|
2026-01-28 16:25:40 +01:00
|
|
|
# camp.participants = data.get("participants", {})
|
2026-01-21 08:31:48 +01:00
|
|
|
for rnd_data in data.get("rounds", []):
|
|
|
|
|
camp.rounds.append(Round.fromDict(rnd_data))
|
|
|
|
|
camp.set_state(data.get("is_over", False))
|
|
|
|
|
return camp
|
2026-01-28 16:25:40 +01:00
|
|
|
|
|
|
|
|
def has_round(self, round_id: str) -> bool:
|
|
|
|
|
return any(r.id == round_id for r in self.rounds)
|
2026-01-21 07:43:04 +01:00
|
|
|
|
2026-01-28 16:25:40 +01:00
|
|
|
def get_round(self, round_id: str) -> Round:
|
2026-01-21 07:43:04 +01:00
|
|
|
return self.rounds[round_id]
|
|
|
|
|
|
|
|
|
|
def get_all_rounds(self) -> list[Round]:
|
|
|
|
|
return list(self.rounds)
|
|
|
|
|
|
|
|
|
|
def add_round(self) -> Round:
|
|
|
|
|
round = Round()
|
|
|
|
|
self.rounds.append(round)
|
2026-01-22 23:42:47 +01:00
|
|
|
return round
|
|
|
|
|
|
|
|
|
|
def remove_round(self, round_id: str):
|
|
|
|
|
rnd = next((r for r in self.rounds if r.id == round_id), None)
|
|
|
|
|
if rnd:
|
|
|
|
|
self.rounds.remove(rnd)
|
2026-01-27 11:49:37 +01:00
|
|
|
|
|
|
|
|
def get_round_index(self, round_id: str) -> int:
|
|
|
|
|
for index, rnd in enumerate(self.rounds, start=1):
|
|
|
|
|
if rnd.id == round_id:
|
|
|
|
|
return index
|
|
|
|
|
raise KeyError("Round not found in campaign")
|
2026-01-28 16:25:40 +01:00
|
|
|
|
|
|
|
|
class CampaignParticipant:
|
|
|
|
|
def __init__(self,war_participant_id: str, leader: str):
|
|
|
|
|
self.id: str = war_participant_id # ref to War.participants
|
|
|
|
|
self.leader: str = leader
|
|
|
|
|
self.victory_points = 0
|
|
|
|
|
self.objective_points = {}
|
|
|
|
|
|
|
|
|
|
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.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
|