Implement platform-controlled GameOptions for complete game behavior customization

- Add GameOptions with gameMode, downwardSpeed, boardDimensions, and wordList
- Platform now controls ALL game behavior through options
- changeGameMode now accepts full GameOptions instead of just mode
- downwardSpeed as single px/s value applies to any mode
- wordList is mode-agnostic, platform provides what they need
- All options are fully optional with sensible defaults
- Update example app to use new options API
This commit is contained in:
2025-11-04 19:56:25 +00:00
parent 2944d43c4a
commit 157e2a71f4
6 changed files with 913 additions and 17 deletions
+6 -5
View File
@@ -6,16 +6,17 @@ import { useGameStatus } from "../useGameStatus";
import { useScore } from "../useScore";
export function useGame(
options?: GameOptions,
initialOptions?: GameOptions,
platformHook?: unknown
): GameManager {
const [keyLog, setKeyLog] = useState<KeyLogEntry[]>([]);
const [gameMode, setGameModeState] = useState<GameMode>(options?.initialGameMode ?? 'letters');
const [options, setOptions] = useState<GameOptions>(initialOptions ?? {});
const gameMode = options.gameMode ?? 'letters';
const gameModeRef = useRef<GameMode>(gameMode);
const boardManager = useBoard();
const cursorManager = useCursor();
const gameStatusManager = useGameStatus(undefined, gameMode);
const gameStatusManager = useGameStatus(undefined, options);
// Wrap renderBoard to include player position and lasers
const renderBoardWrapped = (letters: any = [], lasers: Laser[] = [], shipState: ShipState = 'normal', shipExplosionTime: number = 0) => {
@@ -68,8 +69,8 @@ export function useGame(
gameStatusManager.setGameMode(gameMode);
}, [gameMode]);
const changeGameMode = (mode: GameMode) => {
setGameModeState(mode);
const changeGameMode = (newOptions: GameOptions) => {
setOptions(newOptions);
// Don't quit - just switch modes and let game continue
};