From 002d450e8d2d203469995e0973d725d99cdfed3c Mon Sep 17 00:00:00 2001 From: Killersoren <45606328+Killersoren@users.noreply.github.com> Date: Sun, 17 Aug 2025 20:57:13 +0200 Subject: [PATCH] Add total units / buildings view to the teamstats component (#884) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description: Closes #883 Adds the ability to see combined Launchers, SAMS, Warships & Cities per team on the TeamStats component Skærmbillede 2025-08-17 112010 Skærmbillede 2025-08-17 112122 ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: Killersoren --------- Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- resources/lang/en.json | 8 +- src/client/graphics/layers/TeamStats.ts | 159 ++++++++++++++++-------- 2 files changed, 111 insertions(+), 56 deletions(-) diff --git a/resources/lang/en.json b/resources/lang/en.json index 34eec63f9..46048063f 100644 --- a/resources/lang/en.json +++ b/resources/lang/en.json @@ -453,7 +453,13 @@ "team": "Team", "owned": "Owned", "gold": "Gold", - "troops": "Troops" + "troops": "Troops", + "launchers": "Launchers", + "sams": "SAMs", + "warships": "Warships", + "cities": "Cities", + "show_control": "Show Control", + "show_units": "Show Units" }, "player_info_overlay": { "type": "Type", diff --git a/src/client/graphics/layers/TeamStats.ts b/src/client/graphics/layers/TeamStats.ts index 2a1af49d6..44540048f 100644 --- a/src/client/graphics/layers/TeamStats.ts +++ b/src/client/graphics/layers/TeamStats.ts @@ -1,7 +1,7 @@ import { LitElement, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { EventBus } from "../../../core/EventBus"; -import { GameMode, Team } from "../../../core/game/Game"; +import { GameMode, Team, UnitType } from "../../../core/game/Game"; import { GameView, PlayerView } from "../../../core/game/GameView"; import { renderNumber, translateText } from "../../Utils"; import { Layer } from "./Layer"; @@ -11,6 +11,10 @@ type TeamEntry = { totalScoreStr: string; totalGold: string; totalTroops: string; + totalSAMs: string; + totalLaunchers: string; + totalWarShips: string; + totalCities: string; totalScoreSort: number; players: PlayerView[]; }; @@ -23,6 +27,7 @@ export class TeamStats extends LitElement implements Layer { @property({ type: Boolean }) visible = false; teams: TeamEntry[] = []; private _shownOnInit = false; + private showUnits = false; createRenderRoot() { return this; // use light DOM for Tailwind @@ -61,12 +66,20 @@ export class TeamStats extends LitElement implements Layer { let totalGold = 0n; let totalTroops = 0; let totalScoreSort = 0; + let totalSAMs = 0; + let totalLaunchers = 0; + let totalWarShips = 0; + let totalCities = 0; for (const p of teamPlayers) { if (p.isAlive()) { totalTroops += p.troops(); totalGold += p.gold(); totalScoreSort += p.numTilesOwned(); + totalLaunchers += p.totalUnitLevels(UnitType.MissileSilo); + totalSAMs += p.totalUnitLevels(UnitType.SAMLauncher); + totalWarShips += p.totalUnitLevels(UnitType.Warship); + totalCities += p.totalUnitLevels(UnitType.City); } } @@ -79,6 +92,11 @@ export class TeamStats extends LitElement implements Layer { totalGold: renderNumber(totalGold), totalTroops: renderNumber(totalTroops / 10), players: teamPlayers, + + totalLaunchers: renderNumber(totalLaunchers), + totalSAMs: renderNumber(totalSAMs), + totalWarShips: renderNumber(totalWarShips), + totalCities: renderNumber(totalCities), }; }) .sort((a, b) => b.totalScoreSort - a.totalScoreSort); @@ -93,73 +111,104 @@ export class TeamStats extends LitElement implements Layer { } render() { - if (!this.visible) { - return html``; - } + if (!this.visible) return html``; + return html`
e.preventDefault()} >
- +
-
+
${translateText("leaderboard.team")}
-
- ${translateText("leaderboard.owned")} -
-
- ${translateText("leaderboard.gold")} -
-
- ${translateText("leaderboard.troops")} -
+ ${this.showUnits + ? html` +
+ ${translateText("leaderboard.launchers")} +
+
+ ${translateText("leaderboard.sams")} +
+
+ ${translateText("leaderboard.warships")} +
+
+ ${translateText("leaderboard.cities")} +
+ ` + : html` +
+ ${translateText("leaderboard.owned")} +
+
+ ${translateText("leaderboard.gold")} +
+
+ ${translateText("leaderboard.troops")} +
+ `}
- ${this.teams.map( - (team) => html` -
-
- ${team.teamName} -
-
- ${team.totalScoreStr} -
-
- ${team.totalGold} -
-
- ${team.totalTroops} -
-
- `, + + + ${this.teams.map((team) => + this.showUnits + ? html` +
+
+ ${team.teamName} +
+
+ ${team.totalLaunchers} +
+
+ ${team.totalSAMs} +
+
+ ${team.totalWarShips} +
+
+ ${team.totalCities} +
+
+ ` + : html` +
+
+ ${team.teamName} +
+
+ ${team.totalScoreStr} +
+
+ ${team.totalGold} +
+
+ ${team.totalTroops} +
+
+ `, )}
+
`; }