auto create & edit battles
This commit is contained in:
parent
9f676f6b9d
commit
6bd3ee31dc
10 changed files with 442 additions and 55 deletions
|
|
@ -108,6 +108,13 @@ class Campaign:
|
|||
# TODO manage battles referring to it
|
||||
del self.sectors[sector_id]
|
||||
|
||||
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
|
||||
|
||||
# Round methods
|
||||
|
||||
def has_round(self, round_id: str) -> bool:
|
||||
|
|
@ -158,8 +165,18 @@ class Campaign:
|
|||
rnd = self.get_round(round_id)
|
||||
rnd.remove_choice(participant_id)
|
||||
|
||||
# Battle methods
|
||||
|
||||
def create_battle(self, round_id: str, sector_id: str) -> Battle:
|
||||
rnd = self.get_round(round_id)
|
||||
return rnd.create_battle(sector_id)
|
||||
|
||||
def remove_battle(self, round_id: str, sector_id: str) -> Battle:
|
||||
rnd = self.get_round(round_id)
|
||||
rnd.remove_battle(sector_id)
|
||||
|
||||
class CampaignParticipant:
|
||||
def __init__(self,player_id: str, leader: str, theme: str):
|
||||
def __init__(self, player_id: str, leader: str, theme: str):
|
||||
self.id: str = player_id # ref to War.participants
|
||||
self.leader: str = leader
|
||||
self.theme: str = theme
|
||||
|
|
@ -181,6 +198,8 @@ class Sector:
|
|||
self.major_objective_id: str | None = major_id # ref to War.objectives
|
||||
self.minor_objective_id: str | None = minor_id # ref to War.objectives
|
||||
self.influence_objective_id: str | None = influence_id # ref to War.objectives
|
||||
self.mission: str | None = None
|
||||
self.description: str | None = None
|
||||
|
||||
def set_id(self, new_id: str):
|
||||
self.id = new_id
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ class Model:
|
|||
war = self.get_war_by_round(round_id)
|
||||
war.remove_round(round_id)
|
||||
|
||||
# Choices methods
|
||||
# Choice methods
|
||||
|
||||
def create_choice(self, round_id: str, participant_id: str) -> Choice:
|
||||
war = self.get_war_by_round(round_id)
|
||||
|
|
@ -337,3 +337,14 @@ class Model:
|
|||
if s.round_id == round_id
|
||||
]
|
||||
return camp, rnd, participants, sectors
|
||||
|
||||
# Battle methods
|
||||
|
||||
def create_battle(self, round_id: str, sector_id: str) -> Battle:
|
||||
war = self.get_war_by_round(round_id)
|
||||
return war.create_battle(round_id, sector_id)
|
||||
|
||||
def remove_battle(self, round_id: str, sector_id: str):
|
||||
war = self.get_war_by_round(round_id)
|
||||
war.remove_battle(round_id, sector_id)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,9 +14,6 @@ class Round:
|
|||
def set_state(self, new_state: bool):
|
||||
self.is_over = new_state
|
||||
|
||||
def set_choice(self, participant_id: str, priority_sector_id: str | None, secondary_sector_id: str | None):
|
||||
self.choices[participant_id] = Choice(participant_id, priority_sector_id, secondary_sector_id)
|
||||
|
||||
def toDict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
|
|
@ -36,7 +33,7 @@ class Round:
|
|||
rnd.set_state(data.get("is_over", False))
|
||||
return rnd
|
||||
|
||||
# Choices methods
|
||||
# Choice methods
|
||||
|
||||
def get_choice(self, participant_id: str) -> Choice | None:
|
||||
return self.choices.get(participant_id)
|
||||
|
|
@ -44,24 +41,95 @@ class Round:
|
|||
def create_choice(self, participant_id: str) -> Choice:
|
||||
if participant_id not in self.choices:
|
||||
choice = Choice(
|
||||
participant_id=participant_id,
|
||||
priority_sector_id=None,
|
||||
secondary_sector_id=None
|
||||
participant_id = participant_id,
|
||||
priority_sector_id = None,
|
||||
secondary_sector_id = None
|
||||
)
|
||||
self.choices[participant_id] = choice
|
||||
return self.choices[participant_id]
|
||||
|
||||
def update_choice(self, participant_id: str, priority_sector_id: str | None, secondary_sector_id: str | None, comment: str | None):
|
||||
choice = self.get_choice(participant_id)
|
||||
choice.set_priority(priority_sector_id)
|
||||
choice.set_secondary(secondary_sector_id)
|
||||
choice.set_comment(comment)
|
||||
|
||||
def remove_choice(self,participant_id: str):
|
||||
del self.choices[participant_id]
|
||||
|
||||
# Battle methods
|
||||
|
||||
def get_battle(self, sector_id: str) -> Battle | None:
|
||||
return self.battles.get(sector_id)
|
||||
|
||||
def create_battle(self, sector_id: str) -> Battle:
|
||||
if sector_id not in self.battles:
|
||||
battle = Battle(
|
||||
sector_id = sector_id,
|
||||
player_1_id = None,
|
||||
player_2_id = None
|
||||
)
|
||||
self.battles[sector_id] = battle
|
||||
return self.battles[sector_id]
|
||||
|
||||
def update_battle(self, sector_id: str, player_1_id: str | None, player_2_id: str | None, winner_id: str | None, score: str | None, victory_condition: str | None, comment: str | None):
|
||||
bat = self.get_battle(sector_id)
|
||||
bat.set_player_1(player_1_id)
|
||||
bat.set_player_2(player_2_id)
|
||||
bat.set_winner(winner_id)
|
||||
bat.set_score(score)
|
||||
bat.set_victory_condition(victory_condition)
|
||||
bat.set_comment(comment)
|
||||
|
||||
def remove_battle(self,sector_id: str):
|
||||
del self.battles[sector_id]
|
||||
|
||||
class Choice:
|
||||
def __init__(self, participant_id: str, priority_sector_id: str | None = None, secondary_sector_id: str | None = None):
|
||||
self.participant_id: str = participant_id # ref to Campaign.participants
|
||||
self.priority_sector_id: str | None = priority_sector_id # ref to Campaign.sectors
|
||||
self.secondary_sector_id: str | None = secondary_sector_id # ref to Campaign.sectors
|
||||
self.comment: str | None = None
|
||||
|
||||
def set_id(self, new_id: str):
|
||||
self.participant_id = new_id
|
||||
|
||||
def set_priority(self, new_priority_id: str):
|
||||
self.priority_sector_id = new_priority_id
|
||||
|
||||
def set_secondary(self, new_secondary_id: str):
|
||||
self.secondary_sector_id = new_secondary_id
|
||||
|
||||
def set_comment(self, new_comment: str):
|
||||
self.comment = new_comment
|
||||
|
||||
class Battle:
|
||||
def __init__(self, sector_id: str, player_1_id: str | None = None, player_2_id: str | None = None):
|
||||
self.sector_id: str = sector_id # ref to Campaign.sector
|
||||
self.player_1_id: str | None = player_1_id # ref to Campaign.participants
|
||||
self.player_2_id: str | None = player_2_id # ref to Campaign.participants
|
||||
self.winner_id: str | None = None
|
||||
self.score: str | None = None
|
||||
self.victory_condition: str | None = None
|
||||
self.comment: str | None = None
|
||||
|
||||
def set_id(self, new_id: str):
|
||||
self.sector_id = new_id
|
||||
|
||||
def set_player_1(self, new_player_id: str):
|
||||
self.player_1_id = new_player_id
|
||||
|
||||
def set_player_2(self, new_player_id: str):
|
||||
self.player_2_id = new_player_id
|
||||
|
||||
def set_winner(self, new_player_id: str):
|
||||
self.winner_id = new_player_id
|
||||
|
||||
def set_score(self, new_score: str):
|
||||
self.score = new_score
|
||||
|
||||
def set_victory_condition(self, new_victory_condition: str):
|
||||
self.victory_condition = new_victory_condition
|
||||
|
||||
def set_comment(self, new_comment: str):
|
||||
self.comment = new_comment
|
||||
|
|
@ -177,7 +177,7 @@ class War:
|
|||
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]:
|
||||
|
|
@ -227,6 +227,16 @@ class War:
|
|||
camp = self.get_campaign_by_round(round_id)
|
||||
camp.remove_choice(round_id, participant_id)
|
||||
|
||||
# Battle methods
|
||||
|
||||
def create_battle(self, round_id: str, sector_id: str) -> Battle:
|
||||
camp = self.get_campaign_by_round(round_id)
|
||||
return camp.create_battle(round_id, sector_id)
|
||||
|
||||
def remove_battle(self, round_id: str, sector_id: str):
|
||||
camp = self.get_campaign_by_round(round_id)
|
||||
camp.remove_battle(round_id, sector_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