Repository navigation
Redesign Player info overlay - #2000
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds a shared renderDuration utility, updates PlayerInfoOverlay to show alliance expiration and unit icons, replaces PlayerPanel's private formatter with renderDuration, and updates English localization keys (removed Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant O as PlayerInfoOverlay
participant P as PlayerPanel
participant S as GameState/Ticks
participant R as Utils.renderDuration
U->>O: open player info
O->>S: read player, myPlayer, alliance.expiresAt
alt allied
O->>S: compute remainingSeconds
O->>R: renderDuration(remainingSeconds)
R-->>O: "Xm Ys" / "Ys"
Note right of O #DFF2E1: render AllianceIcon + "Alliance ends in …"
else not allied
Note right of O #FFF3D6: render relation badge (Neutral/Hostile)
end
Note over O: render unit row (icons + counts)
U->>P: open player panel
P->>S: compute remainingSeconds (if any)
alt has expiry
P->>R: renderDuration(remainingSeconds)
R-->>P: "Xm Ys"
P->>U: show expiry text
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/client/graphics/layers/PlayerPanel.ts (1)
197-203: Fix stale alliance timer when it hits zeroWhen remainingTicks <= 0 you never update allianceExpiryText, leaving an old value on screen. Set it to "0s" (or null) to avoid stale UI.
- if (remainingTicks > 0) { - const remainingSeconds = Math.max( - 0, - Math.floor(remainingTicks / 10), - ); // 10 ticks per second - this.allianceExpiryText = renderDuration(remainingSeconds); - } + if (remainingTicks > 0) { + const remainingSeconds = Math.floor(remainingTicks / 10); // 10 ticks/s + this.allianceExpiryText = renderDuration(remainingSeconds); + } else { + this.allianceExpiryText = renderDuration(0); // "0s" + }
🧹 Nitpick comments (8)
src/client/Utils.ts (1)
5-13: Polish duration formatting (pad seconds; optional hours)Readability nit: when minutes exist, pad seconds to 2 digits (e.g., 1m 05s). If alliances can last >59m, consider hours too. Safe-guard NaN input.
Apply:
export function renderDuration(totalSeconds: number): string { - if (totalSeconds <= 0) return "0s"; - const minutes = Math.floor(totalSeconds / 60); - const seconds = totalSeconds % 60; - let time = ""; - if (minutes > 0) time += `${minutes}m `; - time += `${seconds}s`; - return time.trim(); + if (!Number.isFinite(totalSeconds) || totalSeconds <= 0) return "0s"; + const minutes = Math.floor(totalSeconds / 60); + const seconds = Math.floor(totalSeconds % 60); + const sec = minutes > 0 ? String(seconds).padStart(2, "0") : String(seconds); + return (minutes > 0 ? `${minutes}m ${sec}s` : `${sec}s`).trim(); }src/client/graphics/layers/PlayerPanel.ts (1)
15-15: Unify Utils imports to avoid duplicate module pathsImport translateText from the same Utils path to keep module identity stable and consistent.
-import { renderDuration, renderNumber, renderTroops } from "../../Utils"; +import { renderDuration, renderNumber, renderTroops, translateText } from "../../Utils"; @@ -import { translateText } from "../../../client/Utils";Also applies to: 31-31
resources/lang/en.json (1)
486-488: Wording consistency: align alliance timeout labelsPlayer panel uses "Alliance Expires In" while overlay uses "Alliance ends in". Pick one phrase for both for a cleaner UX (suggest: “Alliance expires in”).
src/client/graphics/layers/PlayerInfoOverlay.ts (5)
12-12: Consolidate Utils imports (avoid duplicate paths)Import translateText from the same Utils path as other helpers.
-import { renderDuration, renderNumber, renderTroops } from "../../Utils"; +import { renderDuration, renderNumber, renderTroops, translateText } from "../../Utils"; @@ -import { translateText } from "../../../client/Utils";Also applies to: 28-28
204-217: De-duplicate tick-to-seconds magic number10 is repeated across files. Consider a shared constant (e.g., TICKS_PER_SECOND = 10) in a small constants module and reuse it here and in PlayerPanel.
240-255: Improve accessibility for alliance timeoutOnly an icon + numbers are shown; alt on the img may not be announced in all contexts. Add an sr-only label next to the timer.
- <span class="flex gap-2 ml-auto mr-0 text-sm font-bold"> + <span class="flex gap-2 ml-auto mr-0 text-sm font-bold"> <img src=${allianceIcon} alt=${translateText("player_info_overlay.alliance_timeout")} width="20" height="20" style="vertical-align: middle;" /> - ${this.allianceExpirationText(alliance)} + <span class="sr-only">${translateText("player_info_overlay.alliance_timeout")}:</span> + ${this.allianceExpirationText(alliance)} </span>
222-223: Avoid boolean | undefined for isAlliedCoerce to boolean to simplify conditions.
- const isAllied = myPlayer?.isAlliedWith(player); + const isAllied = !!(myPlayer && myPlayer.isAlliedWith(player));
272-272: Remove non-existent Tailwind class"text-bold" isn’t a Tailwind class; "font-bold" already present.
- class="items-center text-bold text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly + class="items-center text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
resources/lang/en.json(1 hunks)src/client/Utils.ts(1 hunks)src/client/graphics/layers/PlayerInfoOverlay.ts(4 hunks)src/client/graphics/layers/PlayerPanel.ts(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-12T00:31:50.144Z
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#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 (2)
src/client/graphics/layers/PlayerPanel.ts (1)
src/client/Utils.ts (1)
renderDuration(5-13)
src/client/graphics/layers/PlayerInfoOverlay.ts (3)
src/core/game/GameView.ts (5)
type(93-95)type(269-271)player(514-520)PlayerView(180-362)isFriendly(313-315)src/client/Utils.ts (3)
renderDuration(5-13)renderNumber(19-43)renderTroops(15-17)src/core/game/GameUpdates.ts (1)
AllianceView(173-178)
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
src/client/graphics/layers/PlayerInfoOverlay.ts (1)
192-193: Class name typo from prior review is fixed — good catch"text-sm opacity-80" is now correctly spaced; opacity applies as expected.
🧹 Nitpick comments (5)
src/client/graphics/layers/PlayerInfoOverlay.ts (5)
204-217: Don't hardcode 10 ticks/sec for alliance expiryThe 10 tps assumption can drift from server config and mislead users. Read tick rate from config (or a single source of truth) and fall back if missing. Please confirm the actual tick rate used by the game.
private allianceExpirationText( alliance: AllianceView, ) { const { expiresAt } = alliance; const remainingTicks = expiresAt - this.game.ticks(); let remainingSeconds = 0; if (remainingTicks > 0) { - remainingSeconds = Math.max( - 0, - Math.floor(remainingTicks / 10), - ); // 10 ticks per second + const tps = + // Prefer config (or another central source of truth) + (this.game.config?.().ticksPerSecond as number | undefined) ?? 10; + remainingSeconds = Math.max(0, Math.floor(remainingTicks / tps)); } return renderDuration(remainingSeconds); }If ticksPerSecond isn’t available yet, consider adding a small helper in Utils: ticksToSeconds(ticks, tps).
272-275: Remove non-existent Tailwind class “text-bold”Tailwind uses font-bold. text-bold is a no-op and adds noise.
- class="items-center text-bold text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly + class="items-center text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly
276-278: Call requestUpdate directlyrequestUpdate always exists on Lit elements; optional chaining is unnecessary here.
- this.requestUpdate?.(); + this.requestUpdate();
423-425: Drop duplicate/invalid shadow utilityshadow-xs isn’t a standard Tailwind class (unless custom). You already have shadow-lg; keep one to avoid conflicting styles.
- class="bg-gray-800/70 backdrop-blur-sm shadow-xs rounded-lg shadow-lg + class="bg-gray-800/70 backdrop-blur-sm rounded-lg shadow-lg
271-279: Add minimal a11y: expose expansion state and live updates
- Expose the details toggle state with aria-expanded on the button.
- Mark the info container as complementary and live-updating for screen readers.
<button - class="items-center text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly + class="items-center text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly ? "text-green-500" : "text-white"}" + aria-expanded=${String(this.showDetails)} @click=${() => { this.showDetails = !this.showDetails; this.requestUpdate(); }} >- <div - class="bg-gray-800/70 backdrop-blur-sm rounded-lg shadow-lg + <div + role="complementary" aria-live="polite" aria-atomic="true" + class="bg-gray-800/70 backdrop-blur-sm rounded-lg shadow-lg transition-all duration-300 text-white text-lg md:text-base ${containerClasses}" >Also applies to: 422-426
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/client/graphics/layers/PlayerInfoOverlay.ts(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/client/graphics/layers/PlayerInfoOverlay.ts (3)
src/core/game/GameView.ts (6)
type(93-95)type(269-271)player(514-520)PlayerView(180-362)myPlayer(509-512)isFriendly(313-315)src/client/Utils.ts (3)
renderDuration(5-13)renderNumber(19-43)renderTroops(15-17)src/core/game/GameUpdates.ts (1)
AllianceView(173-178)
|
mind rebasing onto main, thanks |
1d82dc0 to
4efccc8
Compare
|
Whoops, looks like I broke this when i moved assets around: 9d5c108 |
f5d983b
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (7)
src/client/PublicLobby.ts (2)
3-3: Normalize Utils import pathUse a direct, local path for clarity and to avoid brittle ups/downs.
-import { renderDuration, translateText } from "../client/Utils"; +import { renderDuration, translateText } from "./Utils";
99-103: Return an empty template instead of undefinedLit’s render should consistently return a TemplateResult.
- if (!lobby?.gameConfig) { - return; - } + if (!lobby?.gameConfig) { + return html``; + }src/client/graphics/layers/PlayerInfoOverlay.ts (5)
188-212: Show unit counts, not level sumsUI labels (“cities”, “ports”, etc.) read as counts. Use number of units instead of total levels.
- <span class="w-full text-right p-1" - >${player.totalUnitLevels(type)}</span - > + <span class="w-full text-right p-1" + >${this.game + .units(type) + .filter((u) => u.owner() === player).length}</span + >If level-sum is intended, rename the labels to “... levels”.
284-287: Remove invalid Tailwind class “text-bold”Tailwind uses font-bold; text-bold is a no-op.
- class="items-center text-bold text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly + class="items-center text-sm lg:text-lg font-bold mb-1 inline-flex break-all ${isFriendly
4-11: Assets verified; suggest barrel import or path aliasAll eight icon files exist under
resources/images. To simplify imports and avoid deep relative paths, consider:
- Adding
resources/images/index.tsto re-export all icons.- Defining a Vite/TSConfig path alias (e.g.
@images/*→resources/images/*) for cleaner imports.
445-446: Remove or define non-standard Tailwind classshadow-xs
No matchingshadow-xsentry was found in your Tailwind config, so this utility isn’t applied. Either extendtheme.extend.boxShadowwith anxskey in tailwind.config.js or remove allshadow-xsoccurrences.
214-222: Use serverConfig().turnIntervalMs() instead of hard-coding 10 tps
Replace the hard-coded tick rate with the server’s turn interval:- const remainingTicks = expiresAt - this.game.ticks(); - let remainingSeconds = 0; - if (remainingTicks > 0) { - remainingSeconds = Math.max(0, Math.floor(remainingTicks / 10)); // 10 ticks per second - } + const remainingTicks = expiresAt - this.game.ticks(); + const msPerTick = this.game.config().serverConfig().turnIntervalMs(); + const remainingSeconds = + remainingTicks > 0 + ? Math.max(0, Math.floor((remainingTicks * msPerTick) / 1000)) + : 0;This ensures the displayed duration stays correct if the server’s tick interval changes.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
resources/lang/en.json(1 hunks)src/client/PublicLobby.ts(2 hunks)src/client/graphics/layers/PlayerInfoOverlay.ts(5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- resources/lang/en.json
🔇 Additional comments (4)
src/client/PublicLobby.ts (1)
106-108: Good: centralized duration formattingUsing renderDuration(timeRemaining) keeps time display consistent across the app.
src/client/graphics/layers/PlayerInfoOverlay.ts (3)
25-30: LGTM: utilities consolidatedImporting renderDuration, renderNumber, renderTroops, translateText from one place is clean and consistent.
249-266: Allied expiration UI: clear and readableAlliance icon + formatted duration is concise and localized. Nice.
360-397: Units grid looks goodTwo-column, wrapped layout with icons improves scanability. Alt text is localized. 👍

Description:
Redesign the player info panel to match the bottom panel.
Changes:
Old:

New:

Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
IngloriousTom