From 6fddd88d9527bb7aa5210d49ffcaf79b6090e78d Mon Sep 17 00:00:00 2001 From: Ebo Date: Sun, 22 Sep 2024 22:09:56 -0700 Subject: [PATCH] Show the team score adjustment on score cards. There will be something like (+10000) or (-5000) if the team score has been adjusted, both on the game card and the player score card. --- assets/html/game/scorecard_sm5.html | 2 +- assets/html/game/sm5.html | 2 +- db/sm5.py | 8 +++++++- helpers/sm5helper.py | 1 + helpers/statshelper.py | 18 ++++++++++++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/assets/html/game/scorecard_sm5.html b/assets/html/game/scorecard_sm5.html index 7519d1c..6ead7e6 100644 --- a/assets/html/game/scorecard_sm5.html +++ b/assets/html/game/scorecard_sm5.html @@ -307,7 +307,7 @@

 {{entity_start.name}}

{% for team in teams %}
-

{{ team.name }} ({{ team.score }})

+

{{ team.name }}: {{ team.score }}{{ team.score_adjustment_string }}

diff --git a/assets/html/game/sm5.html b/assets/html/game/sm5.html index b1fa058..4506b9c 100644 --- a/assets/html/game/sm5.html +++ b/assets/html/game/sm5.html @@ -239,7 +239,7 @@
{% for team in teams %}
-

{{ team.element }} Team: {{ team.score }}

+

{{ team.element }} Team: {{ team.score }}{{team.score_adjustment_string}}

diff --git a/db/sm5.py b/db/sm5.py index c8453c3..6f86cf2 100644 --- a/db/sm5.py +++ b/db/sm5.py @@ -57,11 +57,17 @@ def __repr__(self) -> str: async def get_team_score(self, team: Team) -> int: # Add 10,000 extra points if this team eliminated the opposition. - adjustment = 10000 if team == self.last_team_standing else 0 + adjustment = self.get_team_score_adjustment(team) return adjustment + sum(map(lambda x: x[0], await self.entity_ends.filter(entity__team__color_name=team.element).values_list( "score"))) + def get_team_score_adjustment(self, team: Team) -> int: + """Returns how many points should be added to the team score in addition to the sum of the players' scores.""" + # The only adjustment currently is the 10k bonus for a team that eliminates another team. + return 10000 if team == self.last_team_standing else 0 + + async def get_entity_start_from_token(self, token: str) -> Optional["EntityStarts"]: return await self.entity_starts.filter(entity_id=token).first() diff --git a/helpers/sm5helper.py b/helpers/sm5helper.py index 177eb93..d32e436 100644 --- a/helpers/sm5helper.py +++ b/helpers/sm5helper.py @@ -448,6 +448,7 @@ async def get_sm5_player_stats(game: SM5Game, main_player: Optional[EntityStarts TeamSm5GameStats( team=team, score=await game.get_team_score(team), + score_adjustment=game.get_team_score_adjustment(team), players=players, sum_player=sum_player, lives_over_time=lives_over_time_team_average diff --git a/helpers/statshelper.py b/helpers/statshelper.py index 70b383b..2a8af5e 100644 --- a/helpers/statshelper.py +++ b/helpers/statshelper.py @@ -157,6 +157,10 @@ class TeamCoreGameStats: """The stats for a team for one game that apply to most game formats (at least both SM5 and LB).""" # Final team score, including adjustments. score: int + + # The score adjustment on top of the players' scores. + score_adjustment: int + team: Team @property @@ -179,6 +183,20 @@ def element(self) -> str: def color(self) -> str: return self.team.value.color + @property + def score_adjustment_string(self): + """Returns the team score adjustment as a string. Empty string if there + was no adjustment, otherwise in the format of + " (+10000)" + " (-5000)" + """ + if self.score_adjustment == 0: + return "" + + sign = "+" if self.score_adjustment > 0 else "" + + return f" ({sign}{self.score_adjustment})" + """