refactor war participant ID + fix campaign participant
This commit is contained in:
parent
ac01568c2f
commit
49bf6d7ea8
4 changed files with 55 additions and 26 deletions
|
|
@ -51,9 +51,8 @@ class Campaign:
|
|||
def get_all_campaign_participants_ids(self) -> set[str]:
|
||||
return set(self.participants.keys())
|
||||
|
||||
def has_participant(self, player_id: str) -> bool:
|
||||
##TODO change lookup id target
|
||||
return player_id in self.participants
|
||||
def has_participant(self, participant_id: str) -> bool:
|
||||
return participant_id in self.participants
|
||||
|
||||
def add_campaign_participant(
|
||||
self, war_participant_id: str, leader: str, theme: str
|
||||
|
|
@ -233,11 +232,13 @@ class Campaign:
|
|||
|
||||
|
||||
class CampaignParticipant:
|
||||
def __init__(self, *, war_participant_id: str, leader: str, theme: str):
|
||||
def __init__(
|
||||
self, *, war_participant_id: str, leader: str | None, theme: str | None
|
||||
):
|
||||
self.id: str = str(uuid4())
|
||||
self.war_participant_id: str = war_participant_id # ref to War.participants
|
||||
self.leader: str = leader
|
||||
self.theme: str = theme
|
||||
self.leader: str | None = leader
|
||||
self.theme: str | None = theme
|
||||
|
||||
def set_id(self, new_id: str):
|
||||
self.id = new_id
|
||||
|
|
@ -254,7 +255,12 @@ class CampaignParticipant:
|
|||
|
||||
class Sector:
|
||||
def __init__(
|
||||
self, name: str, round_id: str, major_id: str, minor_id: str, influence_id: str
|
||||
self,
|
||||
name: str,
|
||||
round_id: str,
|
||||
major_id: str | None,
|
||||
minor_id: str | None,
|
||||
influence_id: str | None,
|
||||
):
|
||||
self.id: str = str(uuid4())
|
||||
self.name: str = name
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ class Model:
|
|||
return war
|
||||
raise KeyError(f"Participant {participant_id} not found in any War")
|
||||
|
||||
def get_war_by_campaign_participant(self, participant_id: str) -> Campaign:
|
||||
def get_war_by_campaign_participant(self, participant_id: str) -> War:
|
||||
for war in self.wars.values():
|
||||
camp = war.get_campaign_by_campaign_participant(participant_id)
|
||||
if camp is not None:
|
||||
|
|
@ -304,6 +304,11 @@ class Model:
|
|||
camp = self.get_campaign(camp_id)
|
||||
return camp.add_campaign_participant(player_id, leader, theme)
|
||||
|
||||
def get_participant_name(self, participant_id: str) -> str:
|
||||
war = self.get_war_by_war_participant(participant_id)
|
||||
war_part = war.get_war_participant(participant_id)
|
||||
return self.players[war_part.player_id].name
|
||||
|
||||
def get_campaign_participant(self, participant_id) -> CampaignParticipant:
|
||||
for war in self.wars.values():
|
||||
for camp in war.campaigns:
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class War:
|
|||
def add_war_participant(self, player_id: str, faction: str) -> WarParticipant:
|
||||
if player_id in self.participants:
|
||||
raise ValueError("Player already registered in this war")
|
||||
participant = WarParticipant(player_id, faction)
|
||||
participant = WarParticipant(player_id=player_id, faction=faction)
|
||||
self.participants[participant.id] = participant
|
||||
return participant
|
||||
|
||||
|
|
@ -99,6 +99,7 @@ class War:
|
|||
|
||||
def update_war_participant(self, player_id: str, *, faction: str):
|
||||
part = self.get_war_participant(player_id)
|
||||
# Can't change referred Model.players
|
||||
part.set_faction(faction)
|
||||
|
||||
def remove_war_participant(self, player_id: str):
|
||||
|
|
@ -319,12 +320,16 @@ class Objective:
|
|||
|
||||
|
||||
class WarParticipant:
|
||||
def __init__(self, player_id: str, faction: str):
|
||||
self.id: str = player_id # ref to Model.players
|
||||
def __init__(self, *, player_id: str, faction: str):
|
||||
self.id: str = str(uuid4())
|
||||
self.player_id: str = player_id # ref to WarModel.players
|
||||
self.faction: str = faction
|
||||
|
||||
def set_id(self, new_id: str):
|
||||
self.id = new_id
|
||||
|
||||
def set_player(self, new_player: str):
|
||||
self.player_id = new_player
|
||||
|
||||
def set_faction(self, new_faction: str):
|
||||
self.faction = new_faction
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue