From 961d86c035d6bd6cd33dfc2e493e36c8fb44627e Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Wed, 5 Nov 2025 10:26:45 +0000 Subject: [PATCH] Implement dynamic paragraph line splitting and fix line break detection - Add calculateLineCount() to determine optimal lines based on text length (2-6 lines) - Add getPerspectiveFactors() for appropriate perspective scaling per line count - Replace hardcoded 6-line paragraphs with dynamic line calculation in both rendering and game logic - Fix line break detection in useGameStatus to match rendering calculations exactly - Extend keybindings to support all special characters: apostrophe, hyphen, colon, semicolon, quotes, parentheses, slash, ampersand, and digits - Integrate greatFallsParagraphs content as wordList in paragraph mode - Fix vertical centering to scale properly for variable line counts --- README.md | 2 +- example/src/App.tsx | 47 ++-- .../src/usePlatformHook/greatFallsContent.ts | 33 +++ .../src/usePlatformHook/usePlatformHook.ts | 12 +- .../src/usePlatformHook/useStateMachine.ts | 30 ++- src/gameInfo.ts | 2 +- src/useBoard/useBoard.ts | 222 ++++++++++-------- src/useGameStatus/useGameStatus.ts | 82 +++++-- 8 files changed, 277 insertions(+), 153 deletions(-) create mode 100644 example/src/usePlatformHook/greatFallsContent.ts diff --git a/README.md b/README.md index 8ff605c..a2546d1 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Full words fall from the top. Type each character of the word sequentially. Multi-line sentences with perspective effect. Continue typing through line breaks. ### Paragraphs -4-line paragraphs with advanced perspective and smooth line transitions. +6-line paragraphs with advanced perspective and smooth line transitions. ## API diff --git a/example/src/App.tsx b/example/src/App.tsx index 2281075..84a6e4f 100755 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,14 +1,21 @@ import { useState } from "react"; -import { useGame, type GameMode } from "@vimazing/the-last-startyper"; +import { useGame, type GameMode, type GameOptions } from "@vimazing/the-last-startyper"; import "@vimazing/the-last-startyper/game.css"; import { usePlatformHook, useStateMachine, getScenario, getScenarioNames } from "./usePlatformHook"; +import { greatFallsParagraphs } from "./usePlatformHook/greatFallsContent"; function App() { - const [scenarioId, setScenarioId] = useState("progressive"); - const scenario = getScenario(scenarioId); - const [gameMode, setGameMode] = useState(scenario.initialMode); - const gameManager = useGame({ gameMode }, usePlatformHook); - const { containerRef, gameStatus, scoreManager } = gameManager; + const [scenarioId, setScenarioId] = useState("progressive"); + const scenario = getScenario(scenarioId); + const [gameMode, setGameMode] = useState(scenario.initialMode); + + const getGameOptions = (mode: GameMode): GameOptions => ({ + gameMode: mode, + ...(mode === 'paragraphs' && { wordList: greatFallsParagraphs }), + }); + + const gameManager = useGame(getGameOptions(gameMode), usePlatformHook); + const { containerRef, gameStatus, scoreManager } = gameManager; useStateMachine({ gameManager, @@ -34,12 +41,12 @@ function App() {