refacto update ; pretify code
This commit is contained in:
parent
6bd3ee31dc
commit
fbb1c913ba
11 changed files with 594 additions and 310 deletions
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import annotations
|
||||
from uuid import uuid4
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
class Round:
|
||||
def __init__(self):
|
||||
|
|
@ -20,7 +21,7 @@ class Round:
|
|||
# "sectors" : self.sectors,
|
||||
# "choices" : self.choices,
|
||||
# "battles" : self.battles,
|
||||
"is_over": self.is_over
|
||||
"is_over": self.is_over,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -32,47 +33,58 @@ class Round:
|
|||
# rnd.battles = data.get("battles", {})
|
||||
rnd.set_state(data.get("is_over", False))
|
||||
return rnd
|
||||
|
||||
# Choice methods
|
||||
|
||||
# Choice methods
|
||||
|
||||
def get_choice(self, participant_id: str) -> Choice | None:
|
||||
return self.choices.get(participant_id)
|
||||
|
||||
|
||||
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):
|
||||
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):
|
||||
def remove_choice(self, participant_id: str):
|
||||
del self.choices[participant_id]
|
||||
|
||||
# Battle methods
|
||||
# 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
|
||||
)
|
||||
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):
|
||||
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)
|
||||
|
|
@ -81,14 +93,24 @@ class Round:
|
|||
bat.set_victory_condition(victory_condition)
|
||||
bat.set_comment(comment)
|
||||
|
||||
def remove_battle(self,sector_id: str):
|
||||
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
|
||||
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):
|
||||
|
|
@ -103,11 +125,17 @@ class Choice:
|
|||
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
|
||||
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
|
||||
|
|
@ -121,7 +149,7 @@ class Battle:
|
|||
|
||||
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
|
||||
|
||||
|
|
@ -132,4 +160,4 @@ class Battle:
|
|||
self.victory_condition = new_victory_condition
|
||||
|
||||
def set_comment(self, new_comment: str):
|
||||
self.comment = new_comment
|
||||
self.comment = new_comment
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue