Add Water and Wilderness info overlays#3615
Add Water and Wilderness info overlays#3615camclark wants to merge 2 commits intoopenfrontio:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughA water info overlay was added to PlayerInfoOverlay with two new translation keys; new reactive flags track water/wilderness tiles, render conditionally, hide resets state, and tests cover behaviors for water, wilderness, land, players, and hiding. Changes
Sequence DiagramsequenceDiagram
participant User
participant PlayerInfoOverlay
participant TileService
participant Translator
participant Renderer
User->>PlayerInfoOverlay: hover(x,y)
activate PlayerInfoOverlay
PlayerInfoOverlay->>TileService: queryTile(x,y)
activate TileService
alt tile is water
TileService-->>PlayerInfoOverlay: tileType = water
PlayerInfoOverlay->>PlayerInfoOverlay: set _isWater = true
PlayerInfoOverlay->>TileService: findNearbyShips(x,y)
TileService-->>PlayerInfoOverlay: ships or none
else tile is land
TileService-->>PlayerInfoOverlay: tileType = land/unowned or player-owned
PlayerInfoOverlay->>PlayerInfoOverlay: set _isWilderness or player info
end
deactivate TileService
PlayerInfoOverlay->>Translator: translateText(water_title or wilderness_title)
activate Translator
Translator-->>PlayerInfoOverlay: localized title
deactivate Translator
PlayerInfoOverlay->>Renderer: render overlay with conditional title and unit/player info
activate Renderer
Renderer-->>User: show overlay
deactivate Renderer
deactivate PlayerInfoOverlay
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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.
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/PlayerInfoOverlay.ts (1)
137-143:⚠️ Potential issue | 🟡 MinorClear
playerProfileon hide and guard async profile updates.
playerProfileis not reset inhide(), and asyncprofile()responses can land after cursor moved, leaving stale relation data in subsequent renders.💡 Suggested fix
export class PlayerInfoOverlay extends LitElement implements Layer { + private profileRequestId = 0; + public hide() { + this.profileRequestId++; this.setVisible(false); this.unit = null; this.player = null; + this.playerProfile = null; this.isWater = false; this.isWilderness = false; } public maybeShow(x: number, y: number) { this.hide(); @@ if (owner && owner.isPlayer()) { this.player = owner as PlayerView; - this.player.profile().then((p) => { - this.playerProfile = p; - }); + const requestId = this.profileRequestId; + this.player.profile().then((p) => { + if (this.profileRequestId === requestId) { + this.playerProfile = p; + } + }); this.setVisible(true);Also applies to: 159-161
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/client/graphics/layers/PlayerInfoOverlay.ts` around lines 137 - 143, The hide() method currently resets unit, player, isWater and isWilderness but does not clear playerProfile, so add clearing of this.playerProfile inside hide() (alongside setVisible(false), this.unit = null, this.player = null, etc.). Also guard asynchronous profile updates in the profile() handler (or wherever the async fetch resolves) by validating that the response still pertains to the current cursor target before assigning this.playerProfile (e.g., compare the response's playerId/unitId to this.player/this.unit or check this.visible), so late responses cannot overwrite state for a different hovered unit. Ensure both the hide() change and the guard in the async resolution are implemented.
🧹 Nitpick comments (1)
tests/client/graphics/layers/PlayerInfoOverlay.test.ts (1)
85-191: Nice state coverage; add one render-level assertion for title keys.Current tests prove state transitions, but they don’t directly verify that render uses
player_info_overlay.water_title/player_info_overlay.wilderness_title.✅ Minimal test extension
+import { translateText } from "../../../../src/client/Utils"; @@ describe("maybeShow", () => { @@ + test("render uses water title translation key", () => { + const { overlay } = makeOverlay(); + overlay.maybeShow(100, 100); + overlay.render(); + expect(translateText).toHaveBeenCalledWith( + "player_info_overlay.water_title", + ); + }); + + test("render uses wilderness title translation key", () => { + const { overlay } = makeOverlay({ + isLand: vi.fn(() => true), + }); + overlay.maybeShow(100, 100); + overlay.render(); + expect(translateText).toHaveBeenCalledWith( + "player_info_overlay.wilderness_title", + ); + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/client/graphics/layers/PlayerInfoOverlay.test.ts` around lines 85 - 191, Add a small render-level assertion after existing state checks to ensure the component actually uses the translation keys: after calling overlay.maybeShow(...) (from makeOverlay) assert the rendered output/text/DOM contains the literal keys "player_info_overlay.water_title" when (overlay as any).isWater is true and "player_info_overlay.wilderness_title" when (overlay as any).isWilderness is true; keep these as short additional expectations in the existing tests that verify water and wilderness behavior so you validate rendering as well as state.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/client/graphics/layers/PlayerInfoOverlay.ts`:
- Around line 137-143: The hide() method currently resets unit, player, isWater
and isWilderness but does not clear playerProfile, so add clearing of
this.playerProfile inside hide() (alongside setVisible(false), this.unit = null,
this.player = null, etc.). Also guard asynchronous profile updates in the
profile() handler (or wherever the async fetch resolves) by validating that the
response still pertains to the current cursor target before assigning
this.playerProfile (e.g., compare the response's playerId/unitId to
this.player/this.unit or check this.visible), so late responses cannot overwrite
state for a different hovered unit. Ensure both the hide() change and the guard
in the async resolution are implemented.
---
Nitpick comments:
In `@tests/client/graphics/layers/PlayerInfoOverlay.test.ts`:
- Around line 85-191: Add a small render-level assertion after existing state
checks to ensure the component actually uses the translation keys: after calling
overlay.maybeShow(...) (from makeOverlay) assert the rendered output/text/DOM
contains the literal keys "player_info_overlay.water_title" when (overlay as
any).isWater is true and "player_info_overlay.wilderness_title" when (overlay as
any).isWilderness is true; keep these as short additional expectations in the
existing tests that verify water and wilderness behavior so you validate
rendering as well as state.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1b40c707-5dab-48df-9578-feed697cf657
📒 Files selected for processing (3)
resources/lang/en.jsonsrc/client/graphics/layers/PlayerInfoOverlay.tstests/client/graphics/layers/PlayerInfoOverlay.test.ts
Description:
Resolves #3011
Test plan
npm testpasses (all existing + 6 new tests)