Spaces:
Running
Running
Commit ยท
f6cb8e2
1
Parent(s): 7367071
Add implementation plan for theme-specific scenes
Browse filesVerified two of the plan's test patterns empirically before finalizing:
app.storage.user requires a real nicegui.testing.User session (a bare script
raises RuntimeError), and parametrize + module_under_test + the user fixture
compose correctly. Also documented a flaky, pre-existing, unrelated
init_db()-vs-teardown race that can show a harmless ERROR log line.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182# Theme-Specific Scenes Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Give the jellyfishing and firefly-catching themes a fully distinct visual identity (character, rest scene, day/night mechanic, finish container) and eliminate every remaining place corn/farmer art or text leaks into non-harvest themes.
**Architecture:** Shared scene-composition code (movement, HUD, timers, particle/interaction logic) stays as-is; each screen (character, REST background, decision backdrop, splash/finish) gains a small theme-dispatch function that reads content (colors, shapes, activity lists) from an expanded per-theme data table (`THEME_STYLE` in `cornfield.js`, `THEMES` in `themes.py`). `harvest`'s dispatch branch always resolves to the *original, renamed-but-unchanged* function, so its behavior is provably unaffected.
**Tech Stack:** Python (NiceGUI, `nicewebrl`), vanilla JS (HTML canvas 2D, no build step, no framework), `pytest` + `pytest-asyncio` + `nicegui.testing.User` for in-process integration checks, `deno run` for JS parse-checking (no Node/npm in this project).
## Global Constraints
- `harvest` theme's rendered output must not change at all (same functions, reached via the theme table instead of hardcoded call sites).- `boxes` theme stays deliberately plain: character is a flat neutral recolor only (no shape redesign), no new rest-scene decoration beyond a flat background, finish screen stays a plain stack of boxes.- No changes to game mechanics, timing, scoring, or trial design โ art/content only.- No new rendering framework or build step โ stays hand-drawn canvas 2D, matching the rest of `cornfield.js`.- Every JS task's verification step is `deno run` parse-checking the file (this repo has no JS test runner; canvas-drawing correctness beyond "it parses and the right function is dispatched" requires a human looking at a real browser โ noted per-task where relevant) plus, where the file exposes a debug hook, an assertion on *dispatch* (which function/theme key was selected), not on pixel output.- Every Python task's verification step is a real `pytest` assertion (pure functions / already-proven `nicegui.testing.User` harness) โ no placeholders.
---
### Task 1: `THEME_STYLE` schema extension + JS debug hook
**Files:**- Modify: `static/cornfield.js:58-77` (the `cfg` object and `THEME_STYLE` table)- Modify: `static/cornfield.js:151-188` (`window.Cornfield = {...}` public API object)
**Interfaces:**- Produces: `THEME_STYLE[themeKey]` now also has `character`, `puppyAccessory`, `skyByTod`, `sunByTod`, `soil`/`soilDark` (unchanged), `restBackdrop`, `restActivities` (array of 4 keys), `finishContainer`. Later tasks (2โ8) read these fields.- Produces: `window.Cornfield._debug = { THEME_STYLE, themeStyle }` โ a read-only test hook other tasks' tests use to assert dispatch without touching real canvas pixels.
- [ ] **Step 1: Replace the `THEME_STYLE` table**
Replace lines 58โ77 with:
```js const cfg = { avatar: 0, partnerName: "P2", theme: "harvest" };
// ---- themes (same mechanic every theme; only vocab/colors/character/scene // content change). Keys mirror themes.py's THEMES dict. "boxes" stays bland. const THEME_STYLE = { harvest: { target: "corn", targetOne: "corn", verb: "harvest", verbIng: "harvesting", pastLabel: "Harvested", machine: "harvester", itemEmoji: "๐ฝ", titleWord: "Harvest", soil: "#9c6b3f", soilDark: "#8a5d35", decorate: true, character: "farmer", puppyAccessory: null, skyByTod: null, sunByTod: null, restBackdrop: "farm", restActivities: ["lemon", "puppy", "apple", "chair"], finishContainer: "crate" }, jelly: { target: "jellyfish", targetOne: "jellyfish", verb: "catch", verbIng: "catching", pastLabel: "Caught", machine: "net", itemEmoji: "๐ชผ", titleWord: "Jellyfishing", soil: "#0f3547", soilDark: "#0b2a38", decorate: false, character: "snorkeler", puppyAccessory: "snorkel", skyByTod: { morning: ["#bfe8ff", "#8fd8e8"], evening: ["#123a55", "#0d2a3f"] }, sunByTod: { morning: { col: "#eaffff", glow: "rgba(200,240,255,0.35)" }, evening: { col: "#9fd0ff", glow: "rgba(140,190,255,0.3)" } }, restBackdrop: "reef", restActivities: ["clamshell", "puppy", "anemone", "coral"], finishContainer: "net" }, firefly: { target: "fireflies", targetOne: "firefly", verb: "catch", verbIng: "catching", pastLabel: "Caught", machine: "jar", itemEmoji: "โจ", titleWord: "Firefly Catching", soil: "#161a3a", soilDark: "#10132c", decorate: false, character: "explorer", puppyAccessory: "glow-collar", // NOTE: "morning" slot = the displayed "Evening" block (dusk); // "evening" slot = the displayed "Night" block (deep dark). // Both are always dark -- fireflies are never shown in daylight. skyByTod: { morning: ["#3a2a55", "#5a3a20"], evening: ["#0a0e2a", "#05071a"] }, sunByTod: { morning: { col: "#ffe9b0", glow: "rgba(255,220,150,0.25)" }, evening: { col: "#e8ecff", glow: "rgba(220,225,255,0.25)" } }, restBackdrop: "meadowNight", restActivities: ["marshmallow", "puppy", "fireflyCup", "blanket"], finishContainer: "jar" }, boxes: { target: "boxes", targetOne: "box", verb: "click", verbIng: "clicking", pastLabel: "Clicked", machine: "clicker", itemEmoji: "โซ๏ธ", titleWord: "Box", soil: "#bdbdbd", soilDark: "#aaaaaa", decorate: false, character: "plain", puppyAccessory: null, skyByTod: { morning: ["#d6d6d6", "#d6d6d6"], evening: ["#d6d6d6", "#d6d6d6"] }, sunByTod: { morning: { col: "#cfcfcf", glow: "rgba(200,200,200,0.2)" }, evening: { col: "#cfcfcf", glow: "rgba(200,200,200,0.2)" } }, restBackdrop: "plain", restActivities: ["lemon", "puppy", "apple", "chair"], finishContainer: "stack" }, }; function themeStyle() { return THEME_STYLE[cfg.theme] || THEME_STYLE.harvest; }```
(This removes the old flat `sky: [...]` field, replaced by `skyByTod`; `soil`/`soilDark` are unchanged values, just re-declared here for clarity since the whole block is replaced.)
- [ ] **Step 2: Add the debug hook to the public API**
In `window.Cornfield = { ... }` (starting line 151), add as the last property before the closing `};`:
```js _debug: { THEME_STYLE, themeStyle },```
- [ ] **Step 3: Parse-check**
Run: `deno run static/cornfield.js`Expected: same as before this change โ it starts executing and fails only on `window is not defined` (a Deno environment limitation, not a syntax error). Any *different* error (e.g. `Unexpected token`) means Step 1 or 2 has a syntax mistake โ fix before continuing.
- [ ] **Step 4: Commit**
```bashgit add static/cornfield.jsgit commit -m "Extend THEME_STYLE with character/sky/rest/finish fields + debug hook"```
---
### Task 2: Sky/sun day-night dispatch
**Files:**- Modify: `static/cornfield.js:544-562` (`skyStops`, `sunInfo`)- Modify: `static/cornfield.js:595-621` (`drawWorkField`'s sky selection, already partially theme-aware from the first pass)
**Interfaces:**- Consumes: `themeStyle()` from Task 1 (`skyByTod`, `sunByTod`, `decorate`).- Produces: `sunInfo(t)` now returns theme-correct `{x, y, col, glow}` for non-`harvest` themes; `drawWorkField` picks the theme's sky pair by time-of-day instead of a single static pair.
- [ ] **Step 1: Update `sunInfo`**
Find (around line 555):```js function sunInfo(t) { const tod = todOf(t); if (tod === "morning") return { x: W * 0.15, y: HUD + 34, col: "#fff2c2", glow: "rgba(255,235,150,0.4)" }; if (tod === "evening") return { x: W * 0.85, y: HUD + 46, col: "#ff8a44", glow: "rgba(255,120,60,0.4)" }; return { x: W - 46, y: HUD + 38, col: "rgba(255,220,120,0.9)", glow: "rgba(255,200,80,0.35)" }; }```
Replace with:```js function sunInfo(t) { const tod = todOf(t); const th = themeStyle(); if (!th.decorate && th.sunByTod) { const pos = tod === "morning" ? { x: W * 0.15, y: HUD + 34 } : { x: W * 0.85, y: HUD + 46 }; return Object.assign({}, pos, th.sunByTod[tod] || th.sunByTod.morning); } if (tod === "morning") return { x: W * 0.15, y: HUD + 34, col: "#fff2c2", glow: "rgba(255,235,150,0.4)" }; if (tod === "evening") return { x: W * 0.85, y: HUD + 46, col: "#ff8a44", glow: "rgba(255,120,60,0.4)" }; return { x: W - 46, y: HUD + 38, col: "rgba(255,220,120,0.9)", glow: "rgba(255,200,80,0.35)" }; }```(`harvest` has `decorate: true`, so it always falls through to the unchanged original branches โ behavior is identical to before.)
- [ ] **Step 2: Update `drawWorkField`'s sky-pair selection**
Find (around line 596):```js const ss = th.decorate ? skyStops(t, "work") : th.sky;```
Replace with:```js const ss = th.decorate ? skyStops(t, "work") : (th.skyByTod[todOf(t)] || th.skyByTod.morning);```(`th` is already defined earlier in this function from the first theming pass.)
- [ ] **Step 3: Parse-check**
Run: `deno run static/cornfield.js`Expected: same `window is not defined` failure point as Task 1, no new syntax errors.
- [ ] **Step 4: Commit**
```bashgit add static/cornfield.jsgit commit -m "Dispatch sky/sun colors by theme + time-of-day"```
---
### Task 3: Character redesign dispatch
**Files:**- Modify: `static/cornfield.js:891-930` (rename existing `drawFarmerAt` body โ `drawFarmerBodyAt`, add dispatcher + two new character functions)
**Interfaces:**- Consumes: `themeStyle().character` (`"farmer"|"snorkeler"|"explorer"|"plain"`) from Task 1.- Produces: `drawFarmerAt(g, x, y, face, frame, mode, pal, s)` โ **signature unchanged**, so every existing call site (`drawFarmer`, `drawPartner`, `preview`, `splash`, `drawDecisionScene`) needs zero changes.
- [ ] **Step 1: Rename the existing function body**
Find the function starting at line 891 (`function drawFarmerAt(g, x, y, face, frame, mode, pal, s) {`) through its closing `}` (ends right before `function drawHeadwear`). Rename its declaration line only:
```js function drawFarmerBodyAt(g, x, y, face, frame, mode, pal, s) {```(Leave everything else inside the function exactly as-is.)
- [ ] **Step 2: Add the dispatcher + neutral palette + two new character functions**
Insert immediately before the renamed function (i.e., right where `drawFarmerAt` used to start):
```js const NEUTRAL_PAL = { skin: "#c9c9c9", overalls: "#9a9a9a", head: "none", hair: "none" };
function drawFarmerAt(g, x, y, face, frame, mode, pal, s) { const th = themeStyle(); if (th.character === "snorkeler") return drawSnorkelerAt(g, x, y, face, frame, mode, pal, s); if (th.character === "explorer") return drawExplorerAt(g, x, y, face, frame, mode, pal, s); const usePal = th.character === "plain" ? NEUTRAL_PAL : pal; return drawFarmerBodyAt(g, x, y, face, frame, mode, usePal, s); }
function drawSnorkelerAt(g, x, y, face, frame, mode, pal, s) { s = s || 1; const bob = frame ? -1 : 1; const old = ctx; ctx = g; const hy = y - 10 * s + bob; ctx.fillStyle = "rgba(0,0,0,0.18)"; ellipse(x, y + 16 * s, 14 * s, 5 * s); ctx.fillStyle = pal.overalls || "#2b6f8f"; roundRect(x - 9 * s, y - 2 * s + bob, 18 * s, 18 * s, 4 * s); ctx.fill(); ctx.fillStyle = "#1c4a5e"; ellipse(x - 6 * s, y + 15 * s + bob, 6 * s, 3 * s); ellipse(x + 6 * s, y + 15 * s + bob, 6 * s, 3 * s); ctx.fillStyle = pal.skin; circle(x, hy, 8 * s); ctx.fillStyle = "#0e2430"; roundRect(x - 7 * s, hy - 3 * s, 14 * s, 7 * s, 3 * s); ctx.fill(); ctx.fillStyle = "#bfe9ff"; circle(x, hy - 1 * s, 3 * s); ctx.strokeStyle = "#0e2430"; ctx.lineWidth = 2 * s; ctx.beginPath(); ctx.moveTo(x + 7 * s, hy - 4 * s); ctx.lineTo(x + 10 * s, hy - 10 * s); ctx.stroke(); if (mode === "work") { ctx.fillStyle = "#bfe6ff"; circle(x + 9 * s, hy - 2 * s, 2 * s); } ctx = old; }
function drawExplorerAt(g, x, y, face, frame, mode, pal, s) { s = s || 1; const bob = frame ? -1 : 1; const old = ctx; ctx = g; const hy = y - 10 * s + bob; ctx.fillStyle = "rgba(0,0,0,0.18)"; ellipse(x, y + 16 * s, 14 * s, 5 * s); ctx.fillStyle = pal.overalls || "#2a2f3a"; roundRect(x - 9 * s, y - 2 * s + bob, 18 * s, 18 * s, 4 * s); ctx.fill(); ctx.fillStyle = pal.skin; circle(x, hy, 8 * s); ctx.fillStyle = "#1c2027"; ctx.beginPath(); ctx.arc(x, hy, 8 * s, Math.PI, 2 * Math.PI); ctx.fill(); ctx.fillStyle = "#ffe9a0"; circle(x, hy - 8 * s, 2 * s); ctx.fillStyle = "rgba(255,233,160,0.35)"; circle(x, hy - 8 * s, 5 * s); ctx.strokeStyle = "#8a8f9a"; ctx.lineWidth = 1.5 * s; ctx.beginPath(); ctx.moveTo(x + 9 * s, hy); ctx.lineTo(x + 14 * s, y + 10 * s + bob); ctx.stroke(); ctx.beginPath(); ctx.ellipse(x + 15 * s, y + 12 * s + bob, 5 * s, 4 * s, 0.3, 0, 7); ctx.stroke(); if (mode === "work") { ctx.fillStyle = "#ffe9a0"; circle(x + 9 * s, hy - 2 * s, 2 * s); } ctx = old; }
```
- [ ] **Step 3: Write the dispatch test**
Create `test_theme_character_dispatch.py` in the project root (this will be consolidated with other JS-dispatch tests in Task 11; for now, verify manually):
Run: `deno run static/cornfield.js` โ confirms no syntax errors from the rename + new functions (same expected failure point as before).
Also manually grep-verify every existing caller still says `drawFarmerAt(`, not `drawFarmerBodyAt(`, so no call site needed to change:```bashgrep -n "drawFarmerAt(" static/cornfield.js```Expected: the dispatcher's own definition, plus calls inside `drawFarmer`, `preview`, `splash`, `drawPartner`, `drawDecisionScene` โ all unchanged from before this task, all still calling `drawFarmerAt`.
- [ ] **Step 4: Commit**
```bashgit add static/cornfield.jsgit commit -m "Dispatch player/partner character art by theme (snorkeler, night explorer)"```
---
### Task 4: Generalize REST activities (data-driven, theme-agnostic mechanic)
**Files:**- Modify: `static/cornfield.js:381-433` (`restObjects`, `nearestRestObj`, `doRestAction`)- Modify: `static/cornfield.js:805-819` (`drawPuppy` โ add accessory)
**Interfaces:**- Consumes: `themeStyle().restActivities` (array of 4 keys), `themeStyle().puppyAccessory` from Task 1.- Produces: `REST_ACTIVITY_DEFS` (module-level const, keyed by activity key โ `{emoji, label}`) โ Task 5/6 add background art near these same activity keys' positions.
- [ ] **Step 1: Add the activity definitions table**
Insert just before `function restObjects()` (line 381):
```js const REST_ACTIVITY_DEFS = { lemon: { emoji: "๐", label: "sip lemonade" }, puppy: { emoji: "๐ถ", label: "pet the puppy" }, apple: { emoji: "๐", label: "pick an apple" }, chair: { emoji: "๐ช", label: "sit & relax" }, clamshell: { emoji: "๐", label: "sip from a clamshell" }, anemone: { emoji: "๐ธ", label: "pluck an anemone" }, coral: { emoji: "๐ชธ", label: "lounge on the coral" }, marshmallow: { emoji: "๐ฅ", label: "toast a marshmallow" }, fireflyCup: { emoji: "โจ", label: "cup a firefly" }, blanket: { emoji: "๐", label: "watch the stars" }, };```
- [ ] **Step 2: Rewrite `restObjects()` to be theme-driven**
Replace (lines 381โ389):```js function restObjects() { const r = trial.rest; return [ { k: "lemon", x: 96, y: HUD + BOARD_H - 58, label: "๐ sip lemonade" }, { k: "puppy", x: r.puppy.x, y: r.puppy.y, label: "๐ถ pet the puppy" }, { k: "apple", x: W - 96, y: HUD + BOARD_H - 52, label: "๐ pick an apple" }, { k: "chair", x: W - 162, y: HUD + BOARD_H - 26, label: "๐ช sit & relax" }, ]; }```
With:```js function restObjects() { const r = trial.rest, th = themeStyle(); const positions = { lemon: { x: 96, y: HUD + BOARD_H - 58 }, clamshell: { x: 96, y: HUD + BOARD_H - 54 }, marshmallow: { x: 96, y: HUD + BOARD_H - 50 }, puppy: { x: r.puppy.x, y: r.puppy.y }, apple: { x: W - 96, y: HUD + BOARD_H - 52 }, anemone: { x: W - 96, y: HUD + BOARD_H - 50 }, fireflyCup: { x: W - 96, y: HUD + BOARD_H - 50 }, chair: { x: W - 162, y: HUD + BOARD_H - 26 }, coral: { x: W - 162, y: HUD + BOARD_H - 30 }, blanket: { x: W - 162, y: HUD + BOARD_H - 24 }, }; return th.restActivities.map(key => { const def = REST_ACTIVITY_DEFS[key], pos = positions[key]; return { k: key, x: pos.x, y: pos.y, label: def.emoji + " " + def.label }; }); }```
- [ ] **Step 3: Generalize `doRestAction()` by mechanic group, not literal name**
Replace (lines 396-413):```js function doRestAction() { const r = trial.rest; if (!r) return; const { obj, dist } = nearestRestObj(); const p = trial.player, px = p.c * TILE + TILE / 2, py = HUD + p.r * TILE + TILE / 2; if (!obj || dist > 82) { Sound.play("button"); return; } if (obj.k === "lemon") { if (r.glass > 0.12) { r.glass -= 0.34; if (r.glass < 0) r.glass = 0; } r.sips++; Sound.play("sip"); spawnHeart(trial, px, py - 22, "๐"); } else if (obj.k === "puppy") { r.pets++; Sound.play("bark"); spawnHeart(trial, obj.x, obj.y - 14, "โค"); spawnHeart(trial, obj.x + 8, obj.y - 9, "โค"); } else if (obj.k === "apple") { Sound.play("apple"); spawnHeart(trial, obj.x, obj.y - 10, "๐"); } else if (obj.k === "chair") { Sound.play("sit"); spawnHeart(trial, px, py - 20, "๐"); } }```
With:```js function doRestAction() { const r = trial.rest; if (!r) return; const { obj, dist } = nearestRestObj(); const p = trial.player, px = p.c * TILE + TILE / 2, py = HUD + p.r * TILE + TILE / 2; if (!obj || dist > 82) { Sound.play("button"); return; } const glyph = REST_ACTIVITY_DEFS[obj.k].emoji; if (obj.k === "lemon" || obj.k === "clamshell" || obj.k === "marshmallow") { if (r.glass > 0.12) { r.glass -= 0.34; if (r.glass < 0) r.glass = 0; } r.sips++; Sound.play("sip"); spawnHeart(trial, px, py - 22, glyph); } else if (obj.k === "puppy") { r.pets++; Sound.play("bark"); spawnHeart(trial, obj.x, obj.y - 14, "โค"); spawnHeart(trial, obj.x + 8, obj.y - 9, "โค"); } else if (obj.k === "apple" || obj.k === "anemone" || obj.k === "fireflyCup") { Sound.play("apple"); spawnHeart(trial, obj.x, obj.y - 10, glyph); } else if (obj.k === "chair" || obj.k === "coral" || obj.k === "blanket") { Sound.play("sit"); spawnHeart(trial, px, py - 20, "๐"); } }```(`nearestRestObj()` needs no change โ it already works generically off whatever `restObjects()` returns.)
- [ ] **Step 4: Add the puppy accessory**
Replace (lines 805-817, the `drawPuppy` function body) by adding accessory drawing before the closing `}`:
```js function drawPuppy(p) { const x = p.x, y = p.y, f = p.face || 1, bob = p.frame ? -1 : 1; ctx.fillStyle = "rgba(0,0,0,0.15)"; ellipse(x, y + 9, 13, 4); ctx.fillStyle = "#caa472"; roundRect(x - 12, y - 6 + bob, 22, 13, 6); ctx.fill(); ctx.fillStyle = "#b8915f"; circle(x + f * 12, y - 6 + bob, 7); ctx.fillStyle = "#8c6b43"; ellipse(x + f * 16, y - 12 + bob, 3, 5); ctx.fillStyle = "#2b2b2b"; circle(x + f * 14, y - 7 + bob, 1.4); const wag = Math.sin(p.t * 12) * 5; ctx.strokeStyle = "#caa472"; ctx.lineWidth = 3; ctx.beginPath(); ctx.moveTo(x - f * 11, y - 4 + bob); ctx.lineTo(x - f * 18, y - 8 + bob + wag); ctx.stroke(); const acc = themeStyle().puppyAccessory; if (acc === "snorkel") { ctx.strokeStyle = "#0e2430"; ctx.lineWidth = 2; ctx.beginPath(); ctx.arc(x + f * 12, y - 6 + bob, 5, 0, Math.PI); ctx.stroke(); } else if (acc === "glow-collar") { ctx.fillStyle = "rgba(255,240,150,0.9)"; roundRect(x - 8, y - 1 + bob, 16, 3, 2); ctx.fill(); } }```
- [ ] **Step 5: Parse-check + commit**
Run: `deno run static/cornfield.js` โ same expected failure point as prior tasks.
```bashgit add static/cornfield.jsgit commit -m "Generalize rest activities to be theme-driven (same 4 mechanics, themed content)"```
---
### Task 5: Jellyfishing REST background + meter/anemone/coral art
**Files:**- Modify: `static/cornfield.js:710-756` (rename existing `drawRestField` body โ `drawRestFieldFarm`, add dispatcher + reef variant)- Modify: `static/cornfield.js:793-804` (`drawLemonade` area โ add `drawRestMeter` dispatcher + `drawClamshell`)- Modify: `static/cornfield.js:757-792` (`drawRestScene` โ use dispatched meter + theme-driven hint text)
**Interfaces:**- Consumes: `themeStyle()` (`decorate`, `restBackdrop`, `skyByTod`, `restActivities`) from Task 1; `REST_ACTIVITY_DEFS` from Task 4.- Produces: `drawRestField(t)` dispatches correctly for `jelly`; `drawRestMeter(key, x, y, fill)` used by `drawRestScene`.
- [ ] **Step 1: Rename existing background function, add dispatcher + reef helpers**
Rename the `drawRestField` function declaration (line 710) to `drawRestFieldFarm` (body unchanged). Then insert a new dispatcher + reef-specific helpers right before it:
```js function drawRestField(t) { const th = themeStyle(); if (th.decorate) return drawRestFieldFarm(t); if (th.restBackdrop === "reef") return drawRestFieldReef(t); if (th.restBackdrop === "meadowNight") return drawRestFieldMeadowNight(t); return drawRestFieldPlain(t); }
function drawMiniCoral(x, y) { ctx.fillStyle = "#e8767a"; ctx.beginPath(); ctx.moveTo(x, y + 10); ctx.quadraticCurveTo(x - 6, y - 2, x, y - 10); ctx.quadraticCurveTo(x + 6, y - 2, x, y + 10); ctx.fill(); }
function fishSilhouette(x, y) { ctx.fillStyle = "rgba(20,60,80,0.45)"; ctx.beginPath(); ctx.ellipse(x, y, 7, 3, 0, 0, 7); ctx.fill(); ctx.beginPath(); ctx.moveTo(x - 7, y); ctx.lineTo(x - 12, y - 4); ctx.lineTo(x - 12, y + 4); ctx.fill(); }
function drawRestFieldReef(t) { const th = themeStyle(); const ss = th.skyByTod[todOf(t)] || th.skyByTod.morning; const g = ctx.createLinearGradient(0, HUD, 0, HUD + BOARD_H); g.addColorStop(0, ss[0]); g.addColorStop(1, ss[1]); ctx.fillStyle = g; ctx.fillRect(0, HUD, W, BOARD_H); const sun = sunInfo(t); ctx.save(); ctx.globalAlpha = 0.25; ctx.fillStyle = sun.col; for (let i = 0; i < 4; i++) ctx.fillRect(30 + i * 70, HUD, 18, BOARD_H * 0.7); ctx.restore(); ctx.fillStyle = "rgba(255,255,255,0.3)"; [[40, HUD + 60, 4], [70, HUD + 100, 3], [W - 50, HUD + 80, 5]].forEach(b => circle(b[0], b[1], b[2])); ctx.fillStyle = "#e8d9a8"; ctx.fillRect(0, HUD + BOARD_H - 4 * TILE, W, 4 * TILE); const hy = HUD + (ROWS - 4) * TILE; for (let i = 0; i < 20; i++) drawMiniCoral(14 + i * 32, hy - 2); if (t && t.rest) t.rest.birds.forEach(b => fishSilhouette(b.x, b.y)); const ax = W - 96, ay = HUD + BOARD_H - 60; ctx.fillStyle = "#3a7a5a"; roundRect(ax - 14, ay + 10, 28, 10, 4); ctx.fill(); ["#e8567a", "#f28aa8", "#ff9ec4"].forEach((col, i) => { ctx.fillStyle = col; ctx.beginPath(); ctx.ellipse(ax - 8 + i * 8, ay + 4, 5, 8, 0, 0, 7); ctx.fill(); }); ctx.fillStyle = "#f0e4b8"; roundRect(60, HUD + BOARD_H - 68, 120, 50, 8); ctx.fill(); const crx = W - 180, cry = HUD + BOARD_H - 30; ctx.fillStyle = "#c97a6a"; ellipse(crx + 16, cry - 6, 22, 14); ctx.fillStyle = "#e8a08a"; ellipse(crx + 6, cry - 12, 10, 8); }
```
- [ ] **Step 2: Add `drawRestMeter` dispatcher + `drawClamshell`**
Insert right after `drawLemonade` (line 804, before `function drawPuppy`):
```js function drawRestMeter(key, x, y, fill) { if (key === "clamshell") return drawClamshell(x, y, fill); if (key === "marshmallow") return drawMarshmallow(x, y, fill); // added in Task 6 return drawLemonade(x, y, fill); }
function drawClamshell(x, y, fill) { ctx.fillStyle = "#ffe3d6"; ctx.beginPath(); ctx.ellipse(x, y - 6, 11, 8, 0, 0, Math.PI, true); ctx.fill(); ctx.strokeStyle = "#e8a98a"; ctx.lineWidth = 1.5; for (let i = -2; i <= 2; i++) { ctx.beginPath(); ctx.moveTo(x, y - 6); ctx.lineTo(x + i * 4, y - 14); ctx.stroke(); } const h = 10 * clamp(fill, 0, 1); ctx.fillStyle = "#7fd4c8"; ctx.fillRect(x - 8, y - 2 - h, 16, h); ctx.fillStyle = "#fff6c0"; circle(x + 3, y - 4 - h, 2); }```(`drawMarshmallow` doesn't exist yet โ it's added in Task 6. This is fine: `drawRestMeter` isn't called with `key === "marshmallow"` until Task 6's theme is exercised, and Task 6 adds the function before anything calls it in practice. If you run Task 5 in complete isolation and want a fully self-contained intermediate state, stub `drawMarshmallow` as an alias for `drawClamshell` here and let Task 6 replace it โ but per-task ordering in this plan is sequential, so this isn't required.)
- [ ] **Step 3: Update `drawRestScene` to use the dispatched meter + theme-driven hint text**
Find (around line 757, inside `drawRestScene(t)`):```js function drawRestScene(t) { drawRestField(t); // lemonade glass (on the blanket) const gx = 96, gy = HUD + BOARD_H - 58; drawLemonade(gx, gy, t.rest.glass);```
Replace with:```js function drawRestScene(t) { drawRestField(t); const th = themeStyle(); const gx = 96, gy = HUD + BOARD_H - 58; drawRestMeter(th.restActivities[0], gx, gy, t.rest.glass);```
Find (further down in the same function, the hint text block):```js // one general instruction up in the sky (no per-object hover labels) ctx.textAlign = "center"; ctx.font = "14px system-ui, sans-serif"; ctx.fillStyle = "rgba(20,50,35,0.55)"; const hint = "Stroll around and press SPACE to play with things nearby ๐ ๐ถ ๐ ๐ช";```
Replace with:```js // one general instruction up in the sky (no per-object hover labels) ctx.textAlign = "center"; ctx.font = "14px system-ui, sans-serif"; ctx.fillStyle = th.decorate ? "rgba(20,50,35,0.55)" : "rgba(255,255,255,0.75)"; const emojiList = th.restActivities.map(k => REST_ACTIVITY_DEFS[k].emoji).join(" "); const hint = "Stroll around and press SPACE to play with things nearby " + emojiList;```
- [ ] **Step 4: Parse-check + commit**
Run: `deno run static/cornfield.js` โ same expected failure point.
```bashgit add static/cornfield.jsgit commit -m "Add jellyfishing underwater rest scene (reef background, clamshell, anemone, coral)"```
---
### Task 6: Firefly REST background + marshmallow art + Evening/Night block labels
**Files:**- Modify: `static/cornfield.js:793-804` area (add `drawMarshmallow`, referenced by Task 5's dispatcher)- Modify: `static/cornfield.js` (add `drawRestFieldMeadowNight`, `drawRestFieldPlain`, referenced by Task 5's dispatcher)- Modify: `themes.py` (add `block_labels` per theme)- Modify: `effort_stages.py:432-436` (`block_labels()`)- Test: `test_block_labels.py` (new, project root)
**Interfaces:**- Consumes: `themeStyle()` from Task 1; the `drawRestField` dispatcher from Task 5 (which already routes `"meadowNight"` and default/`"plain"` โ this task supplies those two function bodies it was missing).- Produces: `block_labels()` (Python) returns theme-correct block names; `drawMarshmallow`, `drawRestFieldMeadowNight`, `drawRestFieldPlain` (JS).
- [ ] **Step 1: Add `drawMarshmallow`**
Insert next to `drawClamshell` (added in Task 5):
```js function drawMarshmallow(x, y, fill) { ctx.strokeStyle = "#7a4a22"; ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(x - 10, y + 8); ctx.lineTo(x + 10, y - 6); ctx.stroke(); const toast = clamp(fill, 0, 1); // 1 = untoasted (pale), 0 = fully toasted (brown) ctx.fillStyle = toast > 0.5 ? "#fff6ea" : "#c98a4a"; roundRect(x + 4, y - 12, 12, 12, 4); ctx.fill(); ctx.fillStyle = "#ff8a3a"; circle(x - 12, y + 12, 6); ctx.fillStyle = "rgba(255,150,60,0.3)"; circle(x - 12, y + 12, 11); }```
- [ ] **Step 2: Add `drawRestFieldMeadowNight` and `drawRestFieldPlain`**
Insert after `drawRestFieldReef` (added in Task 5):
```js function drawRestFieldMeadowNight(t) { const th = themeStyle(); const ss = th.skyByTod[todOf(t)] || th.skyByTod.morning; const g = ctx.createLinearGradient(0, HUD, 0, HUD + BOARD_H); g.addColorStop(0, ss[0]); g.addColorStop(1, ss[1]); ctx.fillStyle = g; ctx.fillRect(0, HUD, W, BOARD_H); ctx.fillStyle = "rgba(255,255,255,0.8)"; [[30, HUD + 20], [70, HUD + 40], [120, HUD + 15], [200, HUD + 30], [260, HUD + 50], [320, HUD + 18]] .forEach(s => circle(s[0], s[1], 1.4)); const moon = sunInfo(t); ctx.fillStyle = moon.col; circle(moon.x, moon.y, 16); for (let r = ROWS - 4; r < ROWS; r++) for (let c = 0; c < COLS; c++) { const x = c * TILE, y = HUD + r * TILE; ctx.fillStyle = ((c + r) & 1) ? "#1c2e1c" : "#182818"; ctx.fillRect(x, y, TILE, TILE); } const hy = HUD + (ROWS - 4) * TILE; ctx.fillStyle = "#0e1a0e"; for (let i = 0; i < 10; i++) { const tx = 20 + i * 36; ctx.beginPath(); ctx.ellipse(tx, hy - 6, 16, 20, 0, 0, 7); ctx.fill(); } t._ambientFireflies = t._ambientFireflies || Array.from({ length: 6 }, () => ({ x: Math.random() * W, y: HUD + 40 + Math.random() * 100, ph: Math.random() * 10 })); t._ambientFireflies.forEach(f => { const pulse = 0.4 + 0.4 * Math.sin(now() / 300 + f.ph); ctx.fillStyle = "rgba(255,240,150," + pulse.toFixed(2) + ")"; circle(f.x, f.y, 2.5); }); const fx = 96, fy = HUD + BOARD_H - 50; ctx.fillStyle = "#8a5a2a"; roundRect(fx - 12, fy + 8, 24, 6, 3); ctx.fill(); ctx.fillStyle = "rgba(255,140,50,0.5)"; circle(fx, fy + 4, 10); ctx.fillStyle = "#3a2a1a"; roundRect(140, HUD + BOARD_H - 30, 60, 14, 4); ctx.fill(); ctx.fillStyle = "#274a27"; roundRect(W - 210, HUD + BOARD_H - 40, 90, 24, 6); ctx.fill(); }
function drawRestFieldPlain(t) { ctx.fillStyle = "#e8e8e8"; ctx.fillRect(0, HUD, W, BOARD_H); ctx.fillStyle = "#d0d0d0"; ctx.fillRect(0, HUD + BOARD_H - 4 * TILE, W, 4 * TILE); }```
- [ ] **Step 3: Parse-check**
Run: `deno run static/cornfield.js` โ same expected failure point.
- [ ] **Step 4: Add `block_labels` to `themes.py`**
In `themes.py`, add a `block_labels` key to each theme's dict (e.g. for `harvest`, add `block_labels=["Morning", "Evening"],` alongside its other fields; same for `jelly` and `boxes`; for `firefly`, add `block_labels=["Evening", "Night"],`).
- [ ] **Step 5: Write the failing test for `block_labels()`**
`app.storage.user` raises `RuntimeError: app.storage.user can only be used withpage builder functions` when accessed outside a real NiceGUI client/requestcontext โ confirmed empirically, a bare script (`app.storage.user["theme"] = x`with no open session) does not work. Use `nicegui.testing.User` to open a realsession, then access storage inside `with user.client:`.
Create `test_block_labels.py` in the project root:
```python"""Firefly theme must always show Evening/Night (never Morning), sincefireflies aren't visible in daylight; every other theme keeps Morning/Evening."""import osos.environ["RELOAD"] = "0"os.environ["STORAGE_SECRET"] = "test"os.environ["PORT"] = "8094"
import pytestimport web_appimport effort_stages as Efrom nicegui.testing import User
EXPECTED = { "harvest": ["Morning Harvest", "Evening Harvest"], "jelly": ["Morning Jellyfishing", "Evening Jellyfishing"], "firefly": ["Evening Firefly Catching", "Night Firefly Catching"], "boxes": ["Morning Box", "Evening Box"],}
@pytest.mark.parametrize("theme_key,expected", list(EXPECTED.items()))@pytest.mark.module_under_test(web_app)async def test_block_labels(user: User, theme_key, expected) -> None: await user.open(f"/?dev=1&start=end&role=c&theme={theme_key}&pid=SMOKE_labels_{theme_key}") with user.client: labels = E.block_labels() assert labels == expected```
- [ ] **Step 6: Run the test to verify it fails**
Run: `.venv/bin/python3 -m pytest test_block_labels.py -v`Expected: 3 PASS (`harvest`, `jelly`, `boxes` โ unchanged behavior) + 1 FAIL(`firefly`) โ `block_labels()` still returns`["Morning Firefly Catching", "Evening Firefly Catching"]` (the old`f"Morning {title}"`/`f"Evening {title}"` logic).
**Known flaky, unrelated log line:** you may sometimes see`nicegui - ERROR - Cannot operate on a closed database` in the output, from`init_db()`'s background task racing test teardown. This is a pre-existingtiming artifact of running this app's Tortoise-ORM init repeatedly in-processvia `nicegui.testing.User` โ confirmed non-deterministic (reproduced in 2 of 3identical reruns), unrelated to theme/block-label logic. If a test fails *only*on this ERROR line with no `AssertionError`, rerun it once before investigatingfurther.
- [ ] **Step 7: Fix `block_labels()` in `effort_stages.py`**
Find (lines 432-436):```pythondef block_labels(): title = TH.current_theme()["title_word"] return [f"Morning {title}", f"Evening {title}"]```
Replace with:```pythondef block_labels(): th = TH.current_theme() prefix0, prefix1 = th.get("block_labels", ["Morning", "Evening"]) return [f"{prefix0} {th['title_word']}", f"{prefix1} {th['title_word']}"]```
- [ ] **Step 8: Run the test to verify it passes**
Run: `.venv/bin/python3 -m pytest test_block_labels.py -v`Expected: PASS (all 4 tests).
- [ ] **Step 9: Commit**
```bashgit add static/cornfield.js themes.py effort_stages.py test_block_labels.pygit commit -m "Add firefly night rest scene (marshmallow, ambient fireflies) + Evening/Night block labels"```
---
### Task 7: Decision-screen backdrop theming (corn-leak fix)
**Files:**- Modify: `static/cornfield.js:1055-1072` (rename existing `drawWorldBackdrop` body โ `drawWorldBackdropFarm`, add dispatcher + 3 variants)
**Interfaces:**- Consumes: `themeStyle()` (`decorate`, `restBackdrop`) from Task 1; `drawMiniCoral` from Task 5.- Produces: `drawWorldBackdrop()` โ signature unchanged, existing caller `drawDecisionScene` needs no change.
- [ ] **Step 1: Rename the existing function, add dispatcher + 3 variants**
Rename `drawWorldBackdrop` (line 1055) to `drawWorldBackdropFarm` (body unchanged). Insert before it:
```js function drawWorldBackdrop() { const th = themeStyle(); if (th.decorate) return drawWorldBackdropFarm(); if (th.restBackdrop === "reef") return drawWorldBackdropReef(); if (th.restBackdrop === "meadowNight") return drawWorldBackdropNight(); return drawWorldBackdropPlain(); }
function drawWorldBackdropReef() { const g = ctx.createLinearGradient(0, HUD, 0, HUD + BOARD_H); g.addColorStop(0, "#8fd8e8"); g.addColorStop(1, "#e8f6f0"); ctx.fillStyle = g; ctx.fillRect(0, HUD, W, BOARD_H); ctx.fillStyle = "rgba(255,255,255,0.3)"; [[40, HUD + 50, 4], [90, HUD + 90, 3], [W - 60, HUD + 70, 5], [W - 120, HUD + 110, 3]] .forEach(b => circle(b[0], b[1], b[2])); ctx.fillStyle = "#e8d9a8"; ctx.fillRect(0, HUD + BOARD_H * 0.75, W, BOARD_H * 0.25); for (let i = 0; i < 14; i++) drawMiniCoral(10 + i * 26, HUD + BOARD_H * 0.8); }
function drawWorldBackdropNight() { const g = ctx.createLinearGradient(0, HUD, 0, HUD + BOARD_H); g.addColorStop(0, "#0a0e2a"); g.addColorStop(1, "#141a3a"); ctx.fillStyle = g; ctx.fillRect(0, HUD, W, BOARD_H); ctx.fillStyle = "rgba(255,255,255,0.7)"; [[40, HUD + 30], [100, HUD + 50], [160, HUD + 20], [240, HUD + 45], [300, HUD + 25]] .forEach(s => circle(s[0], s[1], 1.3)); ctx.fillStyle = "#e8ecff"; circle(W - 62, HUD + 44, 18); ctx.fillStyle = "#0e1a0e"; for (let i = 0; i < 10; i++) { const tx = 10 + i * 32; ctx.beginPath(); ctx.ellipse(tx, HUD + BOARD_H * 0.72, 14, 18, 0, 0, 7); ctx.fill(); } }
function drawWorldBackdropPlain() { ctx.fillStyle = "#e8e8e8"; ctx.fillRect(0, HUD, W, BOARD_H); ctx.fillStyle = "#d8d8d8"; ctx.fillRect(0, HUD + BOARD_H * 0.8, W, BOARD_H * 0.2); }
```
- [ ] **Step 2: Parse-check + commit**
Run: `deno run static/cornfield.js` โ same expected failure point.
```bashgit add static/cornfield.jsgit commit -m "Theme the decision-screen backdrop (was always blue-sky/green-hills)"```
---
### Task 8: Splash/cover/finish backdrop + finish-container theming
**Files:**- Modify: `static/cornfield.js:967-1015` (`splash()` โ add palette lookup, theme sky/ground, replace emoji-pair with drawn container)
**Interfaces:**- Consumes: `themeStyle()` (`finishContainer`) from Task 1.- Produces: `drawFinishContainer(g, x, y, key)` โ new function, called from `splash()`.
- [ ] **Step 1: Add the splash palette table + `drawFinishContainer`**
Insert right before `function splash(canvasId, kind) {` (line 967):
```js const SPLASH_PALETTE = { harvest: { sky: ["#aee0ff", "#dff4d6"], skyFinish: ["#ffd58a", "#ffb27a"], sun: "#ffe27a", sunFinish: "#ff9e5e", ground: "#7cc36b", groundDark: "#6cb35c" }, jelly: { sky: ["#8fd8e8", "#e8f6f0"], skyFinish: ["#123a55", "#0d2a3f"], sun: "#eaffff", sunFinish: "#9fd0ff", ground: "#e8d9a8", groundDark: "#d8c488" }, firefly: { sky: ["#3a2a55", "#5a3a20"], skyFinish: ["#0a0e2a", "#05071a"], sun: "#ffe9b0", sunFinish: "#e8ecff", ground: "#1c2e1c", groundDark: "#152315" }, boxes: { sky: ["#e0e0e0", "#e0e0e0"], skyFinish: ["#d0d0d0", "#d0d0d0"], sun: "#cfcfcf", sunFinish: "#cfcfcf", ground: "#c8c8c8", groundDark: "#b8b8b8" }, };
function drawFinishContainer(g, x, y, key) { const old = ctx; ctx = g; if (key === "net") { ctx.strokeStyle = "#8a8f9a"; ctx.lineWidth = 2; ctx.beginPath(); ctx.ellipse(x, y, 34, 22, 0, 0, 7); ctx.stroke(); for (let i = -3; i <= 3; i++) { ctx.beginPath(); ctx.moveTo(x + i * 8, y - 18); ctx.lineTo(x + i * 6, y + 18); ctx.stroke(); } ["#a8c8ff", "#c8b8ff", "#9fd0ff"].forEach((col, i) => { ctx.fillStyle = col; ctx.beginPath(); ctx.arc(x - 14 + i * 14, y, 8, Math.PI, 0); ctx.fill(); }); } else if (key === "jar") { ctx.fillStyle = "rgba(210,235,255,0.55)"; roundRect(x - 20, y - 22, 40, 44, 8); ctx.fill(); ctx.strokeStyle = "#8ab0c0"; ctx.lineWidth = 2; ctx.strokeRect(x - 20, y - 22, 40, 44); ctx.fillStyle = "#6a8a98"; roundRect(x - 14, y - 30, 28, 10, 3); ctx.fill(); [[x - 8, y - 6], [x + 6, y + 2], [x - 2, y + 10], [x + 9, y - 10]].forEach(p => { ctx.fillStyle = "rgba(255,240,150,0.95)"; circle(p[0], p[1], 3); ctx.fillStyle = "rgba(255,240,150,0.35)"; circle(p[0], p[1], 6); }); } else if (key === "stack") { ["#c9c9c9", "#bdbdbd", "#d4d4d4"].forEach((col, i) => { ctx.fillStyle = col; roundRect(x - 18 + i * 2, y - 8 - i * 12, 36 - i * 4, 12, 3); ctx.fill(); ctx.strokeStyle = "#9a9a9a"; ctx.strokeRect(x - 18 + i * 2, y - 8 - i * 12, 36 - i * 4, 12); }); } else { ctx.fillStyle = "#a9773f"; roundRect(x - 24, y - 6, 48, 26, 4); ctx.fill(); ctx.strokeStyle = "#7a5228"; ctx.lineWidth = 2; ctx.strokeRect(x - 24, y - 6, 48, 26); ctx.beginPath(); ctx.moveTo(x - 24, y + 7); ctx.lineTo(x + 24, y + 7); ctx.stroke(); [[x - 14, y - 14], [x, y - 18], [x + 14, y - 14]].forEach(p => { ctx.fillStyle = "#4f9a3f"; ctx.beginPath(); ctx.moveTo(p[0], p[1]); ctx.lineTo(p[0] - 4, p[1] - 10); ctx.lineTo(p[0] + 4, p[1] - 10); ctx.fill(); ctx.fillStyle = "#ffd23f"; roundRect(p[0] - 4, p[1] - 4, 8, 12, 3); ctx.fill(); }); } ctx = old; }
```
- [ ] **Step 2: Use the palette + container inside `splash()`**
Find (inside `splash()`):```js const sky = g.createLinearGradient(0, 0, 0, h); if (finish) { sky.addColorStop(0, "#ffd58a"); sky.addColorStop(1, "#ffb27a"); } // warm sunset else { sky.addColorStop(0, "#aee0ff"); sky.addColorStop(1, "#dff4d6"); } g.fillStyle = sky; g.fillRect(0, 0, w, h); // sun g.fillStyle = finish ? "#ff9e5e" : "#ffe27a"; circle(w * 0.82, h * 0.24, 30);```
Replace with:```js const th = themeStyle(); const pal = SPLASH_PALETTE[cfg.theme] || SPLASH_PALETTE.harvest; const sky = g.createLinearGradient(0, 0, 0, h); const skyPair = finish ? pal.skyFinish : pal.sky; sky.addColorStop(0, skyPair[0]); sky.addColorStop(1, skyPair[1]); g.fillStyle = sky; g.fillRect(0, 0, w, h); // sun g.fillStyle = finish ? pal.sunFinish : pal.sun; circle(w * 0.82, h * 0.24, 30);```
Find (a few lines later, the hills):```js g.fillStyle = "#7cc36b"; g.beginPath(); g.moveTo(0, h * 0.7); g.quadraticCurveTo(w * 0.3, h * 0.6, w * 0.6, h * 0.72); g.quadraticCurveTo(w * 0.85, h * 0.8, w, h * 0.68); g.lineTo(w, h); g.lineTo(0, h); g.fill(); g.fillStyle = "#6cb35c"; g.fillRect(0, h * 0.82, w, h * 0.18);```
Replace the two fillStyle lines only (keep the path geometry):```js g.fillStyle = pal.ground; g.beginPath(); g.moveTo(0, h * 0.7); g.quadraticCurveTo(w * 0.3, h * 0.6, w * 0.6, h * 0.72); g.quadraticCurveTo(w * 0.85, h * 0.8, w, h * 0.68); g.lineTo(w, h); g.lineTo(0, h); g.fill(); g.fillStyle = pal.groundDark; g.fillRect(0, h * 0.82, w, h * 0.18);```
Find (the finish-only emoji-pair block added in the first theming pass):```js if (finish) { g.font = "26px system-ui, sans-serif"; g.textAlign = "center"; g.fillText(th.itemEmoji || "๐งบ", w * 0.30, h * 0.84); g.fillText("๐งบ", w * 0.66, h * 0.85); }```
Replace with:```js if (finish) { drawFinishContainer(g, w * 0.5, h * 0.85, th.finishContainer); }```(`th` here is the one just declared in Step 2 above โ remove any now-duplicate `const th = themeStyle();` if one already existed lower in the function from the first theming pass.)
- [ ] **Step 3: Parse-check + commit**
Run: `deno run static/cornfield.js` โ same expected failure point.
```bashgit add static/cornfield.jsgit commit -m "Theme cover/finish splash backdrop + add drawn finish-screen containers"```
---
### Task 9: Python corn-leak fixes ("Choose your farmer", fullscreen button emoji)
**Files:**- Modify: `web_app.py:294-296` (`_intro_page`, `"avatar"` branch)- Modify: `web_app.py:368` (`device_gate`)- Test: `test_theme_text_leaks.py` (new, project root)
**Interfaces:**- Consumes: `themes.current_theme()` (already imported as `themes` in `web_app.py`).
- [ ] **Step 1: Write the failing test**
Same as Task 6: `themes.current_theme()` reads `app.storage.user`, whichrequires a real client/request context (confirmed empirically โ a bare scriptraises `RuntimeError`). Use `nicegui.testing.User` to open a real session.
Create `test_theme_text_leaks.py`:
```python"""'Choose your farmer' and the fullscreen-start emoji must reflect the activetheme, not always say farmer/corn regardless of theme."""import osos.environ["RELOAD"] = "0"os.environ["STORAGE_SECRET"] = "test"os.environ["PORT"] = "8093"
import pytestimport web_appimport themesfrom nicegui.testing import User
EXPECTED_AGENT = {"harvest": "farmer", "jelly": "jellyfisher", "firefly": "firefly catcher", "boxes": "player"}
@pytest.mark.parametrize("theme_key,expected_agent", list(EXPECTED_AGENT.items()))@pytest.mark.module_under_test(web_app)async def test_agent_word_matches_theme(user: User, theme_key, expected_agent) -> None: await user.open(f"/?dev=1&start=end&role=c&theme={theme_key}&pid=SMOKE_agent_{theme_key}") with user.client: assert themes.current_theme()["agent"] == expected_agent```
(This test exercises the theme lookup web_app.py's fixed strings will be changed to use in Step 3 โ it already passes today since `themes.py`'s `agent` field has existed since the first pass, confirming the *data* is already correct and only the *call sites* in `web_app.py` need fixing.)
- [ ] **Step 2: Run it (expected to already pass โ confirms the data layer, not yet the fix)**
Run: `.venv/bin/python3 -m pytest test_theme_text_leaks.py -v`Expected: all 4 PASS (this test targets `themes.py`, which is already correct; it's here to document/guard the assumption Step 3 relies on). Same flaky "Cannot operate on a closed database" caveat as Task 6 applies here too.
- [ ] **Step 3: Fix `_intro_page`'s avatar-picker text**
Find (`web_app.py:294-296`):```python elif page == "avatar": ui.markdown("## Choose your farmer") ui.markdown("Click the farmer you'd like to play as, then press **Next**.")```
Replace with:```python elif page == "avatar": agent = themes.current_theme()["agent"] ui.markdown(f"## Choose your {agent}") ui.markdown(f"Click the {agent} you'd like to play as, then press **Next**.")```
- [ ] **Step 4: Fix `device_gate`'s fullscreen button emoji**
Find (`web_app.py:368`):```python ui.button("Enter fullscreen & start ๐ฝ", on_click=start)```
Replace with:```python item_emoji = themes.current_theme()["item_emoji"] or "๐ฎ" ui.button(f"Enter fullscreen & start {item_emoji}", on_click=start)```
- [ ] **Step 5: Manual verification (no NiceGUI unit test for markdown-string content in these specific functions without a full page render)**
Run: `grep -n "Choose your farmer\|Enter fullscreen & start ๐ฝ" web_app.py`Expected: no matches (both are now theme-conditional f-strings, not literal "farmer"/๐ฝ text).
- [ ] **Step 6: Commit**
```bashgit add web_app.py test_theme_text_leaks.pygit commit -m "Fix corn/farmer leaks in avatar-picker text and fullscreen button"```
---
### Task 10: Per-session browser tab title
**Files:**- Modify: `web_app.py` (inside `index()`, after theme is resolved โ see `app.storage.user.setdefault("theme", themes.DEFAULT_THEME)`)
**Interfaces:**- Consumes: `ui.page_title(title: str) -> None` (confirmed present in the installed `nicegui` version: sets `client.title` and pushes a `document.title` JS update if already connected).
- [ ] **Step 1: Add the per-theme tab title**
Find, in `index()`:```python theme_q = (request.query_params.get("theme") or "").strip().lower() if theme_q in themes.THEMES and not app.storage.user.get("theme"): app.storage.user["theme"] = theme_q app.storage.user.setdefault("theme", themes.DEFAULT_THEME)```
Add immediately after:```python TAB_TITLES = {"harvest": "HarvestForTwo", "jelly": "JellyfishForTwo", "firefly": "FireflyForTwo", "boxes": "BoxesForTwo"} ui.page_title(TAB_TITLES.get(app.storage.user["theme"], "HarvestForTwo"))```
- [ ] **Step 2: Verify via the existing in-process harness**
This isn't unit-testable as a pure function (it mutates client-side page state, not a return value), so verify via the `nicegui.testing.User` harness already established in this project (see Task 11, which exercises this alongside the theme-configure check).
- [ ] **Step 3: Commit**
```bashgit add web_app.pygit commit -m "Set the browser tab title per theme (was always HarvestForTwo)"```
---
### Task 11: Commit a permanent integration smoke test + dev-dependency setup
**Files:**- Create: `test_theme_scenes.py` (project root โ permanent, committed; consolidates and extends the ad-hoc scratchpad diagnostics used earlier in this project's history)- Modify: `pyproject.toml` (add `pytest-asyncio` to the existing `dev` extras group)
**Interfaces:**- Consumes: `nicegui.testing.User`, the `module_under_test` marker, and the `javascript_rules` auto-answer pattern already proven to work in this project (see the conversation history around `test_new_stages.py`/`test_theme_wiring.py`).
- [ ] **Step 1: Add `pytest-asyncio` to `pyproject.toml`'s dev extras**
Find:```toml[project.optional-dependencies]dev = [ "pytest", "black", "isort",]```
Replace with:```toml[project.optional-dependencies]dev = [ "pytest", "pytest-asyncio", "black", "isort",]```
- [ ] **Step 2: Write the committed smoke test**
Create `test_theme_scenes.py`:
```python"""Permanent smoke test: for every theme, confirm (a) the JS engine receivesthe correct theme key via Cornfield.configure(), (b) the per-session tabtitle matches, and (c) block labels are theme-correct (firefly = Evening/Night,others = Morning/Evening). Uses nicegui.testing.User (in-process ASGI, no realbrowser) -- this can prove the Python<->JS wiring is correct and that no stagethrows; it cannot verify the actual canvas pixels, which still needs a humancheck in a real browser after deploy."""import asyncioimport osimport re
os.environ["RELOAD"] = "0"os.environ["STORAGE_SECRET"] = "test"os.environ["PORT"] = "8096"
import pytestimport web_appfrom nicegui.testing import User
CLICK_LABELS = ["Continue", "Submit", "OK", "Next", "I'm ready! \U0001f33d", "Start", "Go again"]TAB_TITLES = {"harvest": "HarvestForTwo", "jelly": "JellyfishForTwo", "firefly": "FireflyForTwo", "boxes": "BoxesForTwo"}
async def _click_any(user: User): for label in CLICK_LABELS: try: el = user.find(label) except AssertionError: continue el.click() await asyncio.sleep(0.05) return label return None
def _capture_js(user: User, sink: list): original_emit = user._client.outbox._emit
async def spy_emit(message): await original_emit(message) _, type_, data = message if type_ == "run_javascript": sink.append(data["code"])
user._client.outbox._emit = spy_emit
@pytest.mark.parametrize("theme_key", ["harvest", "jelly", "firefly", "boxes"])@pytest.mark.module_under_test(web_app)async def test_theme_reaches_configure_and_tab_title(user: User, theme_key) -> None: await user.open(f"/?dev=1&start=practice&role=c&theme={theme_key}&pid=SMOKE_{theme_key}") js_calls = [] _capture_js(user, js_calls) user.javascript_rules[re.compile(r".*window\.Cornfield.*")] = lambda _match: None
for _ in range(15): await _click_any(user) await asyncio.sleep(0.1)
configure_calls = [c for c in js_calls if "Cornfield.configure" in c] assert configure_calls, f"Cornfield.configure was never called for theme={theme_key}" assert any(f'theme:"{theme_key}"' in c for c in configure_calls), \ f'theme:"{theme_key}" never appeared in any configure() call: {configure_calls}' assert user._client.title == TAB_TITLES[theme_key], \ f"tab title was {user._client.title!r}, expected {TAB_TITLES[theme_key]!r}"```
- [ ] **Step 3: Sync dev dependencies and run the test**
Run: `uv sync --extra dev && .venv/bin/python3 -m pytest test_theme_scenes.py test_block_labels.py test_theme_text_leaks.py -v`Expected: all pass. If `test_theme_reaches_configure_and_tab_title` for `firefly` fails on the tab-title assertion, re-check Task 10's Step 1 placement (it must run before `index()` mounts the page โ i.e. before the `ui.page` body begins building the card/UI).
- [ ] **Step 4: Commit**
```bashgit add test_theme_scenes.py pyproject.tomlgit commit -m "Add permanent theme-wiring smoke test (all 4 themes) + pytest-asyncio dev dep"```
---
### Task 12: Manual visual QA (not automated โ requires a real browser)
**Files:** none (verification only)
- [ ] **Step 1: Push to a review environment or run locally with a real browser**
Run: `PORT=8090 RELOAD=0 STORAGE_SECRET=devcheck uv run python web_app.py`, then open each of:- `http://localhost:8090/?dev=1&start=practice&theme=harvest&role=c`- `http://localhost:8090/?dev=1&start=practice&theme=jelly&role=c`- `http://localhost:8090/?dev=1&start=practice&theme=firefly&role=c`- `http://localhost:8090/?dev=1&start=practice&theme=boxes&role=c`
- [ ] **Step 2: For each theme, check**- Character (player + partner) matches the theme (farmer / snorkeler / night explorer / plain-gray).- REST scene (reachable by choosing Rest on a decision round, or waiting through a practice Rest trial): background, all 4 activities' art and effect glyphs, puppy accessory.- Decision-screen backdrop no longer shows blue sky / green hills / corn silhouettes for non-harvest themes.- For `firefly` specifically: confirm the block intro text (visit `?dev=1&start=harvest&theme=firefly`) says "Evening Firefly Catching" / and the second block (`?dev=1&start=main&theme=firefly` then let Harvest1 finish, or jump via `Harvest2` dev-skip point) says "Night Firefly Catching" โ and that the WORK-phase sky is dark in both, never bright daylight.- Cover screen and finish screen (`?dev=1&start=end&theme=<x>`, click through to the end) show the themed sky + the drawn container (crate/net/jar/stack).- Browser tab title matches the theme.
- [ ] **Step 2: Clean up any local test-data files this creates**
Run: `ls data/*SMOKE* data/*CHECK* 2>/dev/null` and remove any matches the same way prior smoke-testing artifacts were cleaned up in this project (delete the matching `log_*.log`, `user_data_*.msgpack`/`.json`/`_qualtrics.csv` โ `data/` is gitignored, so this never touches version control either way).
- [ ] **Step 3: Report back**
No commit for this task โ it's a checklist to run before considering the feature done, and to report findings back (anything that doesn't look right becomes a new small task, not a silent fix).docs/superpowers/plans/2026-08-03-theme-specific-scenes.mdAdded+1182