Skip to content

refactor(games): make things consistent!#45

Merged
d1rshan merged 9 commits into
mainfrom
refactor/falling-words
May 31, 2026
Merged

refactor(games): make things consistent!#45
d1rshan merged 9 commits into
mainfrom
refactor/falling-words

Conversation

@d1rshan

@d1rshan d1rshan commented May 31, 2026

Copy link
Copy Markdown
Owner

make falling words and survival consistent in code

@d1rshan d1rshan marked this pull request as ready for review May 31, 2026 05:07
@greptile-apps

greptile-apps Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR refactors the falling-words game to match the structural conventions already established in the survival game, with no functional changes intended.

  • Component files are renamed to generic names (field.tsx, hud.tsx) and exports are unified; the engine is renamed from use-falling-words-game.ts to engine.ts, and its return shape is restructured into { game, actions, wordBank } to mirror survival/engine.ts.
  • The game-over overlay is extracted from Field into the shared GameOver component, useSubmitGameResult replaces the inline result-saving logic in the view, and UseGameOptions.onComplete is aligned with the survival engine's type (dropping the unused Promise<void> overload and the void keyword on the call site).
  • getWordBank drops the ?? null fallback, making it consistent with the registry's Record<WordBankId, WordBank> type; survival/engine.ts also has its gameId field tightened from string to GameId.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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} />

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.

P1 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.

Suggested change
<GameMeta wordBankLabel={wordBank.label} gameName={meta.name} />
<GameMeta wordBankLabel={wordBank?.label ?? meta.defaultWordBankId} gameName={meta.name} />

Comment thread apps/frontend/src/features/games/falling-words/engine.ts
@d1rshan d1rshan merged commit 449ef5a into main May 31, 2026
1 check passed
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.

1 participant