Repository navigation
Feat: Add troop count bar to PlayerInfoOverlay - #2773
Conversation
WalkthroughThis pull request adds a new troop-bar visualization to the PlayerInfoOverlay component. It introduces a private method that computes and renders a two-color bar showing total troops and attacking troops relative to a maximum capacity, integrated into the existing player information display. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/client/graphics/layers/PlayerInfoOverlay.ts (2)
458-477: Consider adding tooltips for clarity.The bar has no visual legend explaining that green represents total troops and orange represents attacking troops. Consider adding a title attribute or tooltip on hover to clarify what users are seeing.
Possible enhancement with tooltips
return html` <div class="w-full mt-2 mb-2 h-5 border border-gray-600 rounded-md bg-gray-900/60 overflow-hidden" + title="${translateText('player_info_overlay.troop_bar_tooltip')}" >You'd also need to add the translation key to
en.json:"player_info_overlay.troop_bar_tooltip": "Green: troops available, Orange: troops attacking"
458-477: Consider accessibility for screen readers.The troop bar is purely visual with no text alternative. Consider adding an
aria-labelto describe what the bar represents for screen reader users.Possible accessibility enhancement
return html` <div class="w-full mt-2 mb-2 h-5 border border-gray-600 rounded-md bg-gray-900/60 overflow-hidden" + role="progressbar" + aria-label="${translateText('player_info_overlay.troop_capacity')}: ${greenPercent.toFixed(0)}%" + aria-valuenow="${greenPercent}" + aria-valuemin="0" + aria-valuemax="100" >
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/client/graphics/layers/PlayerInfoOverlay.ts
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: Foorack
Repo: openfrontio/OpenFrontIO PR: 2141
File: src/client/ClientGameRunner.ts:228-234
Timestamp: 2025-10-08T17:14:49.369Z
Learning: For the window close confirmation feature in `ClientGameRunner.ts`, the troop count requirement (>10,000 troops) from issue #2137 was intentionally removed because it was arbitrary and troop count can be reported as low despite having significant land. The confirmation now triggers for any alive player regardless of troop count.
Learnt from: 1brucben
Repo: openfrontio/OpenFrontIO PR: 977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.
📚 Learning: 2025-05-31T18:15:03.445Z
Learnt from: 1brucben
Repo: openfrontio/OpenFrontIO PR: 977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.
Applied to files:
src/client/graphics/layers/PlayerInfoOverlay.ts
📚 Learning: 2025-10-08T17:14:49.369Z
Learnt from: Foorack
Repo: openfrontio/OpenFrontIO PR: 2141
File: src/client/ClientGameRunner.ts:228-234
Timestamp: 2025-10-08T17:14:49.369Z
Learning: For the window close confirmation feature in `ClientGameRunner.ts`, the troop count requirement (>10,000 troops) from issue #2137 was intentionally removed because it was arbitrary and troop count can be reported as low despite having significant land. The confirmation now triggers for any alive player regardless of troop count.
Applied to files:
src/client/graphics/layers/PlayerInfoOverlay.ts
📚 Learning: 2025-08-12T00:31:50.144Z
Learnt from: scottanderson
Repo: openfrontio/OpenFrontIO PR: 1752
File: src/core/game/Game.ts:750-752
Timestamp: 2025-08-12T00:31:50.144Z
Learning: In the OpenFrontIO codebase, changes to the PlayerInteraction interface (like adding canDonateGold and canDonateTroops flags) do not require corresponding updates to src/core/Schemas.ts or server serialization code.
Applied to files:
src/client/graphics/layers/PlayerInfoOverlay.ts
🧬 Code graph analysis (1)
src/client/graphics/layers/PlayerInfoOverlay.ts (3)
src/core/game/GameImpl.ts (1)
player(483-489)src/core/game/GameView.ts (1)
player(732-738)src/core/configuration/DefaultConfig.ts (1)
maxTroops(805-836)
🔇 Additional comments (2)
src/client/graphics/layers/PlayerInfoOverlay.ts (2)
262-262: Clean variable extraction.Extracting
totalTroopshere makes line 382 more readable.
382-382: Good placement for the troop bar.Rendering the bar between troop stats and resources makes sense.
Description:
This feature adds a troop count bar into the PlayerInfoOverlay that visualizes how many troops a player/nation has, how big of an attack they are sending, and in general the percentages of their overall troop count. I originally added the toggling of this feature as a setting but thought it might be too narrow to need it's own setting. Would appreciate anyone's thoughts on adding it back in or not.
Inspired by this comment in the Dev Discord.
Video Demo
Screen.Recording.2026-01-02.182901.mp4
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
bijx