krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

docs/superpowers/plans/2026-10-16-part4-richer-cards.md

062549ad26607ce9e973ed2a9a7ef6f853885f83
daybyday/docs/superpowers/plans/2026-10-16-part4-richer-cards.md rendered · source · history · blame · raw

134 lines · 14456 bytes

13 symbols in this file
  1# Part 4: Richer Cards Implementation Plan
  2
  3> **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.
  4
  5**Goal:** Cards that do more than say their name (animal sound and fact, letter and example word), shake-for-rain on the weather cards, and five topic activities: mix colors, trace shapes and letters, dress for the weather, sort fruit and vegetables, and "Touch your nose!" moves.
  6
  7**Architecture:** Card lines live on the item enums (`cardLine`) and are spoken through a small `CardVoice` that plays a sound first and cancels stale lines. Mix colors and dress for the weather are `QuestionSource`s run by `RoundView`, which gains a header that shows a question's `shown` items. Tracing, sorting and moves are pure models (`TraceChecker`/`TraceGuide`, `SortRound`, `MovesRound`) with their own views. All five are `Game` cases opened by `GameDestination`.
  8
  9**Tech Stack:** SwiftUI, CoreGraphics/CoreText (trace regions), AVFoundation, Swift Testing, Xcode 27.
 10
 11**Spec:** `docs/superpowers/specs/2026-10-16-learning-games-design.md` (part 4). Builds on the part 1–3 plans in this folder.
 12
 13## Global Constraints
 14
 15- Effective deployment target is iOS 17.5; SF Symbols used must exist on iOS 17 (SF Symbols 5). Each new symbol gets a `UIImage(systemName:)` test.
 16- `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor`; pure logic is `nonisolated`.
 17- New files under `DayByDay/` and `DayByDayTests/`. No bundled assets; sound synthesized, art in SwiftUI/SF Symbols/the food emoji already in use.
 18- Nothing requires reading: every prompt is spoken; bins and choices are pictures.
 19- Wrong answers: `.gentleMiss` plus a spoken correction. No buzzer, no red X.
 20- Every touched card uses flat fills; every new fill with white content is ≥ 3:1 in `ContrastTests`.
 21- Lifecycle: every `asyncAfter` checks a `generation` counter that only `onDisappear` bumps; screen states sit in a `ZStack`, not a `Group`; card grids stay stable.
 22- Advance after speech with `SpeechSynthesizer.speak(_:completion:)` instead of guessing its length, with a backstop timer.
 23- Reduce Motion: rain from shaking shows still drops that fade instead of falling.
 24- `Game` raw values are persisted; add new cases, never rename.
 25- No camera or microphone. Shake uses the UIKit shake event.
 26- Branch `feat/richer-cards`. Every commit `Ref #N` (last `Closes #N`). No AI attribution.
 27- Test command: `xcodebuild test -project DayByDay.xcodeproj -scheme DayByDay -destination 'platform=iOS Simulator,name=iPhone 18 Pro'` (about 10 min for the full suite; run in the background).
 28
 29## Review Focus
 30
 311. Tracing accepts a child's wobbly but on-target trace and rejects a scribble elsewhere or a half-finished trace, at any canvas size. Test in Task 3.
 322. Dress for the weather never offers a second suitable item as a distractor (coat and jacket suit rain, snow and wind). Test in Task 5.
 333. Rapid taps on look-and-listen cards: only the last card's line is spoken; a sound from an earlier card never runs into a later card's line. Test in Task 1 (`CardVoice` token logic).
 344. Sorting: a tap on a bin while a correction plays, or after the last food, is ignored and records nothing. Test in Task 6.
 355. Leaving any new screen mid-feedback says nothing afterwards (generation guard). Checked in review.
 36
 37---
 38
 39### Task 0: Branch and issue
 40
 41- [ ] `git checkout -b feat/richer-cards main`; `gitbay issue create --title "Part 4: richer cards and topic activities" --json --file -`; commit this plan with `Ref #N`.
 42
 43### Task 1: Card lines, CardVoice, flat animal and letter cards
 44
 45**Files:** Modify `AnimalCard.swift`, `LetterCard.swift`, `AnimalsView.swift`, `AlphabetView.swift`. Create `DayByDay/Quiz/CardVoice.swift`. Test `DayByDayTests/CardLineTests.swift`, `ContrastTests.swift`.
 46
 47**Interfaces:**
 48- `nonisolated extension LearnAnimal { var fact: String; var cardLine: String }`. `cardLine == "\(name)! \(fact)"`. Facts: cat "Cats say meow.", dog "Dogs say woof.", bird "Birds can fly.", fish "Fish swim in water.", rabbit "Rabbits hop.", turtle "Turtles carry their shell.", ladybug "Ladybugs have spots.", cow "Cows say moo.", duck "Ducks say quack.", sheep "Sheep say baa.", pig "Pigs say oink."
 49- `nonisolated extension LearnLetter { var cardLine: String }` = `"\(spokenName). \(spokenName) is for \(exampleWord)."`
 50- `@MainActor final class CardVoice { static let shared; func say(_ line: String, after sound: SoundEffect?); func cancel() }`. Bumps a token, stops speech, plays the sound, speaks after `SoundEngine.remaining(sound) + 0.2` only if the token is unchanged. Testable seam: `nonisolated struct LineQueue { mutating func next() -> Int; func isCurrent(_ token: Int) -> Bool }` used by `CardVoice`.
 51- `LearnAnimal.color` and `LearnLetter.color` changed to values ≥ 3:1 against white; cards use flat fills. Card taps call `CardVoice.shared.say(animal.cardLine, after: animal.sound)` / `say(letter.cardLine, after: nil)`. Views call `CardVoice.shared.cancel()` on disappear.
 52
 53- [ ] Tests: `animalLines` (cow → "Cow! Cows say moo."), `letterLines` (b → "b. b is for ball."), `lineQueueKeepsOnlyLatest` (tokens 1, 2: isCurrent(1) false, isCurrent(2) true), `ContrastTests.animalColorAgainstWhite` and `letterColorAgainstWhite` over all cases. RED, implement, GREEN, commit `feat: animal and letter cards say more`.
 54
 55### Task 2: Question header and Mix colors
 56
 57**Files:** Modify `Question.swift` (`shown`), `RoundView.swift` (header), `Game.swift`, `GameDestination.swift`. Create `DayByDay/Quiz/MixColors.swift`. Test `DayByDayTests/MixColorsTests.swift`, `GameTests.swift`.
 58
 59**Interfaces:**
 60- `Question.shown: [QuizItem] = []`: items drawn above the choices.
 61- `RoundView` draws a header when `current.shown` is not empty: the shown items as 110 pt tiles joined by "+" and followed by "= ?" when there are two; a single item is drawn alone. Existing call sites unchanged.
 62- `nonisolated struct MixColors: QuestionSource`. Mixes: red + yellow = orange, blue + yellow = green, red + blue = purple, red + white = pink. Prompt `"What do \(a) and \(b) make?"` (lower-case color names). Choices: the answer plus other colors, never `a` or `b`. Correction fact on every wrong choice: `"\(A) and \(b) make \(answer)."`.
 63- `Game.mixColors` ("Mix colors", symbol `paintbrush.fill`, `usesRound`). Colors games `[findIt, mixColors]`.
 64
 65- [ ] Tests: `everyMixIsRight` (answer matches the table for the shown pair), `mixNeverOffersIngredients`, `mixPrompt`, `mixCorrection`; catalog. RED, implement, GREEN, render check, commit `feat: mix colors`.
 66
 67### Task 3: Trace model
 68
 69**Files:** Create `DayByDay/Quiz/Trace.swift`. Test `DayByDayTests/TraceTests.swift`.
 70
 71**Interfaces:**
 72- `nonisolated enum TraceGuide { static func region(for item: QuizItem, size: CGFloat) -> CGPath }`: letters are the filled glyph of the uppercase letter in the system rounded heavy font, scaled to fit 80% of a `size`×`size` square and centered; shapes are their outline stroked at `0.12 * size` (circle, square, triangle, star (5 points), heart, oval, diamond, rectangle).
 73- `nonisolated struct TraceChecker { init(region: CGPath, size: CGFloat); let samples: [CGPoint]; func score(_ drawn: [CGPoint]) -> (coverage: Double, accuracy: Double); func passes(_ drawn: [CGPoint]) -> Bool }`. Samples are grid points inside the region at spacing `size / 30`. Tolerance `size * 0.07`. Coverage: share of samples within tolerance of a drawn point. Accuracy: share of drawn points inside the region or within tolerance of a sample. Passes at coverage ≥ 0.75 and accuracy ≥ 0.75.
 74
 75- [ ] Tests, for the circle, star and letters A and S at sizes 300 and 600: `tracingTheGuidePasses` (drawn = samples jittered by up to 0.03·size), `scribbleElsewhereFails` (points in a box outside the region), `halfTraceFails` (first half of samples by x), `regionsFitTheCanvas` (bounding box inside the square, at least 40% of it). RED, implement, GREEN, commit `feat: trace checker`.
 76
 77### Task 4: Trace game
 78
 79**Files:** Create `DayByDay/Quiz/TraceView.swift`. Modify `Game.swift`, `GameDestination.swift`.
 80
 81**Interfaces:**
 82- `Game.trace` ("Trace it", symbol `hand.draw.fill`, not `usesRound`). Shapes games `[findIt, oddOneOut, trace]`; alphabet games `[findIt, listen, trace]`.
 83- `TraceView(category:)`: five random items per round. The guide region is filled in the topic color at 30% opacity with a dashed topic-color edge; the finger's ink is the topic color at 0.08·size wide. It speaks `"Trace the \(name) with your finger."` (letters: `"Trace the letter \(spokenName)."`). On each lift, if `passes` → `.success`, "You traced the \(name)!", next item after the line ends; if accuracy < 0.5 and coverage > 0.4 → `.gentleMiss`, "Stay on the \(name). Let's try again.", ink cleared. "Start over" clears the ink. After five → `FinishedView`. Records `record(item, game: .trace, correct:)` for each pass or miss.
 84
 85- [ ] Catalog test update; build; render check; commit `feat: trace shapes and letters`.
 86
 87### Task 5: Dress for the weather
 88
 89**Files:** Create `DayByDay/Quiz/DressUp.swift`, `DayByDay/Quiz/ClothingTile.swift`. Modify `Game.swift`, `GameDestination.swift`. Test `DayByDayTests/DressUpTests.swift`.
 90
 91**Interfaces:**
 92- `nonisolated enum Clothing: Int, CaseIterable { sunglasses, sunHat, tshirt, umbrella, coat, jacket }` with `name`, `symbol` (`sunglasses.fill`, `hat.widebrim.fill`, `tshirt.fill`, `umbrella.fill`, `coat.fill`, `jacket.fill`), `suits: Set<LearnWeather>` (sunglasses, sunHat, tshirt: sunny; umbrella: rainy; coat and jacket: rainy, snowy, windy), `item: QuizItem` (`id "clothing.<case>"`, category `.weather`), `static func from(_ item: QuizItem) -> Clothing?`.
 93- `nonisolated struct DressUp: QuestionSource`: weather from `[sunny, rainy, snowy, windy]` (never the previous question's weather); answer from the clothing that suits it; distractors only from clothing that does not. Prompt `"It's \(weather.name.lowercased())! What should we wear?"`; `shown = [weather item]`. Facts on wrong choices: `"\(Name) is not for \(weather) days."` (umbrella: "An umbrella is for rainy days." style — use `fact(for:)` per clothing: "Sunglasses are for sunny days.", "A sun hat is for sunny days.", "A T-shirt is for warm days.", "An umbrella is for rainy days.", "A coat is for cold days.", "A jacket is for cold, windy days.").
 94- `ClothingTile(item:)`: weather-topic flat fill, white symbol.
 95- `Game.dressUp` ("Dress for the weather", symbol `tshirt.fill`, `usesRound`). Weather games `[findIt, listen, dressUp]`.
 96
 97- [ ] Tests: `onlyOneSuitableChoice` (300 draws: exactly one choice suits the shown weather), `promptAndShown`, `clothingSymbolsExist`, `idsPinned` (all six ids). RED, implement, GREEN, render, commit `feat: dress for the weather`.
 98
 99### Task 6: Sort fruit and vegetables
100
101**Files:** Create `DayByDay/Quiz/SortRound.swift`, `DayByDay/Quiz/SortView.swift`. Modify `Game.swift`, `GameDestination.swift`. Test `DayByDayTests/SortRoundTests.swift`.
102
103**Interfaces:**
104- `nonisolated struct SortRound { init(using:); let foods: [LearnFood] (3 fruit + 3 vegetables, shuffled); var current: LearnFood?; private(set) var fruitBin, vegetableBin: [LearnFood]; private(set) var isShowingCorrection; mutating func place(isFruit: Bool) -> AnswerOutcome; mutating func resume(); func correction() -> String; var prompt: String? }`. Prompt `"Is the \(name.lowercased()) a fruit or a vegetable?"`. Correction `"\(A/An) \(name.lowercased()) is a \(fruit|vegetable). Try again!"`.
105- `SortView`: current food emoji large (draggable); two bins below (🍓 "Fruit", 🥕 "Vegetables" as pictures with labels), tap or drop. Correct food drops into its bin (bin shows the foods it holds). Records `record(food item, game: .sortFood, correct:)`. After six → `FinishedView`.
106- `Game.sortFood` ("Fruit or vegetable?", symbol `basket.fill`, not `usesRound`). Food games `[findIt, oddOneOut, sortFood]`.
107
108- [ ] Tests: `threeOfEach`, `correctBinAdvances`, `wrongBinWaits` (.incorrect, then .ignored until resume), `doneIgnoresInput`, `correctionCopy` (apple → "An apple is a fruit. Try again!"). RED, implement, GREEN, render, commit `feat: sort fruit and vegetables`.
109
110### Task 7: Touch your nose
111
112**Files:** Create `DayByDay/Quiz/MovesRound.swift`, `DayByDay/Quiz/MovesView.swift`. Modify `Game.swift`, `GameDestination.swift`. Test `DayByDayTests/MovesRoundTests.swift`.
113
114**Interfaces:**
115- `nonisolated extension LearnBodyPart { var command: String }`: head "Touch your head!", eyes "Blink your eyes!", ears "Touch your ears!", nose "Touch your nose!", mouth "Point to your mouth!", hands "Clap your hands!", fingers "Wiggle your fingers!", arms "Wave your arms!", legs "March in place!", feet "Stomp your feet!", heart "Put your hand on your heart!", belly "Pat your belly!".
116- `nonisolated struct MovesRound { static let length = 5; init(using:); let parts: [LearnBodyPart] (5 distinct); private(set) var index; var current: LearnBodyPart?; mutating func next() }`.
117- `MovesView`: the body-part tile large; speaks the command; 3 s after the line ends plays `.success` and a praise phrase; moves on after that line ends. "Hear it again". After five → `FinishedView`. Nothing recorded.
118- `Game.moves` ("Move your body", symbol `figure.wave`, not `usesRound`). Body games `[findIt, moves]`.
119
120- [ ] Tests: `fiveDistinctParts`, `commandsForAll`, `advancesToEnd`. RED, implement, GREEN, render, commit `feat: move your body`.
121
122### Task 8: Shake for rain
123
124**Files:** Create `DayByDay/Quiz/ShakeRain.swift`. Modify `WeatherView.swift`.
125
126**Interfaces:**
127- `extension UIWindow { open override func motionEnded(_:with:) }` posts `Notification.Name.deviceDidShake` for `.motionShake`. `View.onShake(_:)` modifier.
128- `RainOverlay(isActive:)`: falling drops for 3 s in a light-and-dark-visible blue; Reduce Motion shows still drops that fade. `WeatherView` plays `.rain`, shows the overlay and says "It's raining!" on shake; a shake during rain is ignored.
129
130- [ ] Build; render check of the overlay; commit `feat: shake for rain`.
131
132### Task 9: Reviews, MR, merge
133
134- [ ] Extend `ReviewExport` with the new screens and run it. Fresh art/sound reviewer (two rounds max, block on clear defects). Fresh whole-branch code reviewer with this Review Focus. One fix pass, each fix RED→GREEN. Full suite green. Push, MR with `Closes #N` and open notes, squash-merge, delete branch.