brick-engine-js 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.local.example +2 -0
- package/.github/workflows/publish.yml +73 -0
- package/.prettierignore +2 -0
- package/.prettierrc.json +8 -0
- package/README.adoc +84 -0
- package/dist/8e23286c2fdf41fd795f.svg +32 -0
- package/dist/CNAME +1 -0
- package/dist/app.js +2 -0
- package/dist/app.js.map +1 -0
- package/dist/brick-engine.js +2 -0
- package/dist/brick-engine.js.map +1 -0
- package/dist/config/configs.d.ts +180 -0
- package/dist/config/configs.test.d.ts +1 -0
- package/dist/config/env.d.ts +2 -0
- package/dist/config/env.test.d.ts +1 -0
- package/dist/config/styles.d.ts +0 -0
- package/dist/core/Game.d.ts +107 -0
- package/dist/core/Game.test.d.ts +1 -0
- package/dist/core/InitialStateSnapshot.d.ts +19 -0
- package/dist/core/InitialStateSnapshot.test.d.ts +1 -0
- package/dist/core/helpers/CellHelper.d.ts +13 -0
- package/dist/core/helpers/CellHelper.test.d.ts +1 -0
- package/dist/core/helpers/ControlInputHandlerHelper.d.ts +32 -0
- package/dist/core/helpers/ControlInputHandlerHelper.test.d.ts +1 -0
- package/dist/core/helpers/CoordinateHelper.d.ts +54 -0
- package/dist/core/helpers/CoordinateHelper.test.d.ts +1 -0
- package/dist/core/helpers/InterfaceIdentifierHelper.d.ts +7 -0
- package/dist/core/helpers/InterfaceIdentifierHelper.test.d.ts +1 -0
- package/dist/core/helpers/RelativeValuesHelper.d.ts +23 -0
- package/dist/core/helpers/RelativeValuesHelper.test.d.ts +1 -0
- package/dist/core/module/control/GameControl.d.ts +62 -0
- package/dist/core/module/control/GameControl.test.d.ts +1 -0
- package/dist/core/module/control/GameControlKeyBinding.d.ts +36 -0
- package/dist/core/module/control/GameControlKeyBinding.test.d.ts +1 -0
- package/dist/core/module/grid/GameGrid.d.ts +399 -0
- package/dist/core/module/grid/GameGrid.test.d.ts +1 -0
- package/dist/core/module/grid/GameHudGrid.d.ts +24 -0
- package/dist/core/module/grid/GameHudGrid.test.d.ts +1 -0
- package/dist/core/module/grid/engines/GridAnalysisEngine.d.ts +29 -0
- package/dist/core/module/grid/engines/GridAnalysisEngine.test.d.ts +1 -0
- package/dist/core/module/grid/engines/GridLineEngine.d.ts +56 -0
- package/dist/core/module/grid/engines/GridLineEngine.test.d.ts +1 -0
- package/dist/core/module/grid/engines/GridMovementEngine.d.ts +29 -0
- package/dist/core/module/grid/engines/GridMovementEngine.test.d.ts +1 -0
- package/dist/core/module/grid/engines/GridRegionEngine.d.ts +26 -0
- package/dist/core/module/grid/engines/GridRegionEngine.test.d.ts +1 -0
- package/dist/core/module/grid/engines/GridTransformEngine.d.ts +24 -0
- package/dist/core/module/grid/engines/GridTransformEngine.test.d.ts +1 -0
- package/dist/core/module/renderer/DisplayRenderer.d.ts +51 -0
- package/dist/core/module/renderer/DisplayRenderer.test.d.ts +1 -0
- package/dist/core/module/renderer/GameRenderer.d.ts +59 -0
- package/dist/core/module/renderer/GameRenderer.test.d.ts +1 -0
- package/dist/core/module/renderer/HudRenderer.d.ts +56 -0
- package/dist/core/module/renderer/HudRenderer.test.d.ts +1 -0
- package/dist/core/module/score/GameScore.d.ts +117 -0
- package/dist/core/module/score/GameScore.test.d.ts +1 -0
- package/dist/core/module/session/GameSession.d.ts +20 -0
- package/dist/core/module/session/GameSession.test.d.ts +1 -0
- package/dist/core/module/sound/GameSound.d.ts +85 -0
- package/dist/core/module/sound/GameSound.test.d.ts +1 -0
- package/dist/core/module/state/GameState.d.ts +172 -0
- package/dist/core/module/state/GameState.test.d.ts +1 -0
- package/dist/core/module/text/GameText.d.ts +87 -0
- package/dist/core/module/text/GameText.test.d.ts +1 -0
- package/dist/core/module/time/GameTime.d.ts +76 -0
- package/dist/core/module/time/GameTime.test.d.ts +1 -0
- package/dist/core/types/Interfaces.d.ts +53 -0
- package/dist/core/types/Types.d.ts +114 -0
- package/dist/core/types/enums.d.ts +106 -0
- package/dist/core/types/modules.d.ts +723 -0
- package/dist/css/app.743066d8e4172b0e73f9.css +824 -0
- package/dist/css/app.743066d8e4172b0e73f9.css.map +1 -0
- package/dist/docs/GAME_DEVELOPER_GUIDE.html +727 -0
- package/dist/docs/brick-engine-guide.html +610 -0
- package/dist/docs/diagrams/lifecycle.mmd +19 -0
- package/dist/docs/documentation_style_guide.html +994 -0
- package/dist/docs/getting-started.html +648 -0
- package/dist/docs/images/lifecycle.svg +1 -0
- package/dist/docs/index.html +593 -0
- package/dist/docs/jsdoc_standard.html +656 -0
- package/dist/docs/publishing.html +573 -0
- package/dist/docs/reference/enums/Color.html +533 -0
- package/dist/docs/reference/enums/ControlEventType.html +505 -0
- package/dist/docs/reference/enums/ControlKey.html +529 -0
- package/dist/docs/reference/enums/FontAlignment.html +545 -0
- package/dist/docs/reference/enums/FontSize.html +517 -0
- package/dist/docs/reference/enums/Sound.html +558 -0
- package/dist/docs/reference/enums/StateProperty.html +525 -0
- package/dist/docs/reference/helpers/CellHelper.html +520 -0
- package/dist/docs/reference/helpers/ControlInputHandlerHelper.html +569 -0
- package/dist/docs/reference/helpers/CoordinateHelper.html +703 -0
- package/dist/docs/reference/helpers/RelativeValuesHelper.html +560 -0
- package/dist/docs/reference/interfaces/Debuggable.html +501 -0
- package/dist/docs/reference/interfaces/GameModules.html +544 -0
- package/dist/docs/reference/interfaces/Initializable.html +495 -0
- package/dist/docs/reference/interfaces/RendererInitializable.html +517 -0
- package/dist/docs/reference/interfaces/StateSyncable.html +542 -0
- package/dist/docs/reference/interfaces/modules/Control.html +648 -0
- package/dist/docs/reference/interfaces/modules/Grid.html +1256 -0
- package/dist/docs/reference/interfaces/modules/Renderer.html +522 -0
- package/dist/docs/reference/interfaces/modules/RendererComposite.html +577 -0
- package/dist/docs/reference/interfaces/modules/Score.html +669 -0
- package/dist/docs/reference/interfaces/modules/Session.html +585 -0
- package/dist/docs/reference/interfaces/modules/State.html +897 -0
- package/dist/docs/reference/interfaces/modules/Text.html +668 -0
- package/dist/docs/reference/interfaces/modules/Time.html +684 -0
- package/dist/docs/reference/modules/Debugger.html +579 -0
- package/dist/docs/reference/modules/DisplayRenderer.html +557 -0
- package/dist/docs/reference/modules/Game.html +909 -0
- package/dist/docs/reference/modules/GameControl.html +716 -0
- package/dist/docs/reference/modules/GameGrid.html +1910 -0
- package/dist/docs/reference/modules/GameHudGrid.html +508 -0
- package/dist/docs/reference/modules/GameMenu.html +538 -0
- package/dist/docs/reference/modules/GameRenderer.html +589 -0
- package/dist/docs/reference/modules/GameScore.html +664 -0
- package/dist/docs/reference/modules/GameSession.html +533 -0
- package/dist/docs/reference/modules/GameSound.html +636 -0
- package/dist/docs/reference/modules/GameState.html +922 -0
- package/dist/docs/reference/modules/GameText.html +701 -0
- package/dist/docs/reference/modules/GameTime.html +696 -0
- package/dist/docs/reference/modules/HudRenderer.html +568 -0
- package/dist/docs/reference/modules/InitialStateSnapshot.html +557 -0
- package/dist/docs/reference/modules/SessionModal.html +520 -0
- package/dist/docs/reference/types/Axis.html +505 -0
- package/dist/docs/reference/types/Cell.html +514 -0
- package/dist/docs/reference/types/ControlCallback.html +488 -0
- package/dist/docs/reference/types/Coordinate.html +510 -0
- package/dist/docs/reference/types/GameEntry.html +514 -0
- package/dist/docs/reference/types/GameEvent.html +514 -0
- package/dist/docs/reference/types/Piece.html +506 -0
- package/dist/docs/reference/types/RendererMetrics.html +514 -0
- package/dist/docs/reference/types/Vector.html +509 -0
- package/dist/docs/testing_best_practices.html +770 -0
- package/dist/favicon.ico +0 -0
- package/dist/fonts/digital-7.monoitalic.ttf +0 -0
- package/dist/images/cell.svg +32 -0
- package/dist/images/close.png +0 -0
- package/dist/images/games.png +0 -0
- package/dist/images/github.png +0 -0
- package/dist/images/letter-a.png +0 -0
- package/dist/images/letter-d.png +0 -0
- package/dist/images/letter-j.png +0 -0
- package/dist/images/letter-s.png +0 -0
- package/dist/images/letter-w.png +0 -0
- package/dist/images/meta-image.png +0 -0
- package/dist/images/number-1.png +0 -0
- package/dist/images/number-2.png +0 -0
- package/dist/images/number-3.png +0 -0
- package/dist/images/number-4.png +0 -0
- package/dist/images/number-5.png +0 -0
- package/dist/images/number-6.png +0 -0
- package/dist/images/splash.gif +0 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.html +1 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.test.d.ts +1 -0
- package/dist/menu/GameMenu.d.ts +15 -0
- package/dist/menu/GameMenu.test.d.ts +1 -0
- package/dist/menu/GameMenuSingleton.d.ts +6 -0
- package/dist/menu/GameMenuSingleton.test.d.ts +1 -0
- package/dist/menu/GameRepository.d.ts +7 -0
- package/dist/menu/GameRepository.test.d.ts +1 -0
- package/dist/menu/manager/GameManager.d.ts +6 -0
- package/dist/menu/manager/GameManager.test.d.ts +1 -0
- package/dist/sounds/sound_00.wav +0 -0
- package/dist/sounds/sound_01.wav +0 -0
- package/dist/sounds/sound_02.wav +0 -0
- package/dist/sounds/sound_03.wav +0 -0
- package/dist/sounds/sound_04.wav +0 -0
- package/dist/sounds/sound_05.wav +0 -0
- package/dist/sounds/sound_06.wav +0 -0
- package/dist/sounds/sound_07.wav +0 -0
- package/dist/sounds/sound_08.wav +0 -0
- package/dist/sounds/sound_09.wav +0 -0
- package/dist/sounds/sound_10.wav +0 -0
- package/dist/sounds/sound_11.wav +0 -0
- package/dist/sounds/sound_12.wav +0 -0
- package/dist/sounds/sound_13.wav +0 -0
- package/dist/sounds/sound_14.wav +0 -0
- package/dist/sounds/sound_15.wav +0 -0
- package/dist/types/interfaces.d.ts +5 -0
- package/dist/vendor/p5.min.js +1 -0
- package/dist/view/Debugger.d.ts +12 -0
- package/dist/view/Debugger.test.d.ts +1 -0
- package/dist/view/GameView.d.ts +101 -0
- package/dist/view/GameView.test.d.ts +1 -0
- package/dist/view/SessionModal.d.ts +12 -0
- package/dist/view/SessionModal.test.d.ts +4 -0
- package/dist/view/components/layout/ButtonLayout.d.ts +25 -0
- package/dist/view/components/layout/ButtonLayout.test.d.ts +1 -0
- package/dist/view/components/layout/ContainerLayout.d.ts +23 -0
- package/dist/view/components/layout/ContainerLayout.test.d.ts +1 -0
- package/dist/view/components/layout/FrameLayout.d.ts +11 -0
- package/dist/view/components/layout/FrameLayout.test.d.ts +1 -0
- package/dist/view/components/ui/BigButton.d.ts +13 -0
- package/dist/view/components/ui/BigButton.test.d.ts +1 -0
- package/dist/view/components/ui/Button.d.ts +12 -0
- package/dist/view/components/ui/Button.test.d.ts +1 -0
- package/dist/view/components/ui/Canvas.d.ts +22 -0
- package/dist/view/components/ui/Canvas.test.d.ts +1 -0
- package/dist/view/components/ui/SmallButton.d.ts +13 -0
- package/dist/view/components/ui/SmallButton.test.d.ts +1 -0
- package/dist/view/theme/applyColors.d.ts +10 -0
- package/dist/view/theme/applyColors.test.d.ts +1 -0
- package/dist/view/theme/dimensions.d.ts +13 -0
- package/dist/view/theme/dimensions.test.d.ts +1 -0
- package/docs/GAME_DEVELOPER_GUIDE.adoc +167 -0
- package/docs/brick-engine-guide.adoc +87 -0
- package/docs/diagrams/lifecycle.mmd +19 -0
- package/docs/documentation_style_guide.adoc +210 -0
- package/docs/getting-started.adoc +147 -0
- package/docs/images/lifecycle.svg +1 -0
- package/docs/jsdoc_standard.adoc +109 -0
- package/docs/publishing.adoc +58 -0
- package/docs/reference/enums/Color.adoc +35 -0
- package/docs/reference/enums/ControlEventType.adoc +28 -0
- package/docs/reference/enums/ControlKey.adoc +34 -0
- package/docs/reference/enums/FontAlignment.adoc +43 -0
- package/docs/reference/enums/FontSize.adoc +31 -0
- package/docs/reference/enums/Sound.adoc +42 -0
- package/docs/reference/enums/StateProperty.adoc +33 -0
- package/docs/reference/helpers/CellHelper.adoc +37 -0
- package/docs/reference/helpers/ControlInputHandlerHelper.adoc +57 -0
- package/docs/reference/helpers/CoordinateHelper.adoc +118 -0
- package/docs/reference/helpers/RelativeValuesHelper.adoc +53 -0
- package/docs/reference/interfaces/Debuggable.adoc +29 -0
- package/docs/reference/interfaces/GameModules.adoc +35 -0
- package/docs/reference/interfaces/Initializable.adoc +24 -0
- package/docs/reference/interfaces/RendererInitializable.adoc +33 -0
- package/docs/reference/interfaces/StateSyncable.adoc +41 -0
- package/docs/reference/interfaces/modules/Control.adoc +98 -0
- package/docs/reference/interfaces/modules/Grid.adoc +411 -0
- package/docs/reference/interfaces/modules/Renderer.adoc +34 -0
- package/docs/reference/interfaces/modules/RendererComposite.adoc +57 -0
- package/docs/reference/interfaces/modules/Score.adoc +107 -0
- package/docs/reference/interfaces/modules/Session.adoc +66 -0
- package/docs/reference/interfaces/modules/State.adoc +290 -0
- package/docs/reference/interfaces/modules/Text.adoc +110 -0
- package/docs/reference/interfaces/modules/Time.adoc +119 -0
- package/docs/reference/modules/Debugger.adoc +71 -0
- package/docs/reference/modules/DisplayRenderer.adoc +55 -0
- package/docs/reference/modules/Game.adoc +256 -0
- package/docs/reference/modules/GameControl.adoc +139 -0
- package/docs/reference/modules/GameGrid.adoc +794 -0
- package/docs/reference/modules/GameHudGrid.adoc +38 -0
- package/docs/reference/modules/GameMenu.adoc +39 -0
- package/docs/reference/modules/GameRenderer.adoc +79 -0
- package/docs/reference/modules/GameScore.adoc +138 -0
- package/docs/reference/modules/GameSession.adoc +43 -0
- package/docs/reference/modules/GameSound.adoc +111 -0
- package/docs/reference/modules/GameState.adoc +318 -0
- package/docs/reference/modules/GameText.adoc +139 -0
- package/docs/reference/modules/GameTime.adoc +141 -0
- package/docs/reference/modules/HudRenderer.adoc +56 -0
- package/docs/reference/modules/InitialStateSnapshot.adoc +47 -0
- package/docs/reference/modules/SessionModal.adoc +34 -0
- package/docs/reference/types/Axis.adoc +28 -0
- package/docs/reference/types/Cell.adoc +29 -0
- package/docs/reference/types/ControlCallback.adoc +23 -0
- package/docs/reference/types/Coordinate.adoc +29 -0
- package/docs/reference/types/GameEntry.adoc +29 -0
- package/docs/reference/types/GameEvent.adoc +29 -0
- package/docs/reference/types/Piece.adoc +32 -0
- package/docs/reference/types/RendererMetrics.adoc +29 -0
- package/docs/reference/types/Vector.adoc +28 -0
- package/docs/testing_best_practices.adoc +190 -0
- package/eslint.config.mjs +29 -0
- package/package.json +54 -0
- package/public/CNAME +1 -0
- package/public/docs/GAME_DEVELOPER_GUIDE.html +727 -0
- package/public/docs/brick-engine-guide.html +610 -0
- package/public/docs/diagrams/lifecycle.mmd +19 -0
- package/public/docs/documentation_style_guide.html +994 -0
- package/public/docs/getting-started.html +648 -0
- package/public/docs/images/lifecycle.svg +1 -0
- package/public/docs/index.html +593 -0
- package/public/docs/jsdoc_standard.html +656 -0
- package/public/docs/publishing.html +573 -0
- package/public/docs/reference/enums/Color.html +533 -0
- package/public/docs/reference/enums/ControlEventType.html +505 -0
- package/public/docs/reference/enums/ControlKey.html +529 -0
- package/public/docs/reference/enums/FontAlignment.html +545 -0
- package/public/docs/reference/enums/FontSize.html +517 -0
- package/public/docs/reference/enums/Sound.html +558 -0
- package/public/docs/reference/enums/StateProperty.html +525 -0
- package/public/docs/reference/helpers/CellHelper.html +520 -0
- package/public/docs/reference/helpers/ControlInputHandlerHelper.html +569 -0
- package/public/docs/reference/helpers/CoordinateHelper.html +703 -0
- package/public/docs/reference/helpers/RelativeValuesHelper.html +560 -0
- package/public/docs/reference/interfaces/Debuggable.html +501 -0
- package/public/docs/reference/interfaces/GameModules.html +544 -0
- package/public/docs/reference/interfaces/Initializable.html +495 -0
- package/public/docs/reference/interfaces/RendererInitializable.html +517 -0
- package/public/docs/reference/interfaces/StateSyncable.html +542 -0
- package/public/docs/reference/interfaces/modules/Control.html +648 -0
- package/public/docs/reference/interfaces/modules/Grid.html +1256 -0
- package/public/docs/reference/interfaces/modules/Renderer.html +522 -0
- package/public/docs/reference/interfaces/modules/RendererComposite.html +577 -0
- package/public/docs/reference/interfaces/modules/Score.html +669 -0
- package/public/docs/reference/interfaces/modules/Session.html +585 -0
- package/public/docs/reference/interfaces/modules/State.html +897 -0
- package/public/docs/reference/interfaces/modules/Text.html +668 -0
- package/public/docs/reference/interfaces/modules/Time.html +684 -0
- package/public/docs/reference/modules/Debugger.html +579 -0
- package/public/docs/reference/modules/DisplayRenderer.html +557 -0
- package/public/docs/reference/modules/Game.html +909 -0
- package/public/docs/reference/modules/GameControl.html +716 -0
- package/public/docs/reference/modules/GameGrid.html +1910 -0
- package/public/docs/reference/modules/GameHudGrid.html +508 -0
- package/public/docs/reference/modules/GameMenu.html +538 -0
- package/public/docs/reference/modules/GameRenderer.html +589 -0
- package/public/docs/reference/modules/GameScore.html +664 -0
- package/public/docs/reference/modules/GameSession.html +533 -0
- package/public/docs/reference/modules/GameSound.html +636 -0
- package/public/docs/reference/modules/GameState.html +922 -0
- package/public/docs/reference/modules/GameText.html +701 -0
- package/public/docs/reference/modules/GameTime.html +696 -0
- package/public/docs/reference/modules/HudRenderer.html +568 -0
- package/public/docs/reference/modules/InitialStateSnapshot.html +557 -0
- package/public/docs/reference/modules/SessionModal.html +520 -0
- package/public/docs/reference/types/Axis.html +505 -0
- package/public/docs/reference/types/Cell.html +514 -0
- package/public/docs/reference/types/ControlCallback.html +488 -0
- package/public/docs/reference/types/Coordinate.html +510 -0
- package/public/docs/reference/types/GameEntry.html +514 -0
- package/public/docs/reference/types/GameEvent.html +514 -0
- package/public/docs/reference/types/Piece.html +506 -0
- package/public/docs/reference/types/RendererMetrics.html +514 -0
- package/public/docs/reference/types/Vector.html +509 -0
- package/public/docs/testing_best_practices.html +770 -0
- package/public/favicon.ico +0 -0
- package/public/fonts/digital-7.monoitalic.ttf +0 -0
- package/public/images/cell.svg +32 -0
- package/public/images/close.png +0 -0
- package/public/images/games.png +0 -0
- package/public/images/github.png +0 -0
- package/public/images/letter-a.png +0 -0
- package/public/images/letter-d.png +0 -0
- package/public/images/letter-j.png +0 -0
- package/public/images/letter-s.png +0 -0
- package/public/images/letter-w.png +0 -0
- package/public/images/meta-image.png +0 -0
- package/public/images/number-1.png +0 -0
- package/public/images/number-2.png +0 -0
- package/public/images/number-3.png +0 -0
- package/public/images/number-4.png +0 -0
- package/public/images/number-5.png +0 -0
- package/public/images/number-6.png +0 -0
- package/public/images/splash.gif +0 -0
- package/public/index.html +15 -0
- package/public/sounds/sound_00.wav +0 -0
- package/public/sounds/sound_01.wav +0 -0
- package/public/sounds/sound_02.wav +0 -0
- package/public/sounds/sound_03.wav +0 -0
- package/public/sounds/sound_04.wav +0 -0
- package/public/sounds/sound_05.wav +0 -0
- package/public/sounds/sound_06.wav +0 -0
- package/public/sounds/sound_07.wav +0 -0
- package/public/sounds/sound_08.wav +0 -0
- package/public/sounds/sound_09.wav +0 -0
- package/public/sounds/sound_10.wav +0 -0
- package/public/sounds/sound_11.wav +0 -0
- package/public/sounds/sound_12.wav +0 -0
- package/public/sounds/sound_13.wav +0 -0
- package/public/sounds/sound_14.wav +0 -0
- package/public/sounds/sound_15.wav +0 -0
- package/public/style/body.css +86 -0
- package/public/style/buttons.css +233 -0
- package/public/style/debugger.css +117 -0
- package/public/style/sessionModal.css +155 -0
- package/public/style/sourceCodeAndCommands.css +74 -0
- package/public/style/splash.css +13 -0
- package/public/style/theme.css +137 -0
- package/scripts/generate-diagrams.sh +20 -0
- package/scripts/generate-docs.js +111 -0
- package/src/client-game.d.ts +1 -0
- package/src/config/configs.test.ts +20 -0
- package/src/config/configs.ts +197 -0
- package/src/config/env.test.ts +59 -0
- package/src/config/env.ts +7 -0
- package/src/config/styles.ts +5 -0
- package/src/core/Game.test.ts +167 -0
- package/src/core/Game.ts +307 -0
- package/src/core/InitialStateSnapshot.test.ts +51 -0
- package/src/core/InitialStateSnapshot.ts +46 -0
- package/src/core/helpers/CellHelper.test.ts +33 -0
- package/src/core/helpers/CellHelper.ts +21 -0
- package/src/core/helpers/ControlInputHandlerHelper.test.ts +116 -0
- package/src/core/helpers/ControlInputHandlerHelper.ts +68 -0
- package/src/core/helpers/CoordinateHelper.test.ts +113 -0
- package/src/core/helpers/CoordinateHelper.ts +82 -0
- package/src/core/helpers/InterfaceIdentifierHelper.test.ts +122 -0
- package/src/core/helpers/InterfaceIdentifierHelper.ts +43 -0
- package/src/core/helpers/RelativeValuesHelper.test.ts +47 -0
- package/src/core/helpers/RelativeValuesHelper.ts +29 -0
- package/src/core/module/control/GameControl.test.ts +82 -0
- package/src/core/module/control/GameControl.ts +142 -0
- package/src/core/module/control/GameControlKeyBinding.test.ts +59 -0
- package/src/core/module/control/GameControlKeyBinding.ts +92 -0
- package/src/core/module/grid/GameGrid.test.ts +83 -0
- package/src/core/module/grid/GameGrid.ts +610 -0
- package/src/core/module/grid/GameHudGrid.test.ts +22 -0
- package/src/core/module/grid/GameHudGrid.ts +40 -0
- package/src/core/module/grid/engines/GridAnalysisEngine.test.ts +157 -0
- package/src/core/module/grid/engines/GridAnalysisEngine.ts +124 -0
- package/src/core/module/grid/engines/GridLineEngine.test.ts +132 -0
- package/src/core/module/grid/engines/GridLineEngine.ts +165 -0
- package/src/core/module/grid/engines/GridMovementEngine.test.ts +125 -0
- package/src/core/module/grid/engines/GridMovementEngine.ts +113 -0
- package/src/core/module/grid/engines/GridRegionEngine.test.ts +136 -0
- package/src/core/module/grid/engines/GridRegionEngine.ts +52 -0
- package/src/core/module/grid/engines/GridTransformEngine.test.ts +98 -0
- package/src/core/module/grid/engines/GridTransformEngine.ts +70 -0
- package/src/core/module/renderer/DisplayRenderer.test.ts +86 -0
- package/src/core/module/renderer/DisplayRenderer.ts +152 -0
- package/src/core/module/renderer/GameRenderer.test.ts +103 -0
- package/src/core/module/renderer/GameRenderer.ts +144 -0
- package/src/core/module/renderer/HudRenderer.test.ts +108 -0
- package/src/core/module/renderer/HudRenderer.ts +203 -0
- package/src/core/module/score/GameScore.test.ts +71 -0
- package/src/core/module/score/GameScore.ts +188 -0
- package/src/core/module/session/GameSession.test.ts +176 -0
- package/src/core/module/session/GameSession.ts +103 -0
- package/src/core/module/sound/GameSound.test.ts +117 -0
- package/src/core/module/sound/GameSound.ts +229 -0
- package/src/core/module/state/GameState.test.ts +101 -0
- package/src/core/module/state/GameState.ts +339 -0
- package/src/core/module/text/GameText.test.ts +87 -0
- package/src/core/module/text/GameText.ts +150 -0
- package/src/core/module/time/GameTime.test.ts +86 -0
- package/src/core/module/time/GameTime.ts +144 -0
- package/src/core/types/Interfaces.ts +59 -0
- package/src/core/types/Types.ts +124 -0
- package/src/core/types/enums.ts +113 -0
- package/src/core/types/modules.ts +841 -0
- package/src/index.test.ts +15 -0
- package/src/index.ts +9 -0
- package/src/main.test.ts +137 -0
- package/src/main.ts +77 -0
- package/src/menu/GameMenu.test.ts +157 -0
- package/src/menu/GameMenu.ts +124 -0
- package/src/menu/GameMenuSingleton.test.ts +26 -0
- package/src/menu/GameMenuSingleton.ts +13 -0
- package/src/menu/GameRepository.test.ts +46 -0
- package/src/menu/GameRepository.ts +47 -0
- package/src/menu/manager/GameManager.test.ts +68 -0
- package/src/menu/manager/GameManager.ts +50 -0
- package/src/types/global.d.ts +8 -0
- package/src/types/interfaces.ts +5 -0
- package/src/view/Debugger.test.ts +152 -0
- package/src/view/Debugger.ts +124 -0
- package/src/view/GameView.test.ts +95 -0
- package/src/view/GameView.ts +244 -0
- package/src/view/SessionModal.test.ts +141 -0
- package/src/view/SessionModal.ts +73 -0
- package/src/view/components/layout/ButtonLayout.test.ts +28 -0
- package/src/view/components/layout/ButtonLayout.ts +63 -0
- package/src/view/components/layout/ContainerLayout.test.ts +48 -0
- package/src/view/components/layout/ContainerLayout.ts +50 -0
- package/src/view/components/layout/FrameLayout.test.ts +24 -0
- package/src/view/components/layout/FrameLayout.ts +25 -0
- package/src/view/components/ui/BigButton.test.ts +28 -0
- package/src/view/components/ui/BigButton.ts +31 -0
- package/src/view/components/ui/Button.test.ts +30 -0
- package/src/view/components/ui/Button.ts +30 -0
- package/src/view/components/ui/Canvas.test.ts +32 -0
- package/src/view/components/ui/Canvas.ts +34 -0
- package/src/view/components/ui/SmallButton.test.ts +48 -0
- package/src/view/components/ui/SmallButton.ts +32 -0
- package/src/view/theme/applyColors.test.ts +47 -0
- package/src/view/theme/applyColors.ts +38 -0
- package/src/view/theme/dimensions.test.ts +34 -0
- package/src/view/theme/dimensions.ts +53 -0
- package/tsconfig.json +16 -0
- package/vitest.config.ts +14 -0
- package/webpack.config.js +133 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { Debuggable } from '../../types/Interfaces';
|
|
2
|
+
import { State } from '../../types/modules';
|
|
3
|
+
import { StateProperty } from '../../types/Types';
|
|
4
|
+
|
|
5
|
+
type StateMetadata = {
|
|
6
|
+
defaultValue: boolean | number;
|
|
7
|
+
storageKey?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// prettier-ignore
|
|
11
|
+
const STATE_CONFIG: Record<StateProperty, StateMetadata> = {
|
|
12
|
+
[StateProperty.ON] : { defaultValue: false },
|
|
13
|
+
[StateProperty.START] : { defaultValue: false },
|
|
14
|
+
[StateProperty.PLAYING] : { defaultValue: false },
|
|
15
|
+
[StateProperty.GAME_OVER] : { defaultValue: false },
|
|
16
|
+
[StateProperty.COLOR_ENABLED] : { defaultValue: true , storageKey: 'colorEnabled' },
|
|
17
|
+
[StateProperty.MUTED] : { defaultValue: false , storageKey: 'muted' },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Manages the core boolean states of the game and handles state-change events.
|
|
22
|
+
*
|
|
23
|
+
* Provides a central hub for tracking game lifecycle states (on, running, gameOver)
|
|
24
|
+
* and user preferences (color enabled).
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* **Persistence Responsibility:**
|
|
28
|
+
* This class is the SOLE responsible for persisting and loading generic, cross-session
|
|
29
|
+
* player preferences (like mute settings and color toggle) from LocalStorage.
|
|
30
|
+
* It does NOT handle transient session data (GameSession) or specific scoring logic (GameScore).
|
|
31
|
+
*/
|
|
32
|
+
export default class GameState implements State, Debuggable {
|
|
33
|
+
private _state: Map<StateProperty, boolean | number> = new Map();
|
|
34
|
+
|
|
35
|
+
/** Map to store property names and their associated subscription callbacks. */
|
|
36
|
+
|
|
37
|
+
private _subscribers: Map<StateProperty, Array<(value: boolean | number) => void>> = new Map();
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Initializes the state module.
|
|
41
|
+
* Sets default values for all state properties and loads persisted data.
|
|
42
|
+
*/
|
|
43
|
+
setup(): void {
|
|
44
|
+
// Initialize default values
|
|
45
|
+
Object.values(StateProperty).forEach(property => {
|
|
46
|
+
const config = STATE_CONFIG[property];
|
|
47
|
+
this._state.set(property, config.defaultValue);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
this._loadPersistentState();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Loads persistent state from LocalStorage.
|
|
55
|
+
*/
|
|
56
|
+
private _loadPersistentState(): void {
|
|
57
|
+
Object.values(StateProperty).forEach(property => {
|
|
58
|
+
const config = STATE_CONFIG[property];
|
|
59
|
+
if (config.storageKey) {
|
|
60
|
+
const storedValue = localStorage.getItem(config.storageKey);
|
|
61
|
+
if (storedValue !== null) {
|
|
62
|
+
this._state.set(property, JSON.parse(storedValue));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Sets a state property value, handling persistence and notification.
|
|
70
|
+
*
|
|
71
|
+
* @param {StateProperty} property - The property to set.
|
|
72
|
+
* @param {boolean | number} value - The value to set.
|
|
73
|
+
*/
|
|
74
|
+
private _set(property: StateProperty, value: boolean | number): void {
|
|
75
|
+
const currentValue = this._state.get(property);
|
|
76
|
+
if (currentValue !== value) {
|
|
77
|
+
this._state.set(property, value);
|
|
78
|
+
|
|
79
|
+
const config = STATE_CONFIG[property];
|
|
80
|
+
if (config.storageKey) {
|
|
81
|
+
localStorage.setItem(config.storageKey, JSON.stringify(value));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
this._notify(property, value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Notifies all subscribers of a property change.
|
|
90
|
+
*
|
|
91
|
+
* @param {StateProperty} property - The property that changed.
|
|
92
|
+
* @param {boolean | number} value - The new value of the property.
|
|
93
|
+
*/
|
|
94
|
+
private _notify(property: StateProperty, value: boolean | number): void {
|
|
95
|
+
const callbacks = this._subscribers.get(property);
|
|
96
|
+
if (callbacks) {
|
|
97
|
+
callbacks.forEach(callback => callback(value));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Checks if the game machine is powered on.
|
|
103
|
+
*
|
|
104
|
+
* @returns {boolean} True if powered on.
|
|
105
|
+
*/
|
|
106
|
+
isOn(): boolean {
|
|
107
|
+
return this._state.get(StateProperty.ON) as boolean;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Checks if the game machine is powered off.
|
|
112
|
+
*
|
|
113
|
+
* @returns {boolean} True if powered off.
|
|
114
|
+
*/
|
|
115
|
+
isOff(): boolean {
|
|
116
|
+
return !this.isOn();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Checks if a game session has currently started.
|
|
121
|
+
* This includes both playing and paused states.
|
|
122
|
+
*
|
|
123
|
+
* @returns {boolean} True if a game is active.
|
|
124
|
+
*/
|
|
125
|
+
isStarted(): boolean {
|
|
126
|
+
return this._state.get(StateProperty.START) as boolean;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Checks if the game is currently running (not paused, not game over).
|
|
131
|
+
*
|
|
132
|
+
* @returns {boolean} True if gameplay is active.
|
|
133
|
+
*/
|
|
134
|
+
isPlaying(): boolean {
|
|
135
|
+
return this._state.get(StateProperty.PLAYING) as boolean;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Checks if the game is paused.
|
|
140
|
+
*
|
|
141
|
+
* @returns {boolean} True if the game is started but not playing (and not game over).
|
|
142
|
+
*/
|
|
143
|
+
isPaused(): boolean {
|
|
144
|
+
return this.isStarted() && !this.isPlaying() && !this.isGameOver();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Checks if the game is in a "Game Over" state.
|
|
149
|
+
*
|
|
150
|
+
* @returns {boolean} True if the game is over.
|
|
151
|
+
*/
|
|
152
|
+
isGameOver(): boolean {
|
|
153
|
+
return this._state.get(StateProperty.GAME_OVER) as boolean;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Powers on the game machine.
|
|
158
|
+
* Resets all session states (start, playing, game over).
|
|
159
|
+
*/
|
|
160
|
+
turnOn(): void {
|
|
161
|
+
this._set(StateProperty.ON, true);
|
|
162
|
+
this._set(StateProperty.START, false);
|
|
163
|
+
this._set(StateProperty.PLAYING, false);
|
|
164
|
+
this._set(StateProperty.GAME_OVER, false);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Powers off the game machine.
|
|
169
|
+
* Resets all states.
|
|
170
|
+
*/
|
|
171
|
+
turnOff(): void {
|
|
172
|
+
this._set(StateProperty.ON, false);
|
|
173
|
+
this._set(StateProperty.START, false);
|
|
174
|
+
this._set(StateProperty.PLAYING, false);
|
|
175
|
+
this._set(StateProperty.GAME_OVER, false);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Starts a new game session.
|
|
180
|
+
* Only works if the machine is powered on.
|
|
181
|
+
*/
|
|
182
|
+
startGame(): void {
|
|
183
|
+
if (!this.isOn()) return;
|
|
184
|
+
this._set(StateProperty.START, true);
|
|
185
|
+
this._set(StateProperty.PLAYING, true);
|
|
186
|
+
this._set(StateProperty.GAME_OVER, false);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Resets the game over state and starts the game again.
|
|
191
|
+
*/
|
|
192
|
+
resetGameOver(): void {
|
|
193
|
+
this._set(StateProperty.GAME_OVER, false);
|
|
194
|
+
this._set(StateProperty.START, true);
|
|
195
|
+
this._set(StateProperty.PLAYING, true);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Exits the current game session, returning to the "On" state.
|
|
200
|
+
*/
|
|
201
|
+
exitGame(): void {
|
|
202
|
+
this._set(StateProperty.START, false);
|
|
203
|
+
this._set(StateProperty.PLAYING, false);
|
|
204
|
+
this._set(StateProperty.GAME_OVER, false);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Pauses the current game.
|
|
209
|
+
*/
|
|
210
|
+
pause(): void {
|
|
211
|
+
if (this.isStarted() && !this.isGameOver()) {
|
|
212
|
+
this._set(StateProperty.PLAYING, false);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Resumes the game from a paused state.
|
|
218
|
+
*/
|
|
219
|
+
resume(): void {
|
|
220
|
+
if (this.isStarted() && !this.isGameOver()) {
|
|
221
|
+
this._set(StateProperty.PLAYING, true);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Triggers the "Game Over" state.
|
|
227
|
+
* Stops gameplay.
|
|
228
|
+
*/
|
|
229
|
+
triggerGameOver(): void {
|
|
230
|
+
this._set(StateProperty.PLAYING, false);
|
|
231
|
+
this._set(StateProperty.GAME_OVER, true);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Resets the game to the initial state (restarts).
|
|
236
|
+
*/
|
|
237
|
+
resetGame(): void {
|
|
238
|
+
if (!this.isOn()) return;
|
|
239
|
+
this._set(StateProperty.GAME_OVER, false);
|
|
240
|
+
this._set(StateProperty.START, true);
|
|
241
|
+
this._set(StateProperty.PLAYING, true);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Checks if color mode is enabled.
|
|
246
|
+
*
|
|
247
|
+
* @returns {boolean} True if color is enabled.
|
|
248
|
+
*/
|
|
249
|
+
isColorEnabled(): boolean {
|
|
250
|
+
return this._state.get(StateProperty.COLOR_ENABLED) as boolean;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Enables or disables color mode.
|
|
255
|
+
*
|
|
256
|
+
* @param {boolean} value - True to enable, false to disable.
|
|
257
|
+
*/
|
|
258
|
+
setColorEnabled(value: boolean): void {
|
|
259
|
+
this._set(StateProperty.COLOR_ENABLED, value);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Checks if audio is muted.
|
|
264
|
+
*
|
|
265
|
+
* @returns {boolean} True if muted.
|
|
266
|
+
*/
|
|
267
|
+
isMuted(): boolean {
|
|
268
|
+
return this._state.get(StateProperty.MUTED) as boolean;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Mutes or unmutes the audio.
|
|
273
|
+
*
|
|
274
|
+
* @param {boolean} value - True to mute, false to unmute.
|
|
275
|
+
*/
|
|
276
|
+
setMuted(value: boolean): void {
|
|
277
|
+
this._set(StateProperty.MUTED, value);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Toggles the color enabled state.
|
|
282
|
+
*/
|
|
283
|
+
toggleColorEnabled(): void {
|
|
284
|
+
this.setColorEnabled(!this.isColorEnabled());
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Toggles the muted state.
|
|
289
|
+
*/
|
|
290
|
+
toggleMuted(): void {
|
|
291
|
+
this.setMuted(!this.isMuted());
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Subscribes to changes in specific state properties.
|
|
296
|
+
*
|
|
297
|
+
* @param {StateProperty} property - The state property to monitor.
|
|
298
|
+
* @param {function(boolean | number): void} callback - The function to execute when the property changes.
|
|
299
|
+
*/
|
|
300
|
+
subscribe(property: StateProperty, callback: (value: boolean | number) => void): void {
|
|
301
|
+
if (!this._subscribers.has(property)) {
|
|
302
|
+
this._subscribers.set(property, []);
|
|
303
|
+
}
|
|
304
|
+
this._subscribers.get(property)?.push(callback);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Unsubscribes from changes in specific state properties.
|
|
309
|
+
*
|
|
310
|
+
* @param {StateProperty} property - The state property to monitor.
|
|
311
|
+
* @param {function(boolean | number): void} callback - The function to remove.
|
|
312
|
+
*/
|
|
313
|
+
unsubscribe(property: StateProperty, callback: (value: boolean | number) => void): void {
|
|
314
|
+
const callbacks = this._subscribers.get(property);
|
|
315
|
+
if (callbacks) {
|
|
316
|
+
this._subscribers.set(
|
|
317
|
+
property,
|
|
318
|
+
callbacks.filter(cb => cb !== callback),
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Retrieves debug information about the game state.
|
|
325
|
+
*
|
|
326
|
+
* @returns {Record<string, string | number | boolean>} The debug data.
|
|
327
|
+
*/
|
|
328
|
+
getDebugData(): Record<string, string | number | boolean> {
|
|
329
|
+
return {
|
|
330
|
+
on: this.isOn(),
|
|
331
|
+
start: this.isStarted(),
|
|
332
|
+
playing: this.isPlaying(),
|
|
333
|
+
paused: this.isPaused(),
|
|
334
|
+
game_over: this.isGameOver(),
|
|
335
|
+
color_enabled: this.isColorEnabled(),
|
|
336
|
+
muted: this.isMuted(),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import GameText from './GameText';
|
|
3
|
+
import p5 from 'p5';
|
|
4
|
+
import { FontSize, FontAlign, FontVerticalAlign } from '../../types/enums';
|
|
5
|
+
import CoordinateHelper from '../../helpers/CoordinateHelper';
|
|
6
|
+
|
|
7
|
+
// [ARRANGE] Mock CoordinateHelper
|
|
8
|
+
vi.mock('../../helpers/CoordinateHelper', () => ({
|
|
9
|
+
default: {
|
|
10
|
+
getHudPosX: vi.fn().mockReturnValue(10),
|
|
11
|
+
getHudPosY: vi.fn().mockReturnValue(20),
|
|
12
|
+
getDisplayPosX: vi.fn().mockReturnValue(30),
|
|
13
|
+
getDisplayPosY: vi.fn().mockReturnValue(40),
|
|
14
|
+
},
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
describe('GameText', () => {
|
|
18
|
+
let gameText: GameText;
|
|
19
|
+
let mockP5: p5;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
mockP5 = {
|
|
23
|
+
textFont: vi.fn(),
|
|
24
|
+
fill: vi.fn(),
|
|
25
|
+
textSize: vi.fn(),
|
|
26
|
+
textAlign: vi.fn(),
|
|
27
|
+
text: vi.fn(),
|
|
28
|
+
width: 1000,
|
|
29
|
+
height: 1000,
|
|
30
|
+
} as unknown as p5;
|
|
31
|
+
|
|
32
|
+
gameText = new GameText(mockP5);
|
|
33
|
+
gameText.setRendererMetrics({
|
|
34
|
+
display: { width: 600, height: 900, origin: { x: 0, y: 0 } },
|
|
35
|
+
hud: { width: 400, height: 900, origin: { x: 600, y: 0 } },
|
|
36
|
+
cell: { size: 50 },
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('setup', () => {
|
|
41
|
+
it('should set font and calculate font sizes', () => {
|
|
42
|
+
// [ACT]
|
|
43
|
+
gameText.setup();
|
|
44
|
+
|
|
45
|
+
// [ASSERT]
|
|
46
|
+
expect(mockP5.textFont).toHaveBeenCalledWith('retro-gamming');
|
|
47
|
+
// Check if some sizes were set (e.g. textSize(FontSize.MEDIUM))
|
|
48
|
+
gameText.setTextSize(FontSize.MEDIUM);
|
|
49
|
+
expect(mockP5.textSize).toHaveBeenCalled();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('Rendering positions', () => {
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
gameText.setup();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should call CoordinateHelper.getHudPos and p5.text for HUD text', () => {
|
|
59
|
+
// [ACT]
|
|
60
|
+
gameText.textOnHud('Hello', { x: 0.5, y: 0.5 });
|
|
61
|
+
|
|
62
|
+
// [ASSERT]
|
|
63
|
+
expect(CoordinateHelper.getHudPosX).toHaveBeenCalled();
|
|
64
|
+
expect(mockP5.text).toHaveBeenCalledWith('Hello', 10, 20);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should call CoordinateHelper.getDisplayPos and p5.text for Display text', () => {
|
|
68
|
+
// [ACT]
|
|
69
|
+
gameText.textOnDisplay('Score', { x: 0.1, y: 0.1 });
|
|
70
|
+
|
|
71
|
+
// [ASSERT]
|
|
72
|
+
expect(CoordinateHelper.getDisplayPosX).toHaveBeenCalled();
|
|
73
|
+
expect(mockP5.text).toHaveBeenCalledWith('Score', 30, 40);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('Alignment & Sizing', () => {
|
|
78
|
+
it('should delegate to p5.textAlign and p5.textSize', () => {
|
|
79
|
+
// [ACT]
|
|
80
|
+
gameText.setTextAlign(FontAlign.CENTER, FontVerticalAlign.CENTER);
|
|
81
|
+
gameText.setTextSize(FontSize.LARGE);
|
|
82
|
+
|
|
83
|
+
// [ASSERT]
|
|
84
|
+
expect(mockP5.textAlign).toHaveBeenCalledWith(FontAlign.CENTER, FontVerticalAlign.CENTER);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import p5 from 'p5';
|
|
2
|
+
import configs from '../../../config/configs';
|
|
3
|
+
import { FontSize, FontAlign, FontVerticalAlign } from '../../types/enums';
|
|
4
|
+
import { Coordinate, RendererMetrics } from '../../types/Types';
|
|
5
|
+
import { Debuggable } from '../../types/Interfaces';
|
|
6
|
+
import CoordinateHelper from '../../helpers/CoordinateHelper';
|
|
7
|
+
import RelativeValuesHelper from '../../helpers/RelativeValuesHelper';
|
|
8
|
+
import { Text } from '../../types/modules';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Handles text rendering and font management within the game.
|
|
12
|
+
*
|
|
13
|
+
* This class orchestrates font initialization, sizing, alignment, and
|
|
14
|
+
* provides methods to render text on specific areas (HUD or Display).
|
|
15
|
+
*/
|
|
16
|
+
export default class GameText implements Text, Debuggable {
|
|
17
|
+
/** The default font family used for game text. */
|
|
18
|
+
protected defaultFontFamily: string = 'retro-gamming';
|
|
19
|
+
|
|
20
|
+
/** Array containing pre-calculated font sizes in pixels. */
|
|
21
|
+
private fontSizes: number[] = [0];
|
|
22
|
+
|
|
23
|
+
/** Stores the current display metrics for relative positioning. */
|
|
24
|
+
private _rendererMetrics: RendererMetrics;
|
|
25
|
+
|
|
26
|
+
/** The p5 instance used for rendering. */
|
|
27
|
+
private _p: p5;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of GameText.
|
|
31
|
+
*
|
|
32
|
+
* @param {p5} p - The p5 instance.
|
|
33
|
+
*/
|
|
34
|
+
constructor(p: p5) {
|
|
35
|
+
this._p = p;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// prettier-ignore
|
|
39
|
+
/**
|
|
40
|
+
* Setup the font and pre-calculates relative font sizes.
|
|
41
|
+
*
|
|
42
|
+
* Uses configuration values to define a set of pixel-perfect font sizes
|
|
43
|
+
* based on current container width.
|
|
44
|
+
*/
|
|
45
|
+
setup(): void {
|
|
46
|
+
const { extraSmall, small, medium, large, extraLarge } = configs.screenLayout.fontSize;
|
|
47
|
+
|
|
48
|
+
this._p.textFont(this.defaultFontFamily);
|
|
49
|
+
|
|
50
|
+
// Define font sizes
|
|
51
|
+
this.fontSizes = [];
|
|
52
|
+
|
|
53
|
+
this.fontSizes[FontSize.EXTRA_SMALL] = RelativeValuesHelper.getRelativeWidth(this._p, extraSmall);
|
|
54
|
+
this.fontSizes[FontSize.SMALL] = RelativeValuesHelper.getRelativeWidth(this._p, small);
|
|
55
|
+
this.fontSizes[FontSize.MEDIUM] = RelativeValuesHelper.getRelativeWidth(this._p, medium);
|
|
56
|
+
this.fontSizes[FontSize.LARGE] = RelativeValuesHelper.getRelativeWidth(this._p, large);
|
|
57
|
+
this.fontSizes[FontSize.EXTRA_LARGE] = RelativeValuesHelper.getRelativeWidth(this._p, extraLarge);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Sets the display metrics used for relative text positioning.
|
|
62
|
+
*
|
|
63
|
+
* @param {RendererMetrics} rendererMetrics - The current renderer dimensions and origin.
|
|
64
|
+
*/
|
|
65
|
+
setRendererMetrics(rendererMetrics: RendererMetrics): void {
|
|
66
|
+
this._rendererMetrics = rendererMetrics;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Sets the fill color of the text based on its state.
|
|
71
|
+
*
|
|
72
|
+
* @param {boolean} state - Whether the text should use the active or inactive color.
|
|
73
|
+
*/
|
|
74
|
+
protected setTextState(state: boolean): void {
|
|
75
|
+
const { active, inactive } = configs.colors;
|
|
76
|
+
this._p.fill(state ? active : inactive);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Sets the text color to the active theme color.
|
|
81
|
+
*/
|
|
82
|
+
setActiveText(): void {
|
|
83
|
+
this.setTextState(true);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Sets the text color to the inactive theme color.
|
|
88
|
+
*/
|
|
89
|
+
setInactiveText(): void {
|
|
90
|
+
this.setTextState(false);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Sets the current font size from predefined values.
|
|
95
|
+
*
|
|
96
|
+
* @param {FontSize} fontSize - The enum value representing the desired size.
|
|
97
|
+
*/
|
|
98
|
+
setTextSize(fontSize: FontSize): void {
|
|
99
|
+
this._p.textSize(this.fontSizes[fontSize]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Configures horizontal and vertical text alignment.
|
|
104
|
+
*
|
|
105
|
+
* @param {FontAlign} fontAlign - Horizontal alignment value.
|
|
106
|
+
* @param {FontVerticalAlign} fontVerticalAlign - Vertical alignment value.
|
|
107
|
+
*/
|
|
108
|
+
setTextAlign(fontAlign: FontAlign, fontVerticalAlign: FontVerticalAlign): void {
|
|
109
|
+
this._p.textAlign(fontAlign, fontVerticalAlign);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Renders text on the HUD area using relative coordinates.
|
|
114
|
+
*
|
|
115
|
+
* @param {string} text - The string to be rendered.
|
|
116
|
+
* @param {Coordinate} coordinate - Normalized coordinates (0 to 1) within the HUD area.
|
|
117
|
+
*/
|
|
118
|
+
textOnHud(text: string, coordinate: Coordinate): void {
|
|
119
|
+
const x = CoordinateHelper.getHudPosX(this._p, coordinate.x, this._rendererMetrics.display.width);
|
|
120
|
+
const y = CoordinateHelper.getHudPosY(this._p, coordinate.y, this._rendererMetrics.display.height);
|
|
121
|
+
|
|
122
|
+
this._p.text(text, x, y);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Renders text on the main display area using relative coordinates.
|
|
127
|
+
*
|
|
128
|
+
* @param {string} text - The string to be rendered.
|
|
129
|
+
* @param {Coordinate} coordinate - Normalized coordinates (0 to 1) within the display area.
|
|
130
|
+
*/
|
|
131
|
+
textOnDisplay(text: string, coordinate: Coordinate): void {
|
|
132
|
+
// Fixed argument order: (p, x, displayWidth)
|
|
133
|
+
const x = CoordinateHelper.getDisplayPosX(this._p, coordinate.x, this._rendererMetrics.display.width);
|
|
134
|
+
const y = CoordinateHelper.getDisplayPosY(this._p, coordinate.y, this._rendererMetrics.display.height);
|
|
135
|
+
|
|
136
|
+
this._p.text(text, x, y);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Retrieves debug information about the text system.
|
|
141
|
+
*
|
|
142
|
+
* @returns {Record<string, string | number | boolean>} The debug data.
|
|
143
|
+
*/
|
|
144
|
+
getDebugData(): Record<string, string | number | boolean> {
|
|
145
|
+
return {
|
|
146
|
+
current_font_family: this.defaultFontFamily,
|
|
147
|
+
font_sizes_count: this.fontSizes.length,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import GameTime from './GameTime';
|
|
3
|
+
|
|
4
|
+
describe('GameTime', () => {
|
|
5
|
+
let gameTime: GameTime;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
gameTime = new GameTime();
|
|
9
|
+
gameTime.setup();
|
|
10
|
+
gameTime.setTickInterval(100);
|
|
11
|
+
gameTime.setMinTickInterval(10);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe('update & shouldTick', () => {
|
|
15
|
+
it('should accumulate time and trigger tick when interval is reached', () => {
|
|
16
|
+
// [ACT]
|
|
17
|
+
gameTime.update(50);
|
|
18
|
+
const firstCheck = gameTime.shouldTick();
|
|
19
|
+
|
|
20
|
+
gameTime.update(50);
|
|
21
|
+
const secondCheck = gameTime.shouldTick();
|
|
22
|
+
|
|
23
|
+
// [ASSERT]
|
|
24
|
+
expect(firstCheck).toBe(false);
|
|
25
|
+
expect(secondCheck).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should handle multiple ticks in one large update', () => {
|
|
29
|
+
// [ACT]
|
|
30
|
+
gameTime.update(250);
|
|
31
|
+
|
|
32
|
+
const tick1 = gameTime.shouldTick(); // consumes 100, rem 150
|
|
33
|
+
const tick2 = gameTime.shouldTick(); // consumes 100, rem 50
|
|
34
|
+
const tick3 = gameTime.shouldTick();
|
|
35
|
+
|
|
36
|
+
// [ASSERT]
|
|
37
|
+
expect(tick1).toBe(true);
|
|
38
|
+
expect(tick2).toBe(true);
|
|
39
|
+
expect(tick3).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('FPS & TPS calculation', () => {
|
|
44
|
+
it('should calculate FPS correctly', () => {
|
|
45
|
+
// [ACT]
|
|
46
|
+
gameTime.update(16.666); // roughly 60fps
|
|
47
|
+
|
|
48
|
+
// [ASSERT]
|
|
49
|
+
const debug = gameTime.getDebugData();
|
|
50
|
+
expect(debug.fps).toBe(60);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should update TPS every 1000ms', () => {
|
|
54
|
+
// [ARRANGE] Trigger 5 ticks
|
|
55
|
+
for (let i = 0; i < 5; i++) {
|
|
56
|
+
gameTime.update(100);
|
|
57
|
+
gameTime.shouldTick();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// [ACT]
|
|
61
|
+
gameTime.update(500); // 5*100 + 500 = 1000ms elapsed
|
|
62
|
+
|
|
63
|
+
// [ASSERT]
|
|
64
|
+
const debug = gameTime.getDebugData();
|
|
65
|
+
expect(debug.tps).toBe(5);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('Interval management', () => {
|
|
70
|
+
it('should decrement interval but stay above minimum', () => {
|
|
71
|
+
// [ACT]
|
|
72
|
+
gameTime.decrementTickInterval(200);
|
|
73
|
+
|
|
74
|
+
// [ASSERT]
|
|
75
|
+
expect(gameTime.tickInterval).toBe(10);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should increment interval', () => {
|
|
79
|
+
// [ACT]
|
|
80
|
+
gameTime.incrementTickInterval(50);
|
|
81
|
+
|
|
82
|
+
// [ASSERT]
|
|
83
|
+
expect(gameTime.tickInterval).toBe(150);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|