Skip to content

Wapuu easter egg: lazy sprite loading#3287

Merged
sejas merged 1 commit intoeaster-egg-wapuu-platformerfrom
easter-egg-wapuu-long-press-and-lazy-sprites
Apr 30, 2026
Merged

Wapuu easter egg: lazy sprite loading#3287
sejas merged 1 commit intoeaster-egg-wapuu-platformerfrom
easter-egg-wapuu-long-press-and-lazy-sprites

Conversation

@sejas
Copy link
Copy Markdown
Member

@sejas sejas commented Apr 29, 2026

Related issues

Follow-up to #3270 addressing two review findings:

  1. Eager sprite loadingrenderer.ts instantiates 10 Image objects at module top level. wapuu-score.tsx imports MAX_SCORE from game-loop.ts, which transitively imports renderer.ts, so opening Settings → Account fires 10 sprite network requests for users who never play.

Proposed Changes

apps/studio/src/modules/wapuu-world/engine/renderer.ts

Convert module-level const sprites = { ... } to a lazy getSprites() singleton. The 9 sprites.foo call sites updated to getSprites().foo. Static import bgFarUrl from '...png' lines stay (Vite resolves these to URL strings at build time, no network cost) — only the new Image(); .src = url pair is now deferred until the first render call inside startGame().

Testing Instructions

Lazy sprite loading

  1. npm start. Open DevTools → Network tab. Clear log. Filter by wapuu.
  2. Log in and navigate to Settings → Account.
  3. Expected: only wapuu-player-idle-sprite.png loads (the score icon — direct import in wapuu-score.tsx). The other 9 sprite PNGs (wapuu-bg-far.png, wapuu-bg-near.png, wapuu-gutenberg-sprite.png, wapuu-mguy-sprite.png, wapuu-flag-sprite.png, wapuu-wave-sprite.png, wapuu-sprites-coin.png, wapuu-sprites-tiles.png, wapuu-player-sprite.png) must not appear.
  4. Trigger the game (Konami code or 4-second hold).
  5. Expected: the 9 deferred sprite PNGs now appear in the network log on game open.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors? (Tests pass, no errors)

@sejas sejas self-assigned this Apr 29, 2026
@sejas sejas requested a review from wojtekn April 29, 2026 21:10
@sejas sejas mentioned this pull request Apr 30, 2026
1 task
@wojtekn
Copy link
Copy Markdown
Contributor

wojtekn commented Apr 30, 2026

Settings click delay regression — original PR's triple-click detection delays every click on the settings gear by 200ms before opening settings. UX regression for all users.

I'm not convinced - pressing the key for some time doesn't seem like cheat codes should work. What if we removed this part completely and left the Konami code as the only way? This feels ever more fun to me.

I'm happy to merge the resource loading part.

@sejas
Copy link
Copy Markdown
Member Author

sejas commented Apr 30, 2026

Ok! I'll remove the long press modifications and merge the loading part.

Convert module-level `const sprites = { ... }` into a lazy
`getSprites()` singleton so importers (e.g. wapuu-score.tsx pulling
MAX_SCORE through game-loop.ts) don't fire 10 image network requests
at module evaluation. Sprites now load on first render call inside
startGame().
@sejas sejas force-pushed the easter-egg-wapuu-long-press-and-lazy-sprites branch from cfd5174 to 29a46ad Compare April 30, 2026 08:19
@sejas sejas changed the title Wapuu easter egg: 4s long-press + lazy sprite loading Wapuu easter egg: lazy sprite loading Apr 30, 2026
@sejas sejas merged commit 0dd8414 into easter-egg-wapuu-platformer Apr 30, 2026
3 of 6 checks passed
@sejas sejas deleted the easter-egg-wapuu-long-press-and-lazy-sprites branch April 30, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants