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,203 @@
|
|
|
1
|
+
import { Renderer } from '../../types/modules';
|
|
2
|
+
import { Cell, Coordinate, GameModules, RendererMetrics } from '../../types/Types';
|
|
3
|
+
import p5 from 'p5';
|
|
4
|
+
import { Color, FontAlign, FontSize, FontVerticalAlign } from '../../types/enums';
|
|
5
|
+
import CoordinateHelper from '../../helpers/CoordinateHelper';
|
|
6
|
+
import configs from '../../../config/configs';
|
|
7
|
+
import RelativeValuesHelper from '../../helpers/RelativeValuesHelper';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Responsible for rendering the Heads-Up Display (HUD).
|
|
11
|
+
* Displays game information like Score, High Score, Level, and the Next Piece Preview.
|
|
12
|
+
*/
|
|
13
|
+
export default class HudRenderer implements Renderer {
|
|
14
|
+
private _p: p5;
|
|
15
|
+
|
|
16
|
+
private _gridOrigin: Coordinate;
|
|
17
|
+
|
|
18
|
+
private _cellSize: number;
|
|
19
|
+
|
|
20
|
+
private _hudBorderRect: {
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
w: number;
|
|
24
|
+
h: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates an instance of HudRenderer.
|
|
29
|
+
*
|
|
30
|
+
* @param {p5} p - The p5 instance.
|
|
31
|
+
*/
|
|
32
|
+
constructor(p: p5) {
|
|
33
|
+
this._p = p;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Initializes the HUD with calculated metrics.
|
|
38
|
+
* Sets up the grid origin and border rectangle for the "next piece" preview area.
|
|
39
|
+
*
|
|
40
|
+
* @param {RendererMetrics} rendererMetrics - The shared renderer metrics.
|
|
41
|
+
*/
|
|
42
|
+
setup(rendererMetrics: RendererMetrics): void {
|
|
43
|
+
this._cellSize = rendererMetrics.cell.size;
|
|
44
|
+
this._gridOrigin = {
|
|
45
|
+
x: CoordinateHelper.getHudPosX(this._p, 0.078, rendererMetrics.display.width),
|
|
46
|
+
y: CoordinateHelper.getHudPosY(this._p, 0.375, rendererMetrics.display.height),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
this._hudBorderRect = {
|
|
50
|
+
x: this._gridOrigin.x - RelativeValuesHelper.getRelativeWidth(this._p, 0.005),
|
|
51
|
+
y: this._gridOrigin.y - RelativeValuesHelper.getRelativeHeight(this._p, 0.005),
|
|
52
|
+
w: this._cellSize * 4 + RelativeValuesHelper.getRelativeWidth(this._p, 0.01),
|
|
53
|
+
h: this._cellSize * 4 + RelativeValuesHelper.getRelativeHeight(this._p, 0.01),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Renders all HUD elements.
|
|
59
|
+
*
|
|
60
|
+
* @param {Cell[][]} grid - The main game grid (unused in HUD, but required by interface).
|
|
61
|
+
* @param {GameModules} modules - The game modules for retrieving state and score.
|
|
62
|
+
*/
|
|
63
|
+
render(grid: Cell[][], modules: GameModules): void {
|
|
64
|
+
this._renderHud(modules);
|
|
65
|
+
this._drawHudGrid(modules);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Renders the text-based HUD elements (Score, Level, Status).
|
|
70
|
+
*
|
|
71
|
+
* @param {GameModules} modules - The game modules.
|
|
72
|
+
*/
|
|
73
|
+
private _renderHud(modules: GameModules): void {
|
|
74
|
+
const { text, state, score } = modules;
|
|
75
|
+
|
|
76
|
+
this._p.push();
|
|
77
|
+
|
|
78
|
+
text.setTextSize(FontSize.SMALL);
|
|
79
|
+
text.setInactiveText();
|
|
80
|
+
text.setTextAlign(FontAlign.LEFT, FontVerticalAlign.BOTTOM);
|
|
81
|
+
|
|
82
|
+
//Placeholders text
|
|
83
|
+
text.textOnHud('88888888', { x: 0.05, y: 0.13 });
|
|
84
|
+
text.textOnHud('88888888', { x: 0.05, y: 0.3 });
|
|
85
|
+
text.textOnHud('88 - 88', { x: 0.05, y: 0.8 });
|
|
86
|
+
|
|
87
|
+
if (state.isOn()) {
|
|
88
|
+
text.setActiveText();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
//Score text
|
|
92
|
+
text.textOnHud('Score', { x: 0.05, y: 0.06 });
|
|
93
|
+
text.textOnHud(score.score.toString(), { x: 0.05, y: 0.13 });
|
|
94
|
+
|
|
95
|
+
//Hi-Score text
|
|
96
|
+
text.textOnHud('Hi-Score', { x: 0.05, y: 0.23 });
|
|
97
|
+
text.textOnHud(score.highScore.toString(), { x: 0.05, y: 0.3 });
|
|
98
|
+
|
|
99
|
+
//Level text
|
|
100
|
+
text.textOnHud('Level', { x: 0.05, y: 0.72 });
|
|
101
|
+
const levelValue = `${score.level < 10 ? '0' + score.level : score.level} - ${score.maxLevel}`;
|
|
102
|
+
text.textOnHud(levelValue, { x: 0.05, y: 0.8 });
|
|
103
|
+
|
|
104
|
+
text.setTextAlign(FontAlign.CENTER, FontVerticalAlign.BOTTOM);
|
|
105
|
+
|
|
106
|
+
//Paused text
|
|
107
|
+
if (state.isPaused()) {
|
|
108
|
+
text.setActiveText();
|
|
109
|
+
} else {
|
|
110
|
+
text.setInactiveText();
|
|
111
|
+
}
|
|
112
|
+
text.textOnHud('Paused', { x: 0.5, y: 0.9 });
|
|
113
|
+
|
|
114
|
+
//Muted text
|
|
115
|
+
if (state.isOn() && state.isMuted()) {
|
|
116
|
+
text.setActiveText();
|
|
117
|
+
} else {
|
|
118
|
+
text.setInactiveText();
|
|
119
|
+
}
|
|
120
|
+
text.textOnHud('Muted', { x: 0.5, y: 0.97 });
|
|
121
|
+
|
|
122
|
+
this._p.pop();
|
|
123
|
+
|
|
124
|
+
this._drawHudGrid(modules);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Renders the preview grid for the next piece.
|
|
129
|
+
*
|
|
130
|
+
* @param {GameModules} modules - The game modules.
|
|
131
|
+
*/
|
|
132
|
+
private _drawHudGrid(modules: GameModules): void {
|
|
133
|
+
const { hudGrid, state } = modules;
|
|
134
|
+
|
|
135
|
+
this._p.push();
|
|
136
|
+
|
|
137
|
+
hudGrid.forEach(cell => {
|
|
138
|
+
const { x, y } = cell.coordinate;
|
|
139
|
+
|
|
140
|
+
if (state.isOff() && !state.isPlaying()) {
|
|
141
|
+
cell.value = 0;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let color = cell.value !== 0 ? Color.DEFAULT : Color.INACTIVE;
|
|
145
|
+
|
|
146
|
+
if (state.isColorEnabled() && cell.value !== 0) {
|
|
147
|
+
color = cell.color;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
this.drawCellElement({
|
|
151
|
+
w: this._cellSize,
|
|
152
|
+
h: this._cellSize,
|
|
153
|
+
posX: this._gridOrigin.x + this._cellSize * x,
|
|
154
|
+
posY: this._gridOrigin.y + this._cellSize * y,
|
|
155
|
+
color,
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
this._p.noFill();
|
|
160
|
+
this._p.stroke(state.isOn() ? Color.DEFAULT : Color.INACTIVE);
|
|
161
|
+
|
|
162
|
+
this._p.rect(this._hudBorderRect.x, this._hudBorderRect.y, this._hudBorderRect.w, this._hudBorderRect.h);
|
|
163
|
+
|
|
164
|
+
this._p.pop();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Helper method to draw a single cell on the HUD.
|
|
169
|
+
* Identical in logic to DisplayRenderer's cell drawing but localized for HUD.
|
|
170
|
+
*
|
|
171
|
+
* @param {object} params - The drawing parameters.
|
|
172
|
+
* @param {number} params.w - Width of the cell.
|
|
173
|
+
* @param {number} params.posX - Absolute X position.
|
|
174
|
+
* @param {number} params.posY - Absolute Y position.
|
|
175
|
+
* @param {Color} params.color - Color of the cell.
|
|
176
|
+
*/
|
|
177
|
+
private drawCellElement({ w, posX, posY, color }: { w: number; h: number; posX: number; posY: number; color: Color }): void {
|
|
178
|
+
const { margin: cellMargin, padding: cellPadding, strokeWeight: cellStrokeWeight } = configs.screenLayout.cell;
|
|
179
|
+
|
|
180
|
+
const innerOffset = cellMargin * w;
|
|
181
|
+
const innerSize = w - cellMargin * w * 2;
|
|
182
|
+
const paddingOffset = cellPadding * w;
|
|
183
|
+
const paddingSize = w - cellPadding * w * 2;
|
|
184
|
+
const strokeWeight = cellStrokeWeight * w;
|
|
185
|
+
|
|
186
|
+
this._p.push();
|
|
187
|
+
|
|
188
|
+
this._p.translate(posX, posY);
|
|
189
|
+
|
|
190
|
+
this._p.strokeWeight(strokeWeight);
|
|
191
|
+
this._p.stroke(color);
|
|
192
|
+
|
|
193
|
+
// Outer Box
|
|
194
|
+
this._p.noFill();
|
|
195
|
+
this._p.rect(innerOffset, innerOffset, innerSize, innerSize);
|
|
196
|
+
|
|
197
|
+
// Inner Fill
|
|
198
|
+
this._p.fill(color);
|
|
199
|
+
this._p.rect(paddingOffset, paddingOffset, paddingSize, paddingSize);
|
|
200
|
+
|
|
201
|
+
this._p.pop();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import GameScore from './GameScore';
|
|
3
|
+
|
|
4
|
+
describe('GameScore', () => {
|
|
5
|
+
let gameScore: GameScore;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
vi.stubGlobal('localStorage', {
|
|
9
|
+
getItem: vi.fn().mockReturnValue('100'),
|
|
10
|
+
setItem: vi.fn(),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
gameScore = new GameScore();
|
|
14
|
+
gameScore.setup();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('increaseScore', () => {
|
|
18
|
+
it('should increase score by base amount * multiplier', () => {
|
|
19
|
+
// [ARRANGE]
|
|
20
|
+
gameScore.multiplier = 2;
|
|
21
|
+
|
|
22
|
+
// [ACT]
|
|
23
|
+
gameScore.increaseScore(50);
|
|
24
|
+
|
|
25
|
+
// [ASSERT]
|
|
26
|
+
expect(gameScore.score).toBe(100);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should update high score if current score exceeds it', () => {
|
|
30
|
+
// [ACT]
|
|
31
|
+
gameScore.increaseScore(150);
|
|
32
|
+
|
|
33
|
+
// [ASSERT]
|
|
34
|
+
expect(localStorage.setItem).toHaveBeenCalledWith('highScore', '150');
|
|
35
|
+
expect(gameScore.highScore).toBe(150);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should NOT update high score if current score is lower than high score', () => {
|
|
39
|
+
// [ACT]
|
|
40
|
+
gameScore.increaseScore(50);
|
|
41
|
+
|
|
42
|
+
// [ASSERT]
|
|
43
|
+
expect(localStorage.setItem).not.toHaveBeenCalled();
|
|
44
|
+
expect(gameScore.highScore).toBe(100);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('formatting', () => {
|
|
49
|
+
it('should return score padded with zeros', () => {
|
|
50
|
+
// [ARRANGE]
|
|
51
|
+
gameScore.increaseScore(123); // multiplier is 1 by default
|
|
52
|
+
|
|
53
|
+
// [ACT]
|
|
54
|
+
const formatted = gameScore.getFormattedScore(6);
|
|
55
|
+
|
|
56
|
+
// [ASSERT]
|
|
57
|
+
expect(formatted).toBe('000123');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('Level Management', () => {
|
|
62
|
+
it('should increase and reset level', () => {
|
|
63
|
+
// [ACT]
|
|
64
|
+
gameScore.increaseLevel(2);
|
|
65
|
+
expect(gameScore.level).toBe(3);
|
|
66
|
+
|
|
67
|
+
gameScore.resetLevel();
|
|
68
|
+
expect(gameScore.level).toBe(1);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { Debuggable } from '../../types/Interfaces';
|
|
2
|
+
import { Score } from '../../types/modules';
|
|
3
|
+
import { Serializable } from '../../types/Interfaces';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Manages game scoring, levels, and high score tracking.
|
|
7
|
+
* Acts as the authority for the game's `highScore`, persisting it directly to `LocalStorage`.
|
|
8
|
+
* Handles multipliers and supports Session serialization out of the box.
|
|
9
|
+
*/
|
|
10
|
+
export default class GameScore implements Score, Debuggable, Serializable {
|
|
11
|
+
private _score: number = 0;
|
|
12
|
+
private _multiplier: number = 1;
|
|
13
|
+
private _level: number = 1;
|
|
14
|
+
private _maxLevel: number = 10;
|
|
15
|
+
private _highScore: number = 0;
|
|
16
|
+
|
|
17
|
+
serialId: string = 'score';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Initializes the score module.
|
|
21
|
+
* Currently a no-op but required by interface.
|
|
22
|
+
*/
|
|
23
|
+
setup(): void {
|
|
24
|
+
this._highScore = Number(localStorage.getItem('highScore'));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Increases the score by the given amount, applying the current multiplier.
|
|
29
|
+
* Automatically checks for high score updates.
|
|
30
|
+
*
|
|
31
|
+
* @param {number} amount - The base amount to increase by.
|
|
32
|
+
*/
|
|
33
|
+
increaseScore(amount: number): void {
|
|
34
|
+
this._score += amount * this._multiplier;
|
|
35
|
+
if (this._score > this._highScore) {
|
|
36
|
+
this.highScore = this._score;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Resets the current score to 0.
|
|
42
|
+
*/
|
|
43
|
+
resetScore(): void {
|
|
44
|
+
this._score = 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Formats the current score as a string with leading zeros.
|
|
49
|
+
*
|
|
50
|
+
* @param {number} [digits=6] - The total number of digits to display.
|
|
51
|
+
* @returns {string} The formatted score string (e.g., "000150").
|
|
52
|
+
*/
|
|
53
|
+
getFormattedScore(digits: number = 6): string {
|
|
54
|
+
return this._score.toString().padStart(digits, '0');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Increases the game level by a specific amount.
|
|
59
|
+
*
|
|
60
|
+
* @param {number} amount - The number of levels to add.
|
|
61
|
+
*/
|
|
62
|
+
increaseLevel(amount: number): void {
|
|
63
|
+
this._level += amount;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Resets the game level back to 1.
|
|
68
|
+
*/
|
|
69
|
+
resetLevel(): void {
|
|
70
|
+
this._level = 1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets the current score multiplier.
|
|
75
|
+
*
|
|
76
|
+
* @returns {number} The active multiplier.
|
|
77
|
+
*/
|
|
78
|
+
get multiplier(): number {
|
|
79
|
+
return this._multiplier;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Sets the score multiplier.
|
|
84
|
+
*
|
|
85
|
+
* @param {number} value - The new multiplier value.
|
|
86
|
+
*/
|
|
87
|
+
set multiplier(value: number) {
|
|
88
|
+
this._multiplier = value;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Gets the current level.
|
|
93
|
+
*
|
|
94
|
+
* @returns {number} The current level.
|
|
95
|
+
*/
|
|
96
|
+
get level(): number {
|
|
97
|
+
return this._level;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Gets the current raw score.
|
|
102
|
+
*
|
|
103
|
+
* @returns {number} The current score value.
|
|
104
|
+
*/
|
|
105
|
+
get score(): number {
|
|
106
|
+
return this._score;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Gets the maximum achievable level (if defined).
|
|
111
|
+
*
|
|
112
|
+
* @returns {number} The max level.
|
|
113
|
+
*/
|
|
114
|
+
get maxLevel(): number {
|
|
115
|
+
return this._maxLevel;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Sets the maximum game level.
|
|
120
|
+
*
|
|
121
|
+
* @param {number} value - The max level cap.
|
|
122
|
+
*/
|
|
123
|
+
set maxLevel(value: number) {
|
|
124
|
+
this._maxLevel = value;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Gets the current high score.
|
|
129
|
+
*
|
|
130
|
+
* @returns {number} The current high score.
|
|
131
|
+
*/
|
|
132
|
+
get highScore(): number {
|
|
133
|
+
return this._highScore;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Sets the high score.
|
|
138
|
+
*
|
|
139
|
+
* @param {number} value - The new high score.
|
|
140
|
+
*/
|
|
141
|
+
set highScore(value: number) {
|
|
142
|
+
this._highScore = value;
|
|
143
|
+
localStorage.setItem('highScore', value.toString());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Retrieves debug information about the score status.
|
|
148
|
+
*
|
|
149
|
+
* @returns {Record<string, string | number | boolean>} The debug data.
|
|
150
|
+
*/
|
|
151
|
+
getDebugData(): Record<string, string | number | boolean> {
|
|
152
|
+
return {
|
|
153
|
+
score: this._score,
|
|
154
|
+
multiplier: this._multiplier,
|
|
155
|
+
level: this._level,
|
|
156
|
+
max_level: this._maxLevel,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Serializes the current score and level progress into a JSON string.
|
|
162
|
+
* This is used by the SessionManager to save transient state.
|
|
163
|
+
*
|
|
164
|
+
* @returns {string} The serialized JSON data.
|
|
165
|
+
*/
|
|
166
|
+
serialize(): string {
|
|
167
|
+
return JSON.stringify({
|
|
168
|
+
score: this._score,
|
|
169
|
+
multiplier: this._multiplier,
|
|
170
|
+
level: this._level,
|
|
171
|
+
max_level: this._maxLevel,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Restores score and level progress from a serialized JSON string.
|
|
177
|
+
* Used by the SessionManager when recovering an active session.
|
|
178
|
+
*
|
|
179
|
+
* @param {string} data - The JSON string containing the saved session data.
|
|
180
|
+
*/
|
|
181
|
+
deserialize(data: string): void {
|
|
182
|
+
const parsed = JSON.parse(data);
|
|
183
|
+
this._score = parsed.score;
|
|
184
|
+
this._multiplier = parsed.multiplier;
|
|
185
|
+
this._level = parsed.level;
|
|
186
|
+
this._maxLevel = parsed.max_level;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, Mock } from 'vitest';
|
|
2
|
+
import GameSession from './GameSession';
|
|
3
|
+
import { State } from '../../types/modules';
|
|
4
|
+
import { Serializable } from '../../types/Interfaces';
|
|
5
|
+
import { StateProperty } from '../../types/enums';
|
|
6
|
+
|
|
7
|
+
const localStorageMock = (() => {
|
|
8
|
+
let store: Record<string, string> = {};
|
|
9
|
+
return {
|
|
10
|
+
getItem: vi.fn((key: string) => store[key] || null),
|
|
11
|
+
setItem: vi.fn((key: string, value: string) => {
|
|
12
|
+
store[key] = value.toString();
|
|
13
|
+
}),
|
|
14
|
+
removeItem: vi.fn((key: string) => {
|
|
15
|
+
delete store[key];
|
|
16
|
+
}),
|
|
17
|
+
clear: vi.fn(() => {
|
|
18
|
+
store = {};
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
})();
|
|
22
|
+
|
|
23
|
+
vi.stubGlobal('localStorage', localStorageMock);
|
|
24
|
+
|
|
25
|
+
describe('GameSession', () => {
|
|
26
|
+
let session: GameSession;
|
|
27
|
+
let mockState: State;
|
|
28
|
+
let mockSerializable: Serializable;
|
|
29
|
+
let showModalMock: Mock;
|
|
30
|
+
let stateSubscriptions: Record<string, (val: boolean) => void>;
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
// [ARRANGE]
|
|
34
|
+
localStorageMock.clear();
|
|
35
|
+
vi.clearAllMocks();
|
|
36
|
+
|
|
37
|
+
stateSubscriptions = {};
|
|
38
|
+
mockState = {
|
|
39
|
+
subscribe: vi.fn((property: StateProperty, callback: (val: boolean) => void) => {
|
|
40
|
+
stateSubscriptions[property] = callback;
|
|
41
|
+
}),
|
|
42
|
+
} as unknown as State;
|
|
43
|
+
|
|
44
|
+
mockSerializable = {
|
|
45
|
+
serialId: 'test-serial',
|
|
46
|
+
serialize: vi.fn().mockReturnValue('serialized-data'),
|
|
47
|
+
deserialize: vi.fn(),
|
|
48
|
+
} as unknown as Serializable;
|
|
49
|
+
|
|
50
|
+
showModalMock = vi.fn();
|
|
51
|
+
|
|
52
|
+
session = new GameSession();
|
|
53
|
+
session.gameId = 'test-game';
|
|
54
|
+
session.setShowModalFunction(showModalMock);
|
|
55
|
+
session.register(mockSerializable);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('saveSession', () => {
|
|
59
|
+
it('should return early and not save if modal is not closed', () => {
|
|
60
|
+
// [ACT]
|
|
61
|
+
session.saveSession();
|
|
62
|
+
|
|
63
|
+
// [ASSERT]
|
|
64
|
+
expect(localStorageMock.setItem).not.toHaveBeenCalled();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should return early and not save if it is game-menu instance', () => {
|
|
68
|
+
// [ARRANGE]
|
|
69
|
+
session.gameId = 'game-menu';
|
|
70
|
+
session.syncState(mockState);
|
|
71
|
+
// Simulate playing state with no previous session, which closes the modal automatically
|
|
72
|
+
stateSubscriptions[StateProperty.PLAYING]?.(true);
|
|
73
|
+
|
|
74
|
+
// [ACT]
|
|
75
|
+
session.saveSession();
|
|
76
|
+
|
|
77
|
+
// [ASSERT]
|
|
78
|
+
expect(localStorageMock.setItem).not.toHaveBeenCalled();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should save session when modal is closed and game is not menu', () => {
|
|
82
|
+
// [ARRANGE]
|
|
83
|
+
session.syncState(mockState);
|
|
84
|
+
// Close the modal automatically since no session exists
|
|
85
|
+
stateSubscriptions[StateProperty.PLAYING]?.(true);
|
|
86
|
+
|
|
87
|
+
// [ACT]
|
|
88
|
+
session.saveSession();
|
|
89
|
+
|
|
90
|
+
// [ASSERT]
|
|
91
|
+
expect(localStorageMock.setItem).toHaveBeenCalledWith('test-game::test-serial', 'serialized-data');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('syncState', () => {
|
|
96
|
+
it('should automatically close modal and not show when there is no session', () => {
|
|
97
|
+
// [ARRANGE]
|
|
98
|
+
session.syncState(mockState);
|
|
99
|
+
|
|
100
|
+
// [ACT]
|
|
101
|
+
stateSubscriptions[StateProperty.PLAYING]?.(true);
|
|
102
|
+
|
|
103
|
+
// [ASSERT]
|
|
104
|
+
expect(showModalMock).not.toHaveBeenCalled();
|
|
105
|
+
// Verify _isModalClosed is true internally by verifying if it can save now
|
|
106
|
+
session.saveSession();
|
|
107
|
+
expect(localStorageMock.setItem).toHaveBeenCalled();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should automatically close modal and not show when it is a game-menu instance', () => {
|
|
111
|
+
// [ARRANGE]
|
|
112
|
+
session.gameId = 'game-menu';
|
|
113
|
+
// Simulate existing session
|
|
114
|
+
localStorageMock.setItem('game-menu::test-serial', 'some-data');
|
|
115
|
+
session.syncState(mockState);
|
|
116
|
+
|
|
117
|
+
// [ACT]
|
|
118
|
+
stateSubscriptions[StateProperty.PLAYING]?.(true);
|
|
119
|
+
|
|
120
|
+
// [ASSERT]
|
|
121
|
+
expect(showModalMock).not.toHaveBeenCalled();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should show session modal when playing, has session, and is not game-menu', () => {
|
|
125
|
+
// [ARRANGE]
|
|
126
|
+
localStorageMock.setItem('test-game::test-serial', 'some-data');
|
|
127
|
+
session.syncState(mockState);
|
|
128
|
+
|
|
129
|
+
// [ACT]
|
|
130
|
+
stateSubscriptions[StateProperty.PLAYING]?.(true);
|
|
131
|
+
|
|
132
|
+
// [ASSERT]
|
|
133
|
+
expect(showModalMock).toHaveBeenCalledTimes(1);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should load session when modal is confirmed and a session exists', () => {
|
|
137
|
+
// [ARRANGE]
|
|
138
|
+
localStorageMock.setItem('test-game::test-serial', 'some-data');
|
|
139
|
+
session.syncState(mockState);
|
|
140
|
+
stateSubscriptions[StateProperty.PLAYING]?.(true);
|
|
141
|
+
const onConfirm = showModalMock.mock.calls[0][0] as () => void;
|
|
142
|
+
|
|
143
|
+
// [ACT]
|
|
144
|
+
onConfirm();
|
|
145
|
+
|
|
146
|
+
// [ASSERT]
|
|
147
|
+
expect(mockSerializable.deserialize).toHaveBeenCalledWith('some-data');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should destroy session when modal is canceled', () => {
|
|
151
|
+
// [ARRANGE]
|
|
152
|
+
localStorageMock.setItem('test-game::test-serial', 'some-data');
|
|
153
|
+
session.syncState(mockState);
|
|
154
|
+
stateSubscriptions[StateProperty.PLAYING]?.(true);
|
|
155
|
+
const onCancel = showModalMock.mock.calls[0][1] as () => void;
|
|
156
|
+
|
|
157
|
+
// [ACT]
|
|
158
|
+
onCancel();
|
|
159
|
+
|
|
160
|
+
// [ASSERT]
|
|
161
|
+
expect(localStorageMock.removeItem).toHaveBeenCalledWith('test-game::test-serial');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('should destroy session when game is over', () => {
|
|
165
|
+
// [ARRANGE]
|
|
166
|
+
localStorageMock.setItem('test-game::test-serial', 'some-data');
|
|
167
|
+
session.syncState(mockState);
|
|
168
|
+
|
|
169
|
+
// [ACT]
|
|
170
|
+
stateSubscriptions[StateProperty.GAME_OVER]?.(true);
|
|
171
|
+
|
|
172
|
+
// [ASSERT]
|
|
173
|
+
expect(localStorageMock.removeItem).toHaveBeenCalledWith('test-game::test-serial');
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
});
|