refactor(games): make things consistent!#45
Conversation
Greptile SummaryThis PR refactors the falling-words game to match the structural conventions already established in the survival game, with no functional changes intended.
Confidence Score: 5/5Safe to merge — all changes are structural renames and consolidations with no behavioural differences. The diff is a pure refactor: file renames, return-shape reorganisation, shared-component extraction, and minor type tightening. The focusedWordId logic rewrite is logically equivalent to the original. The getWordBank null-removal is correct given the registry's exhaustive Record<WordBankId, WordBank> type. No new code paths, side effects, or data mutations are introduced. No files require special attention.
|
| Filename | Overview |
|---|---|
| apps/frontend/src/features/content/word-banks/manager.ts | Removes the ?? null fallback; safe because the registry is typed as Record<WordBankId, WordBank> (all keys always present), so the return type is now the non-nullable WordBank. |
| apps/frontend/src/features/games/falling-words/engine.ts | Renamed from use-falling-words-game.ts; return value restructured into { game, actions, wordBank } to mirror survival/engine.ts; UseGameOptions type now matches survival's; void keyword removed before onComplete call (safe, callback is typed as => void). |
| apps/frontend/src/features/games/falling-words/view.tsx | Refactored to use the shared useSubmitGameResult hook and the new GameOver component; wordBank.label access is safe now that getWordBank returns non-nullable WordBank. |
| apps/frontend/src/features/games/falling-words/components/field.tsx | Renamed from falling-words-field.tsx; game-over overlay extracted into the shared GameOver component in the view, score prop removed accordingly; phase prop is still used for the idle prompt. |
| apps/frontend/src/features/games/survival/engine.ts | Minor change: gameId: string tightened to gameId: GameId in UseGameOptions, making the type consistent with the falling-words engine. |
| apps/frontend/src/features/games/survival/view.tsx | Only change is the import rename from SurvivalHud to Hud; rest of the file unchanged. |
| apps/frontend/src/features/games/falling-words/types.ts | Removed UseFallingWordsGameOptions and CompletedGameResult types that are now consolidated into UseGameOptions in the engine file. |
Reviews (2): Last reviewed commit: "void" | Re-trigger Greptile
| /> | ||
|
|
||
| <GameMeta wordBankLabel={game.wordBank.label} gameName={meta.name} /> | ||
| <GameMeta wordBankLabel={wordBank.label} gameName={meta.name} /> |
There was a problem hiding this comment.
wordBank can be null (since getWordBank returns WordBank | null), so accessing .label directly will throw at runtime if the word bank ID isn't found. The survival view handles this correctly with an optional chain and fallback.
| <GameMeta wordBankLabel={wordBank.label} gameName={meta.name} /> | |
| <GameMeta wordBankLabel={wordBank?.label ?? meta.defaultWordBankId} gameName={meta.name} /> |
make falling words and survival consistent in code