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,15 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import * as BrickEngine from './index';
|
|
3
|
+
|
|
4
|
+
describe('index (Library Exports)', () => {
|
|
5
|
+
it('should export the core modules and configurations', () => {
|
|
6
|
+
// [ASSERT]
|
|
7
|
+
expect(BrickEngine.Game).toBeDefined();
|
|
8
|
+
expect(BrickEngine.GameView).toBeDefined();
|
|
9
|
+
expect(BrickEngine.configs).toBeDefined();
|
|
10
|
+
|
|
11
|
+
// Exported enums/types check
|
|
12
|
+
expect(BrickEngine.Color).toBeDefined();
|
|
13
|
+
expect(BrickEngine.FontSize).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Library Exports Only
|
|
2
|
+
export * from './core/types/enums';
|
|
3
|
+
export * from './core/types/Interfaces';
|
|
4
|
+
export * from './core/types/modules';
|
|
5
|
+
export * from './core/types/Types';
|
|
6
|
+
export * from './types/interfaces';
|
|
7
|
+
export { default as Game } from './core/Game';
|
|
8
|
+
export { default as GameView } from './view/GameView';
|
|
9
|
+
export { default as configs } from './config/configs';
|
package/src/main.test.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, Mock } from 'vitest';
|
|
3
|
+
import p5 from 'p5';
|
|
4
|
+
import Game from './core/Game';
|
|
5
|
+
|
|
6
|
+
// Mocking everything before importing main.ts logic
|
|
7
|
+
const createMockGame = () => ({
|
|
8
|
+
setup: vi.fn(),
|
|
9
|
+
setSwitchHandler: vi.fn(),
|
|
10
|
+
propagateSwitchHandler: vi.fn(),
|
|
11
|
+
draw: vi.fn(),
|
|
12
|
+
modules: {
|
|
13
|
+
state: { turnOn: vi.fn(), turnOff: vi.fn(), isOn: vi.fn() },
|
|
14
|
+
control: { subscribe: vi.fn() },
|
|
15
|
+
time: { update: vi.fn() },
|
|
16
|
+
},
|
|
17
|
+
view: {
|
|
18
|
+
unbindControls: vi.fn(),
|
|
19
|
+
bindControls: vi.fn(),
|
|
20
|
+
updateDebuggerGameModules: vi.fn(),
|
|
21
|
+
setupDebugger: vi.fn(),
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const mockGame = createMockGame();
|
|
26
|
+
|
|
27
|
+
vi.mock('p5', () => {
|
|
28
|
+
return {
|
|
29
|
+
default: vi.fn().mockImplementation(function (sketch: (p: unknown) => void) {
|
|
30
|
+
const p = {
|
|
31
|
+
loop: vi.fn(),
|
|
32
|
+
noLoop: vi.fn(),
|
|
33
|
+
setup: vi.fn(),
|
|
34
|
+
draw: vi.fn(),
|
|
35
|
+
};
|
|
36
|
+
sketch(p);
|
|
37
|
+
return p;
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
vi.mock('./view/GameView', () => {
|
|
43
|
+
return {
|
|
44
|
+
default: vi.fn().mockImplementation(function () {
|
|
45
|
+
return {
|
|
46
|
+
build: vi.fn().mockReturnValue({ canvas: {}, canvasHeight: 100, canvasWidth: 100 }),
|
|
47
|
+
bindControls: vi.fn(),
|
|
48
|
+
unbindControls: vi.fn(),
|
|
49
|
+
setupDebugger: vi.fn(),
|
|
50
|
+
updateDebuggerGameModules: vi.fn(),
|
|
51
|
+
};
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
vi.mock('./menu/GameMenu', () => {
|
|
57
|
+
return {
|
|
58
|
+
default: vi.fn().mockImplementation(function () {
|
|
59
|
+
return mockGame;
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
vi.mock('./core/Debugger', () => ({
|
|
65
|
+
default: vi.fn().mockImplementation(function () {
|
|
66
|
+
return { setup: vi.fn(), update: vi.fn(), destroy: vi.fn() };
|
|
67
|
+
}),
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
vi.mock('./config/env', () => ({
|
|
71
|
+
isClientMode: vi.fn(),
|
|
72
|
+
isServerMode: vi.fn(),
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
vi.mock('@client-game', () => ({
|
|
76
|
+
default: vi.fn().mockImplementation(function () {
|
|
77
|
+
return mockGame;
|
|
78
|
+
}),
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
vi.mock('./menu/GameMenuSingleton', () => ({
|
|
82
|
+
default: {
|
|
83
|
+
setInstance: vi.fn(),
|
|
84
|
+
getInstance: vi.fn().mockReturnValue(mockGame),
|
|
85
|
+
},
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
vi.mock('./config/styles', () => ({}));
|
|
89
|
+
|
|
90
|
+
describe('main.ts', () => {
|
|
91
|
+
beforeEach(() => {
|
|
92
|
+
vi.clearAllMocks();
|
|
93
|
+
vi.resetModules();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should initialize the p5 instance and GameMenu in server mode', async () => {
|
|
97
|
+
const { isClientMode, isServerMode } = await import('./config/env');
|
|
98
|
+
const GameMenu = (await import('./menu/GameMenu')).default;
|
|
99
|
+
|
|
100
|
+
(isClientMode as unknown as Mock).mockReturnValue(false);
|
|
101
|
+
(isServerMode as unknown as Mock).mockReturnValue(true);
|
|
102
|
+
|
|
103
|
+
const main = await import('./main');
|
|
104
|
+
|
|
105
|
+
expect(p5).toHaveBeenCalled();
|
|
106
|
+
expect(GameMenu).toHaveBeenCalled();
|
|
107
|
+
expect(main.p5Instance).toBeDefined();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should initialize ClientGame in client mode', async () => {
|
|
111
|
+
const { isClientMode, isServerMode } = await import('./config/env');
|
|
112
|
+
const ClientGame = (await import('@client-game')).default;
|
|
113
|
+
|
|
114
|
+
(isClientMode as unknown as Mock).mockReturnValue(true);
|
|
115
|
+
(isServerMode as unknown as Mock).mockReturnValue(false);
|
|
116
|
+
|
|
117
|
+
await import('./main');
|
|
118
|
+
|
|
119
|
+
expect(ClientGame).toHaveBeenCalled();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should handle game switching', async () => {
|
|
123
|
+
const { isClientMode, isServerMode } = await import('./config/env');
|
|
124
|
+
(isClientMode as unknown as Mock).mockReturnValue(false);
|
|
125
|
+
(isServerMode as unknown as Mock).mockReturnValue(true);
|
|
126
|
+
|
|
127
|
+
await import('./main');
|
|
128
|
+
|
|
129
|
+
const switchHandler = (mockGame.setSwitchHandler as unknown as Mock).mock.calls[0][0];
|
|
130
|
+
const nextGame = createMockGame();
|
|
131
|
+
|
|
132
|
+
switchHandler(nextGame as unknown as Game);
|
|
133
|
+
|
|
134
|
+
expect(nextGame.setup).toHaveBeenCalled();
|
|
135
|
+
expect(nextGame.modules.state.turnOn).toHaveBeenCalled();
|
|
136
|
+
});
|
|
137
|
+
});
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import p5 from 'p5';
|
|
2
|
+
import Game from './core/Game';
|
|
3
|
+
import GameView from './view/GameView';
|
|
4
|
+
import GameMenu from './menu/GameMenu';
|
|
5
|
+
|
|
6
|
+
import './config/styles';
|
|
7
|
+
|
|
8
|
+
import { isClientMode, isServerMode } from './config/env';
|
|
9
|
+
import ClientGame from '@client-game';
|
|
10
|
+
import { ControlEventType, ControlKey } from './core/types/enums';
|
|
11
|
+
import GameMenuSingleton from './menu/GameMenuSingleton';
|
|
12
|
+
|
|
13
|
+
export const p5Instance = new p5((p: p5) => {
|
|
14
|
+
const view = new GameView(p, document.body);
|
|
15
|
+
let activeGame: Game;
|
|
16
|
+
|
|
17
|
+
if (isClientMode()) {
|
|
18
|
+
// In client mode, we instantiate the game provided via alias
|
|
19
|
+
activeGame = new ClientGame(p, view);
|
|
20
|
+
activeGame.gameId = 'client-game';
|
|
21
|
+
} else if (isServerMode()) {
|
|
22
|
+
// In server mode, we instantiate the game menu
|
|
23
|
+
activeGame = new GameMenu(p, view);
|
|
24
|
+
activeGame.gameId = 'game-menu';
|
|
25
|
+
GameMenuSingleton.setInstance(activeGame as GameMenu);
|
|
26
|
+
} else {
|
|
27
|
+
throw new Error('Invalid APP_MODE');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Register the switch handler
|
|
31
|
+
activeGame.setSwitchHandler((newGame: Game) => {
|
|
32
|
+
try {
|
|
33
|
+
// Unbind the previous game controls
|
|
34
|
+
activeGame.view.unbindControls();
|
|
35
|
+
|
|
36
|
+
// Propagate the switch handler to the new game
|
|
37
|
+
newGame.propagateSwitchHandler(activeGame);
|
|
38
|
+
|
|
39
|
+
// Set the new game
|
|
40
|
+
activeGame = newGame;
|
|
41
|
+
activeGame.setup();
|
|
42
|
+
|
|
43
|
+
// Update debugger
|
|
44
|
+
activeGame.view.updateDebuggerGameModules(activeGame.modules);
|
|
45
|
+
|
|
46
|
+
// Bind the new game controls
|
|
47
|
+
activeGame.view.bindControls(activeGame.modules.control);
|
|
48
|
+
activeGame.modules.state.turnOn();
|
|
49
|
+
|
|
50
|
+
// Setup exit and power buttons
|
|
51
|
+
if (isServerMode() && newGame !== GameMenuSingleton.getInstance()) {
|
|
52
|
+
newGame.modules.control.subscribe(ControlKey.EXIT, ControlEventType.PRESSED, () => {
|
|
53
|
+
newGame.switchGame(GameMenuSingleton.getInstance());
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
newGame.modules.control.subscribe(ControlKey.POWER, ControlEventType.PRESSED, () => {
|
|
57
|
+
newGame.switchGame(GameMenuSingleton.getInstance());
|
|
58
|
+
activeGame.modules.state.turnOff();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Error switching game:', error);
|
|
63
|
+
}
|
|
64
|
+
p.loop();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
p.setup = () => {
|
|
68
|
+
activeGame.setup();
|
|
69
|
+
activeGame.view.setupDebugger(activeGame.modules);
|
|
70
|
+
activeGame.view.setupSessionModal();
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
p.draw = () => {
|
|
74
|
+
activeGame.draw();
|
|
75
|
+
activeGame.view.updateDebugger();
|
|
76
|
+
};
|
|
77
|
+
}, document.body);
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/** @vitest-environment jsdom */
|
|
2
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
+
import GameMenu from './GameMenu';
|
|
4
|
+
import GameView from '../view/GameView';
|
|
5
|
+
import p5 from 'p5';
|
|
6
|
+
import { ControlEventType, ControlKey } from '../core/types/enums';
|
|
7
|
+
|
|
8
|
+
// Mock GameRepository to avoid external dependencies
|
|
9
|
+
vi.mock('./GameRepository', () => {
|
|
10
|
+
return {
|
|
11
|
+
default: vi.fn().mockImplementation(function () {
|
|
12
|
+
return {
|
|
13
|
+
games: [
|
|
14
|
+
{ id: '1', name: 'Game 1', url: 'url1' },
|
|
15
|
+
{ id: '2', name: 'Game 2', url: 'url2' },
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
}),
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Mock GameManager
|
|
23
|
+
vi.mock('./manager/GameManager', () => {
|
|
24
|
+
return {
|
|
25
|
+
default: vi.fn().mockImplementation(function () {
|
|
26
|
+
return {
|
|
27
|
+
handleGameSwitch: vi.fn(),
|
|
28
|
+
};
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('GameMenu', () => {
|
|
34
|
+
let menu: GameMenu;
|
|
35
|
+
let mockP5: Record<string, unknown>;
|
|
36
|
+
let mockView: Record<string, unknown>;
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
vi.stubGlobal('localStorage', {
|
|
40
|
+
getItem: vi.fn().mockReturnValue(null),
|
|
41
|
+
setItem: vi.fn(),
|
|
42
|
+
clear: vi.fn(),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
vi.stubGlobal(
|
|
46
|
+
'AudioContext',
|
|
47
|
+
vi.fn().mockImplementation(function () {
|
|
48
|
+
return {
|
|
49
|
+
createGain: vi.fn().mockReturnValue({
|
|
50
|
+
connect: vi.fn(),
|
|
51
|
+
gain: { setValueAtTime: vi.fn() },
|
|
52
|
+
}),
|
|
53
|
+
createBufferSource: vi.fn().mockReturnValue({
|
|
54
|
+
connect: vi.fn(),
|
|
55
|
+
start: vi.fn(),
|
|
56
|
+
buffer: null,
|
|
57
|
+
}),
|
|
58
|
+
destination: {},
|
|
59
|
+
decodeAudioData: vi.fn().mockResolvedValue({}),
|
|
60
|
+
resume: vi.fn().mockResolvedValue({}),
|
|
61
|
+
};
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
vi.stubGlobal(
|
|
66
|
+
'fetch',
|
|
67
|
+
vi.fn().mockResolvedValue({
|
|
68
|
+
arrayBuffer: vi.fn().mockResolvedValue(new ArrayBuffer(0)),
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
mockP5 = {
|
|
73
|
+
deltaTime: 16,
|
|
74
|
+
noLoop: vi.fn(),
|
|
75
|
+
push: vi.fn(),
|
|
76
|
+
pop: vi.fn(),
|
|
77
|
+
translate: vi.fn(),
|
|
78
|
+
strokeWeight: vi.fn(),
|
|
79
|
+
stroke: vi.fn(),
|
|
80
|
+
noFill: vi.fn(),
|
|
81
|
+
rect: vi.fn(),
|
|
82
|
+
fill: vi.fn(),
|
|
83
|
+
text: vi.fn(),
|
|
84
|
+
textFont: vi.fn(),
|
|
85
|
+
textSize: vi.fn(),
|
|
86
|
+
textAlign: vi.fn(),
|
|
87
|
+
image: vi.fn(),
|
|
88
|
+
createGraphics: vi.fn().mockReturnValue({
|
|
89
|
+
background: vi.fn(),
|
|
90
|
+
strokeWeight: vi.fn(),
|
|
91
|
+
noFill: vi.fn(),
|
|
92
|
+
stroke: vi.fn(),
|
|
93
|
+
rect: vi.fn(),
|
|
94
|
+
}),
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
mockView = {
|
|
98
|
+
build: vi.fn(),
|
|
99
|
+
bindControls: vi.fn(),
|
|
100
|
+
showSessionModal: vi.fn(),
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
menu = new GameMenu(mockP5 as unknown as p5, mockView as unknown as GameView);
|
|
104
|
+
menu.setup();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should cycle through games on LEFT/RIGHT arrow press', () => {
|
|
108
|
+
const { control, state } = menu.modules;
|
|
109
|
+
|
|
110
|
+
// Ensure game is ON and STARTED/PLAYING
|
|
111
|
+
state.turnOn();
|
|
112
|
+
state.startGame();
|
|
113
|
+
|
|
114
|
+
expect(state.isPlaying()).toBe(true);
|
|
115
|
+
|
|
116
|
+
// Initial selection should be 0 (Game 1)
|
|
117
|
+
expect((menu as unknown as Record<string, unknown>)['_gameSelectionPointer']).toBe(0);
|
|
118
|
+
|
|
119
|
+
// Press RIGHT
|
|
120
|
+
control.notify(ControlKey.RIGHT, ControlEventType.PRESSED);
|
|
121
|
+
expect((menu as unknown as Record<string, unknown>)['_gameSelectionPointer']).toBe(1);
|
|
122
|
+
|
|
123
|
+
// Press RIGHT again (should cycle)
|
|
124
|
+
control.notify(ControlKey.RIGHT, ControlEventType.PRESSED);
|
|
125
|
+
expect((menu as unknown as Record<string, unknown>)['_gameSelectionPointer']).toBe(0);
|
|
126
|
+
|
|
127
|
+
// Press LEFT (should cycle back)
|
|
128
|
+
control.notify(ControlKey.LEFT, ControlEventType.PRESSED);
|
|
129
|
+
expect((menu as unknown as Record<string, unknown>)['_gameSelectionPointer']).toBe(1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should handle game switch on ACTION press', () => {
|
|
133
|
+
const { control, state } = menu.modules;
|
|
134
|
+
state.turnOn();
|
|
135
|
+
state.startGame();
|
|
136
|
+
|
|
137
|
+
expect(state.isStarted()).toBe(true);
|
|
138
|
+
|
|
139
|
+
const managerSpy = (menu as unknown as { _gameManager: { handleGameSwitch: import('vitest').Mock } })._gameManager.handleGameSwitch;
|
|
140
|
+
|
|
141
|
+
control.notify(ControlKey.ACTION, ControlEventType.PRESSED);
|
|
142
|
+
|
|
143
|
+
expect(managerSpy).toHaveBeenCalledWith(expect.objectContaining({ name: 'Game 1' }), menu);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should play theme when turned on', () => {
|
|
147
|
+
const { state, sound } = menu.modules;
|
|
148
|
+
|
|
149
|
+
// Mock play to resolve
|
|
150
|
+
const soundSpy = vi.spyOn(sound, 'play').mockResolvedValue(undefined as unknown as void);
|
|
151
|
+
|
|
152
|
+
state.turnOn();
|
|
153
|
+
|
|
154
|
+
expect(state.isOn()).toBe(true);
|
|
155
|
+
expect(soundSpy).toHaveBeenCalled();
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import p5 from 'p5';
|
|
2
|
+
import GameView from '../view/GameView';
|
|
3
|
+
import Game from '../core/Game';
|
|
4
|
+
import { ControlEventType, ControlKey, FontAlign, FontSize, FontVerticalAlign, Sound, StateProperty } from '../core/types/enums';
|
|
5
|
+
import GameRepository from './GameRepository';
|
|
6
|
+
import GameManager from './manager/GameManager';
|
|
7
|
+
|
|
8
|
+
export default class GameMenu extends Game {
|
|
9
|
+
private _gameSelectionPointer = 0;
|
|
10
|
+
private _isLoading = false;
|
|
11
|
+
|
|
12
|
+
private _gameRepository = new GameRepository();
|
|
13
|
+
private _gameManager = new GameManager();
|
|
14
|
+
|
|
15
|
+
constructor(p: p5, view: GameView) {
|
|
16
|
+
super(p, view);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setupGame() {
|
|
20
|
+
const { state, control, sound } = this.modules;
|
|
21
|
+
|
|
22
|
+
control.subscribe(ControlKey.ACTION, ControlEventType.PRESSED, () => {
|
|
23
|
+
if (this._isLoading) return;
|
|
24
|
+
|
|
25
|
+
if (state.isStarted()) {
|
|
26
|
+
const selectedGame = this._gameRepository.games[this._gameSelectionPointer];
|
|
27
|
+
this._gameManager.handleGameSwitch(selectedGame, this);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
control.subscribe(ControlKey.LEFT, ControlEventType.PRESSED, () => {
|
|
32
|
+
if (state.isPlaying()) {
|
|
33
|
+
sound.play(Sound.ACTION_1);
|
|
34
|
+
if (this._gameSelectionPointer === 0) {
|
|
35
|
+
this._gameSelectionPointer = this._gameRepository.games.length - 1;
|
|
36
|
+
} else {
|
|
37
|
+
this._gameSelectionPointer--;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
control.subscribe(ControlKey.RIGHT, ControlEventType.PRESSED, () => {
|
|
43
|
+
if (state.isPlaying()) {
|
|
44
|
+
sound.play(Sound.ACTION_1);
|
|
45
|
+
if (this._gameSelectionPointer === this._gameRepository.games.length - 1) {
|
|
46
|
+
this._gameSelectionPointer = 0;
|
|
47
|
+
} else {
|
|
48
|
+
this._gameSelectionPointer++;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
state.subscribe(StateProperty.ON, on => {
|
|
54
|
+
if (on) {
|
|
55
|
+
sound.play(Sound.START_THEME);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
update() {}
|
|
61
|
+
|
|
62
|
+
render() {
|
|
63
|
+
const { text } = this.modules;
|
|
64
|
+
|
|
65
|
+
const { p } = this;
|
|
66
|
+
p.push();
|
|
67
|
+
|
|
68
|
+
text.setTextSize(FontSize.LARGE);
|
|
69
|
+
text.setActiveText();
|
|
70
|
+
text.setTextAlign(FontAlign.CENTER, FontVerticalAlign.BOTTOM);
|
|
71
|
+
|
|
72
|
+
text.textOnDisplay('Menu', { x: 0.5, y: 0.15 });
|
|
73
|
+
|
|
74
|
+
text.setTextSize(FontSize.SMALL);
|
|
75
|
+
|
|
76
|
+
text.textOnDisplay('Choose a game and', { x: 0.5, y: 0.25 });
|
|
77
|
+
text.textOnDisplay('Press action to play', { x: 0.5, y: 0.32 });
|
|
78
|
+
|
|
79
|
+
text.setTextAlign(FontAlign.RIGHT, FontVerticalAlign.BOTTOM);
|
|
80
|
+
text.textOnDisplay('<', { x: 0.1, y: 0.54 });
|
|
81
|
+
|
|
82
|
+
text.setTextAlign(FontAlign.LEFT, FontVerticalAlign.BOTTOM);
|
|
83
|
+
text.textOnDisplay('>', { x: 0.9, y: 0.54 });
|
|
84
|
+
|
|
85
|
+
text.setTextSize(FontSize.MEDIUM);
|
|
86
|
+
text.setTextAlign(FontAlign.CENTER, FontVerticalAlign.BOTTOM);
|
|
87
|
+
text.textOnDisplay(this._gameRepository.games[this._gameSelectionPointer].name, { x: 0.5, y: 0.55 });
|
|
88
|
+
|
|
89
|
+
text.setTextSize(FontSize.EXTRA_SMALL);
|
|
90
|
+
text.setTextAlign(FontAlign.LEFT, FontVerticalAlign.BOTTOM);
|
|
91
|
+
|
|
92
|
+
text.textOnDisplay('Left: Previous option', { x: 0.05, y: 0.78 });
|
|
93
|
+
text.textOnDisplay('Right: Next option', { x: 0.05, y: 0.84 });
|
|
94
|
+
text.textOnDisplay('Action: Select', { x: 0.05, y: 0.9 });
|
|
95
|
+
|
|
96
|
+
p.pop();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
drawTitleScreen() {
|
|
100
|
+
const { text } = this.modules;
|
|
101
|
+
|
|
102
|
+
this.p.push();
|
|
103
|
+
|
|
104
|
+
text.setTextSize(FontSize.LARGE);
|
|
105
|
+
text.setActiveText();
|
|
106
|
+
text.setTextAlign(FontAlign.CENTER, FontVerticalAlign.TOP);
|
|
107
|
+
|
|
108
|
+
text.textOnDisplay('Menu', { x: 0.5, y: 0.15 });
|
|
109
|
+
|
|
110
|
+
text.setTextSize(FontSize.SMALL);
|
|
111
|
+
|
|
112
|
+
text.textOnDisplay('Wellcome to your', { x: 0.5, y: 0.25 });
|
|
113
|
+
text.textOnDisplay('favorite brick game', { x: 0.5, y: 0.32 });
|
|
114
|
+
text.textOnDisplay('simulator!', { x: 0.5, y: 0.39 });
|
|
115
|
+
text.textOnDisplay('Press start', { x: 0.5, y: 0.66 });
|
|
116
|
+
text.textOnDisplay('to continue.', { x: 0.5, y: 0.72 });
|
|
117
|
+
|
|
118
|
+
this.p.pop();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
drawGameOverScreen() {
|
|
122
|
+
// Menu doesn't have a game over screen
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import GameMenuSingleton from './GameMenuSingleton';
|
|
3
|
+
import GameMenu from './GameMenu';
|
|
4
|
+
|
|
5
|
+
describe('GameMenuSingleton', () => {
|
|
6
|
+
it('should store and retrieve a GameMenu instance', () => {
|
|
7
|
+
const mockInstance = { name: 'MockGameMenu' } as unknown as GameMenu;
|
|
8
|
+
|
|
9
|
+
GameMenuSingleton.setInstance(mockInstance);
|
|
10
|
+
const retrieved = GameMenuSingleton.getInstance();
|
|
11
|
+
|
|
12
|
+
expect(retrieved).toBe(mockInstance);
|
|
13
|
+
expect((retrieved as unknown as { name: string }).name).toBe('MockGameMenu');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should overwrite the previous instance when setInstance is called again', () => {
|
|
17
|
+
const mockInstance1 = { id: 1 } as unknown as GameMenu;
|
|
18
|
+
const mockInstance2 = { id: 2 } as unknown as GameMenu;
|
|
19
|
+
|
|
20
|
+
GameMenuSingleton.setInstance(mockInstance1);
|
|
21
|
+
expect(GameMenuSingleton.getInstance()).toBe(mockInstance1);
|
|
22
|
+
|
|
23
|
+
GameMenuSingleton.setInstance(mockInstance2);
|
|
24
|
+
expect(GameMenuSingleton.getInstance()).toBe(mockInstance2);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import GameMenu from './GameMenu';
|
|
2
|
+
|
|
3
|
+
export default class GameMenuSingleton {
|
|
4
|
+
private static _instance: GameMenu;
|
|
5
|
+
|
|
6
|
+
static setInstance(instance: GameMenu) {
|
|
7
|
+
GameMenuSingleton._instance = instance;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static getInstance(): GameMenu {
|
|
11
|
+
return GameMenuSingleton._instance;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import GameRepository from './GameRepository';
|
|
3
|
+
|
|
4
|
+
describe('GameRepository', () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
vi.stubGlobal(
|
|
7
|
+
'fetch',
|
|
8
|
+
vi.fn().mockResolvedValue({
|
|
9
|
+
ok: true,
|
|
10
|
+
json: vi.fn().mockResolvedValue({
|
|
11
|
+
games: [{ id: 'test-game', name: 'Test Game', url: 'http://localhost:8080/game.bundle.js' }],
|
|
12
|
+
}),
|
|
13
|
+
}),
|
|
14
|
+
);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
vi.unstubAllGlobals();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should start with a loading state', () => {
|
|
22
|
+
const repo = new GameRepository();
|
|
23
|
+
expect(repo.games).toBeDefined();
|
|
24
|
+
expect(repo.games.length).toBeGreaterThan(0);
|
|
25
|
+
expect(repo.games[0].name).toBe('Loading...');
|
|
26
|
+
expect(repo.games[0].id).toBe('loading');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should load games asynchronously', async () => {
|
|
30
|
+
const repo = new GameRepository();
|
|
31
|
+
// Wait for the microtask queue to process the fetch
|
|
32
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
33
|
+
|
|
34
|
+
expect(repo.games[0].id).toBe('test-game');
|
|
35
|
+
expect(repo.games[0].name).toBe('Test Game');
|
|
36
|
+
expect(repo.games[0].url).toBe('http://localhost:8080/game.bundle.js');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should return a frozen list of games', () => {
|
|
40
|
+
const repo = new GameRepository();
|
|
41
|
+
const games = repo.games;
|
|
42
|
+
|
|
43
|
+
// This should throw in strict mode, or at least not change if we tried to mutate it
|
|
44
|
+
expect(Object.isFrozen(games)).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GameEntry } from '../types/interfaces';
|
|
2
|
+
|
|
3
|
+
export default class GameRepository {
|
|
4
|
+
private _games: GameEntry[] = [{ id: 'loading', name: 'Loading...', url: '' }];
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
this.fetchGames();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
private async fetchGames(): Promise<void> {
|
|
11
|
+
try {
|
|
12
|
+
// Read from injected env variables, or fallback to local
|
|
13
|
+
const supabaseUrl = process.env.SUPABASE_URL || 'http://127.0.0.1:54321';
|
|
14
|
+
const anonKey = process.env.SUPABASE_ANON_KEY || '';
|
|
15
|
+
|
|
16
|
+
const headers: HeadersInit = {};
|
|
17
|
+
if (anonKey) {
|
|
18
|
+
headers['Authorization'] = `Bearer ${anonKey}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const response = await fetch(`${supabaseUrl}/functions/v1/list`, {
|
|
22
|
+
headers,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
throw new Error(`Error fetching games: ${response.statusText}`);
|
|
27
|
+
}
|
|
28
|
+
const data = await response.json();
|
|
29
|
+
if (data && data.games && data.games.length > 0) {
|
|
30
|
+
this._games = data.games.map((game: GameEntry) => ({
|
|
31
|
+
id: game.id,
|
|
32
|
+
name: game.name,
|
|
33
|
+
url: game.url,
|
|
34
|
+
}));
|
|
35
|
+
} else {
|
|
36
|
+
this._games = [{ id: 'empty', name: 'Not found', url: '' }];
|
|
37
|
+
}
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error(error);
|
|
40
|
+
this._games = [{ id: 'error', name: 'Error', url: '' }];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get games(): readonly GameEntry[] {
|
|
45
|
+
return Object.freeze(this._games);
|
|
46
|
+
}
|
|
47
|
+
}
|