Skip to content

Fix missing boat sprite icon in attacks panel#4141

Open
camclark wants to merge 3 commits into
openfrontio:mainfrom
camclark:fix/4100-boat-sprite-icon
Open

Fix missing boat sprite icon in attacks panel#4141
camclark wants to merge 3 commits into
openfrontio:mainfrom
camclark:fix/4100-boat-sprite-icon

Conversation

@camclark

@camclark camclark commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Resolves #4100

Description:

The boat row in the attacks panel (bottom-right UI) rendered an empty slot where the tinted boat sprite icon should appear, for both incoming and outgoing transport boats.

Root cause: loadAllSprites() in SpriteLoader.ts was never called. It was previously invoked by a canvas layer that has since been deleted, so the sprite map stayed empty. As a result getColoredSprite() threw, AttacksDisplay.getBoatSpriteDataURL() caught the error and returned "", and the icon rendered blank.

This fix calls loadAllSprites() from AttacksDisplay.init() (currently the only consumer of the sprite loader), so the sprite map is populated at startup.

Demo after fix:

CleanShot 2026-06-03 at 18 51 01

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file (N/A — no user-facing text added; only a console error log)
  • I have added relevant tests to the test directory (smoke tested locally, see demo recording above)

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

cool_clarky

@camclark camclark requested a review from a team as a code owner June 3, 2026 08:46
@github-actions github-actions Bot added the small-fix Small fix (≤ 50 lines) — auto-applied by PR gate label Jun 3, 2026
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0b53ebcd-c2ad-4867-8130-f301a22b3e9c

📥 Commits

Reviewing files that changed from the base of the PR and between 84d7787 and e43cccb.

📒 Files selected for processing (1)
  • src/client/hud/GameRenderer.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/client/hud/GameRenderer.ts

Walkthrough

GameRenderer.ts adds controller imports to wire additional HUD layers and imports loadAllSprites to preload sprite assets. During initialization, it invokes sprite preloading asynchronously with error handling to populate the sprite map before rendering begins.

Changes

Sprite Preloading in Renderer Setup

Layer / File(s) Summary
Sprite preloading initialization in GameRenderer
src/client/hud/GameRenderer.ts
GameRenderer imports additional HUD controller dependencies and loadAllSprites, then invokes sprite preloading asynchronously during initialize() with error logging to ensure sprite data is available at startup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • evanpelle

Poem

🎨 Sprites awaken at the renderer's dawn,
Preloaded bright before the scene is drawn,
No more empty slots where icons should gleam—
The boat sprites sail through the startup stream! ⛵

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title mentions a boat sprite icon fix, but the code changes show broader HUD renderer wiring improvements beyond just the attacks panel. Clarify whether the title should reflect the specific fix (boat sprite in attacks panel) or the broader renderer changes (HUD controller imports and sprite preloading).
Out of Scope Changes check ❓ Inconclusive The file summary shows additional HUD controller imports and import reordering beyond the sprite preloading fix described in the PR description. Confirm whether importing additional HUD controllers is part of a separate refactoring or is necessary for the sprite-loading fix.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the root cause, the fix approach, and includes demo screenshots showing the resolved issue.
Linked Issues check ✅ Passed The PR directly addresses #4100 by calling loadAllSprites() to populate the sprite map, restoring the colored boat sprite icon in the attacks panel as required.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 3, 2026
Comment thread src/client/hud/layers/AttacksDisplay.ts Outdated
Comment on lines +50 to +54
init() {
loadAllSprites().catch((err) =>
console.error("Failed to preload attack display sprites:", err),
);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe instead we should move it to GameRenderer.initialize(), since multiple layers use sprites.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call - done :)

@evanpelle evanpelle added this to the v32 milestone Jun 4, 2026
@camclark camclark requested a review from evanpelle June 9, 2026 11:14
camclark added 3 commits June 9, 2026 21:16
Call loadAllSprites() from AttacksDisplay.init() so the sprite map is
populated at startup. It was previously loaded by a deleted canvas layer,
leaving the map empty and causing boat row icons to render blank.

Fixes openfrontio#4100
@camclark camclark force-pushed the fix/4100-boat-sprite-icon branch from 84d7787 to e43cccb Compare June 9, 2026 11:16

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/client/hud/GameRenderer.ts (1)

352-354: 💤 Low value

Consider awaiting sprite preload for deterministic startup order.

The current fire-and-forget approach degrades gracefully (render paths retry and cache on success), but you could make the startup sequence more predictable:

await loadAllSprites().catch((err) =>
  console.error("Failed to preload sprites:", err),
);

This would guarantee sprites are loaded before layer.init() runs. The tradeoff is that initialization blocks until all sprites load, which could delay the first frame. Since your tests confirm the current approach works, this is optional—but it removes the timing window where icons might briefly appear blank.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/client/hud/GameRenderer.ts` around lines 352 - 354, Change the
fire-and-forget sprite preload to an awaited preload before initializing layers:
call and await loadAllSprites() (retaining the existing .catch logging) and only
after it resolves call layer.init() so that sprite assets are guaranteed loaded
before layer.init() runs; update the startup sequence where loadAllSprites() is
invoked (and where layer.init() is called) to reflect this await and ensure
errors from loadAllSprites() are still logged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/client/hud/GameRenderer.ts`:
- Around line 352-354: Change the fire-and-forget sprite preload to an awaited
preload before initializing layers: call and await loadAllSprites() (retaining
the existing .catch logging) and only after it resolves call layer.init() so
that sprite assets are guaranteed loaded before layer.init() runs; update the
startup sequence where loadAllSprites() is invoked (and where layer.init() is
called) to reflect this await and ensure errors from loadAllSprites() are still
logged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bc107810-af75-478a-85bc-61e24b5db33c

📥 Commits

Reviewing files that changed from the base of the PR and between 72e519c and 84d7787.

📒 Files selected for processing (1)
  • src/client/hud/GameRenderer.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

small-fix Small fix (≤ 50 lines) — auto-applied by PR gate

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

Bug: Boat row missing its sprite icon in the attacks panel

2 participants