code quality (mypy+flake8)
This commit is contained in:
parent
7210ddc927
commit
55abdccc64
19 changed files with 778 additions and 497 deletions
|
|
@ -1,32 +1,33 @@
|
|||
from __future__ import annotations
|
||||
from uuid import uuid4
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from warchron.model.round import Round, Choice, Battle
|
||||
|
||||
|
||||
class Campaign:
|
||||
def __init__(self, name: str, month: int):
|
||||
def __init__(self, name: str, month: int) -> None:
|
||||
self.id: str = str(uuid4())
|
||||
self.name: str = name
|
||||
self.month: int = month
|
||||
self.participants: dict[str, CampaignParticipant] = {}
|
||||
self.sectors: dict[str, Sector] = {}
|
||||
self.rounds: list[Round] = []
|
||||
self.participants: Dict[str, CampaignParticipant] = {}
|
||||
self.sectors: Dict[str, Sector] = {}
|
||||
self.rounds: List[Round] = []
|
||||
self.is_over = False
|
||||
|
||||
def set_id(self, new_id: str):
|
||||
def set_id(self, new_id: str) -> None:
|
||||
self.id = new_id
|
||||
|
||||
def set_name(self, new_name: str):
|
||||
def set_name(self, new_name: str) -> None:
|
||||
self.name = new_name
|
||||
|
||||
def set_month(self, new_month: int):
|
||||
def set_month(self, new_month: int) -> None:
|
||||
self.month = new_month
|
||||
|
||||
def set_state(self, new_state: bool):
|
||||
def set_state(self, new_state: bool) -> None:
|
||||
self.is_over = new_state
|
||||
|
||||
def toDict(self):
|
||||
def toDict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"id": self.id,
|
||||
"name": self.name,
|
||||
|
|
@ -37,7 +38,7 @@ class Campaign:
|
|||
}
|
||||
|
||||
@staticmethod
|
||||
def fromDict(data: dict):
|
||||
def fromDict(data: Dict[str, Any]) -> Campaign:
|
||||
camp = Campaign(name=data["name"], month=data["month"])
|
||||
camp.set_id(data["id"])
|
||||
# camp.participants = data.get("participants", {})
|
||||
|
|
@ -77,18 +78,18 @@ class Campaign:
|
|||
except KeyError:
|
||||
raise KeyError(f"Participant {participant_id} not in campaign {self.id}")
|
||||
|
||||
def get_all_campaign_participants(self) -> list[CampaignParticipant]:
|
||||
def get_all_campaign_participants(self) -> List[CampaignParticipant]:
|
||||
return list(self.participants.values())
|
||||
|
||||
def update_campaign_participant(
|
||||
self, participant_id: str, *, leader: str, theme: str
|
||||
):
|
||||
) -> None:
|
||||
part = self.get_campaign_participant(participant_id)
|
||||
# Can't change referred War.participant
|
||||
part.set_leader(leader)
|
||||
part.set_theme(theme)
|
||||
|
||||
def remove_campaign_participant(self, participant_id: str):
|
||||
def remove_campaign_participant(self, participant_id: str) -> None:
|
||||
# TODO manage choices referring to it
|
||||
# TODO manage battles referring to it
|
||||
del self.participants[participant_id]
|
||||
|
|
@ -110,7 +111,7 @@ class Campaign:
|
|||
return ""
|
||||
return self.sectors[sector_id].name
|
||||
|
||||
def get_all_sectors(self) -> list[Sector]:
|
||||
def get_all_sectors(self) -> List[Sector]:
|
||||
return list(self.sectors.values())
|
||||
|
||||
# TODO manage choices referring to it (round order!)
|
||||
|
|
@ -123,7 +124,7 @@ class Campaign:
|
|||
major_id: str,
|
||||
minor_id: str,
|
||||
influence_id: str,
|
||||
):
|
||||
) -> None:
|
||||
sect = self.get_sector(sector_id)
|
||||
sect.set_name(name)
|
||||
sect.set_round(round_id)
|
||||
|
|
@ -131,12 +132,12 @@ class Campaign:
|
|||
sect.set_minor(minor_id)
|
||||
sect.set_influence(influence_id)
|
||||
|
||||
def remove_sector(self, sector_id: str):
|
||||
def remove_sector(self, sector_id: str) -> None:
|
||||
# TODO manage choices referring to it
|
||||
# TODO manage battles referring to it
|
||||
del self.sectors[sector_id]
|
||||
|
||||
def get_sectors_in_round(self, round_id: str) -> list[Sector]:
|
||||
def get_sectors_in_round(self, round_id: str) -> List[Sector]:
|
||||
sectors = [s for s in self.sectors.values() if s.round_id == round_id]
|
||||
return sectors
|
||||
|
||||
|
|
@ -151,7 +152,7 @@ class Campaign:
|
|||
return rnd
|
||||
raise KeyError(f"Round {round_id} not found")
|
||||
|
||||
def get_all_rounds(self) -> list[Round]:
|
||||
def get_all_rounds(self) -> List[Round]:
|
||||
return list(self.rounds)
|
||||
|
||||
def add_round(self) -> Round:
|
||||
|
|
@ -159,7 +160,7 @@ class Campaign:
|
|||
self.rounds.append(round)
|
||||
return round
|
||||
|
||||
def remove_round(self, round_id: str):
|
||||
def remove_round(self, round_id: str) -> None:
|
||||
rnd = next((r for r in self.rounds if r.id == round_id), None)
|
||||
if rnd:
|
||||
self.rounds.remove(rnd)
|
||||
|
|
@ -172,14 +173,6 @@ class Campaign:
|
|||
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 ""
|
||||
|
||||
# Choice methods
|
||||
|
||||
def create_choice(self, round_id: str, participant_id: str) -> Choice:
|
||||
|
|
@ -193,13 +186,13 @@ class Campaign:
|
|||
priority_sector_id: str | None,
|
||||
secondary_sector_id: str | None,
|
||||
comment: str | None,
|
||||
):
|
||||
) -> None:
|
||||
rnd = self.get_round(round_id)
|
||||
rnd.update_choice(
|
||||
participant_id, priority_sector_id, secondary_sector_id, comment
|
||||
)
|
||||
|
||||
def remove_choice(self, round_id: str, participant_id: str) -> Choice:
|
||||
def remove_choice(self, round_id: str, participant_id: str) -> None:
|
||||
rnd = self.get_round(round_id)
|
||||
rnd.remove_choice(participant_id)
|
||||
|
||||
|
|
@ -219,7 +212,7 @@ class Campaign:
|
|||
score: str | None,
|
||||
victory_condition: str | None,
|
||||
comment: str | None,
|
||||
):
|
||||
) -> None:
|
||||
rnd = self.get_round(round_id)
|
||||
rnd.update_battle(
|
||||
sector_id,
|
||||
|
|
@ -231,7 +224,7 @@ class Campaign:
|
|||
comment,
|
||||
)
|
||||
|
||||
def remove_battle(self, round_id: str, sector_id: str) -> Battle:
|
||||
def remove_battle(self, round_id: str, sector_id: str) -> None:
|
||||
rnd = self.get_round(round_id)
|
||||
rnd.remove_battle(sector_id)
|
||||
|
||||
|
|
@ -245,16 +238,16 @@ class CampaignParticipant:
|
|||
self.leader: str | None = leader
|
||||
self.theme: str | None = theme
|
||||
|
||||
def set_id(self, new_id: str):
|
||||
def set_id(self, new_id: str) -> None:
|
||||
self.id = new_id
|
||||
|
||||
def set_war_participant(self, new_participant: str):
|
||||
def set_war_participant(self, new_participant: str) -> None:
|
||||
self.war_participant_id = new_participant
|
||||
|
||||
def set_leader(self, new_faction: str):
|
||||
def set_leader(self, new_faction: str) -> None:
|
||||
self.leader = new_faction
|
||||
|
||||
def set_theme(self, new_theme: str):
|
||||
def set_theme(self, new_theme: str) -> None:
|
||||
self.theme = new_theme
|
||||
|
||||
|
||||
|
|
@ -276,20 +269,20 @@ class Sector:
|
|||
self.mission: str | None = None
|
||||
self.description: str | None = None
|
||||
|
||||
def set_id(self, new_id: str):
|
||||
def set_id(self, new_id: str) -> None:
|
||||
self.id = new_id
|
||||
|
||||
def set_name(self, new_name: str):
|
||||
def set_name(self, new_name: str) -> None:
|
||||
self.name = new_name
|
||||
|
||||
def set_round(self, new_round_id: str):
|
||||
def set_round(self, new_round_id: str) -> None:
|
||||
self.round_id = new_round_id
|
||||
|
||||
def set_major(self, new_major_id: str):
|
||||
def set_major(self, new_major_id: str) -> None:
|
||||
self.major_objective_id = new_major_id
|
||||
|
||||
def set_minor(self, new_minor_id: str):
|
||||
def set_minor(self, new_minor_id: str) -> None:
|
||||
self.minor_objective_id = new_minor_id
|
||||
|
||||
def set_influence(self, new_influence_id: str):
|
||||
def set_influence(self, new_influence_id: str) -> None:
|
||||
self.influence_objective_id = new_influence_id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue