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,34 @@
|
|
|
1
|
+
= SessionModal Module Reference
|
|
2
|
+
:description: Handles the UI layer interaction for restoring saved active play sessions.
|
|
3
|
+
:keywords: modal, ui, dialog, DOM, restoration, session
|
|
4
|
+
:toc: left
|
|
5
|
+
:toclevels: 3
|
|
6
|
+
:sectnums:
|
|
7
|
+
:sectlinks:
|
|
8
|
+
:icons: font
|
|
9
|
+
|
|
10
|
+
The `SessionModal` interacts directly with the DOM outside of the Canvas domain, creating standard HTML elements (divs and buttons) overlapping the P5.js context to prompt users whether they wish to resume their previous game session.
|
|
11
|
+
|
|
12
|
+
== Lifecycle
|
|
13
|
+
|
|
14
|
+
=== `setup(): void`
|
|
15
|
+
|
|
16
|
+
Creates the necessary DOM layer elements. Called typically during engine bootstrap by the `xref:../../view/GameView.adoc[GameView]`.
|
|
17
|
+
Constructs the background container wrapper, title frames, dialogue text, and confirm/cancel action buttons. Sets their initial state utilizing the CSS `.hidden` class to keep them out of view until queried.
|
|
18
|
+
|
|
19
|
+
=== `show(onConfirm: () => void, onCancel: () => void): void`
|
|
20
|
+
|
|
21
|
+
Reveals the modal.
|
|
22
|
+
|
|
23
|
+
**Parameters**
|
|
24
|
+
|
|
25
|
+
[cols="1,1,3"]
|
|
26
|
+
|===
|
|
27
|
+
|Name |Type |Description
|
|
28
|
+
|`onConfirm` |`Function` |The closure executed if the user selects "Confirm".
|
|
29
|
+
|`onCancel` |`Function` |The closure executed if the user selects "Cancel".
|
|
30
|
+
|===
|
|
31
|
+
|
|
32
|
+
**Behavior**
|
|
33
|
+
|
|
34
|
+
Hooks the callback functions directly to the `mousePressed` listener of the individual DOM buttons. Upon clicking any of the buttons, it executes the passed callback and immediately invokes `_hide()`, returning to its hidden CSS boundary.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
= Axis Reference
|
|
2
|
+
:description: Represents an axis in a 2D coordinate system.
|
|
3
|
+
:keywords: axis, coordinate, 2d, transformation, mirror
|
|
4
|
+
:toc: left
|
|
5
|
+
:toclevels: 3
|
|
6
|
+
:sectnums:
|
|
7
|
+
:sectlinks:
|
|
8
|
+
:icons: font
|
|
9
|
+
:source-highlighter: highlight.js
|
|
10
|
+
:reproducible:
|
|
11
|
+
:experimental:
|
|
12
|
+
:idprefix:
|
|
13
|
+
:idseparator: -
|
|
14
|
+
|
|
15
|
+
Represents an axis in a 2D coordinate system.
|
|
16
|
+
|
|
17
|
+
== Possible Values
|
|
18
|
+
|
|
19
|
+
[cols="1,3"]
|
|
20
|
+
|===
|
|
21
|
+
|Value |Description
|
|
22
|
+
|`'x'` |The horizontal axis.
|
|
23
|
+
|`'y'` |The vertical axis.
|
|
24
|
+
|===
|
|
25
|
+
|
|
26
|
+
== General Usage
|
|
27
|
+
|
|
28
|
+
The `Axis` type is primarily used for transformation operations that apply selectively to one dimension, such as mirroring a piece across a specific axis.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
= Cell Reference
|
|
2
|
+
:description: Represents the state of an individual unit within the 2D game grid.
|
|
3
|
+
:keywords: cell, grid, unit, state
|
|
4
|
+
:toc: left
|
|
5
|
+
:toclevels: 3
|
|
6
|
+
:sectnums:
|
|
7
|
+
:sectlinks:
|
|
8
|
+
:icons: font
|
|
9
|
+
:source-highlighter: highlight.js
|
|
10
|
+
:reproducible:
|
|
11
|
+
:experimental:
|
|
12
|
+
:idprefix:
|
|
13
|
+
:idseparator: -
|
|
14
|
+
|
|
15
|
+
Represents the state of an individual unit within the 2D game grid.
|
|
16
|
+
|
|
17
|
+
== Attributes
|
|
18
|
+
|
|
19
|
+
[cols="1,1,3"]
|
|
20
|
+
|===
|
|
21
|
+
|Name |Type |Description
|
|
22
|
+
|`value` |`number` |Lifecycle value. `0` is empty, `>0` is occupied.
|
|
23
|
+
|`color` |xref:../enums/Color.adoc[Color] |The theme color to render the cell with.
|
|
24
|
+
|`coordinate` |xref:Coordinate.adoc[Coordinate] |The `{x, y}` position of this cell.
|
|
25
|
+
|===
|
|
26
|
+
|
|
27
|
+
== General Usage
|
|
28
|
+
|
|
29
|
+
Cells are managed by the `xref:../modules/GameGrid.adoc[GameGrid]` module. They are rarely created manually; instead, they are accessed and modified via methods like `grid.getCell(coord)` and `grid.setCellValue(coord, val)`.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
= ControlCallback Reference
|
|
2
|
+
:description: Type definition for functions that handle engine input.
|
|
3
|
+
:keywords: callback, control, input, subscriber
|
|
4
|
+
:toc: left
|
|
5
|
+
:toclevels: 3
|
|
6
|
+
:sectnums:
|
|
7
|
+
:sectlinks:
|
|
8
|
+
:icons: font
|
|
9
|
+
:source-highlighter: highlight.js
|
|
10
|
+
:reproducible:
|
|
11
|
+
:experimental:
|
|
12
|
+
:idprefix:
|
|
13
|
+
:idseparator: -
|
|
14
|
+
|
|
15
|
+
Type definition for functions that handle engine input.
|
|
16
|
+
|
|
17
|
+
== Structure
|
|
18
|
+
|
|
19
|
+
`type ControlCallback = (event: xref:GameEvent.adoc[GameEvent]) => void;`
|
|
20
|
+
|
|
21
|
+
== General Usage
|
|
22
|
+
|
|
23
|
+
This type ensures that functions passed to `modules.control.subscribe(key, type, callback)` (see `xref:../modules/GameControl.adoc[GameControl]`) correctly accept the `xref:GameEvent.adoc[GameEvent]` context.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
= Coordinate Reference
|
|
2
|
+
:description: A foundational 2D point interface used for positioning on grid or display.
|
|
3
|
+
:keywords: coordinate, point, position, 2d
|
|
4
|
+
:toc: left
|
|
5
|
+
:toclevels: 3
|
|
6
|
+
:sectnums:
|
|
7
|
+
:sectlinks:
|
|
8
|
+
:icons: font
|
|
9
|
+
:source-highlighter: highlight.js
|
|
10
|
+
:reproducible:
|
|
11
|
+
:experimental:
|
|
12
|
+
:idprefix:
|
|
13
|
+
:idseparator: -
|
|
14
|
+
|
|
15
|
+
A foundational 2D point interface used for positioning.
|
|
16
|
+
|
|
17
|
+
== Attributes
|
|
18
|
+
|
|
19
|
+
[cols="1,1,3"]
|
|
20
|
+
|===
|
|
21
|
+
|Name |Type |Description
|
|
22
|
+
|`x` |`number` |Horizontal axis value.
|
|
23
|
+
|`y` |`number` |Vertical axis value.
|
|
24
|
+
|===
|
|
25
|
+
|
|
26
|
+
== General Usage
|
|
27
|
+
|
|
28
|
+
Coordinates describe grid positions (columns/rows) as integers, or normalized screen positions as floats (0.0 to 1.0).
|
|
29
|
+
Use `xref:../helpers/CoordinateHelper.adoc[CoordinateHelper]` for translations between these systems.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
= GameEntry Reference
|
|
2
|
+
:description: Defines the structure for games registered in the engine's repository.
|
|
3
|
+
:keywords: game, entry, repository, structure
|
|
4
|
+
:toc: left
|
|
5
|
+
:toclevels: 3
|
|
6
|
+
:sectnums:
|
|
7
|
+
:sectlinks:
|
|
8
|
+
:icons: font
|
|
9
|
+
:source-highlighter: highlight.js
|
|
10
|
+
:reproducible:
|
|
11
|
+
:experimental:
|
|
12
|
+
:idprefix:
|
|
13
|
+
:idseparator: -
|
|
14
|
+
|
|
15
|
+
Defines the structure for games registered in the engine's repository.
|
|
16
|
+
|
|
17
|
+
== Attributes
|
|
18
|
+
|
|
19
|
+
[cols="1,1,3"]
|
|
20
|
+
|===
|
|
21
|
+
|Name |Type |Description
|
|
22
|
+
|`id` |`string` |The unique identifier of the game instance.
|
|
23
|
+
|`name` |`string` |The human-readable label for the game.
|
|
24
|
+
|`url` |`string` |The remote URL of the game's JavaScript bundle.
|
|
25
|
+
|===
|
|
26
|
+
|
|
27
|
+
== General Usage
|
|
28
|
+
|
|
29
|
+
The repository uses `GameEntry` to populate menu lists and manage the lifecycle of different game instances.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
= GameEvent Reference
|
|
2
|
+
:description: The context object delivered to input subscribers during events.
|
|
3
|
+
:keywords: event, input, subscriber, context
|
|
4
|
+
:toc: left
|
|
5
|
+
:toclevels: 3
|
|
6
|
+
:sectnums:
|
|
7
|
+
:sectlinks:
|
|
8
|
+
:icons: font
|
|
9
|
+
:source-highlighter: highlight.js
|
|
10
|
+
:reproducible:
|
|
11
|
+
:experimental:
|
|
12
|
+
:idprefix:
|
|
13
|
+
:idseparator: -
|
|
14
|
+
|
|
15
|
+
The context object delivered to input subscribers.
|
|
16
|
+
|
|
17
|
+
== Attributes
|
|
18
|
+
|
|
19
|
+
[cols="1,1,3"]
|
|
20
|
+
|===
|
|
21
|
+
|Name |Type |Description
|
|
22
|
+
|`key` |xref:../enums/ControlKey.adoc[ControlKey] |The identifier for the triggered key.
|
|
23
|
+
|`type` |xref:../enums/ControlEventType.adoc[ControlEventType] |Whether the key was `PRESSED` or is being `HELD`.
|
|
24
|
+
|`modules` |xref:../interfaces/GameModules.adoc[GameModules] |Accessor for all engine services.
|
|
25
|
+
|===
|
|
26
|
+
|
|
27
|
+
== General Usage
|
|
28
|
+
|
|
29
|
+
When a control callback is executed, it receives a `GameEvent`. This allows the game logic to react based on the key type and interact with the `xref:../interfaces/modules/Grid.adoc[Grid]`, `xref:../interfaces/modules/State.adoc[State]`, or `xref:../interfaces/modules/Score.adoc[Score]` modules.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
= Piece Reference
|
|
2
|
+
:description: Represents a collection of cells that form a game piece or "stamp".
|
|
3
|
+
:keywords: piece, stamp, cells, grid, collection
|
|
4
|
+
:toc: left
|
|
5
|
+
:toclevels: 3
|
|
6
|
+
:sectnums:
|
|
7
|
+
:sectlinks:
|
|
8
|
+
:icons: font
|
|
9
|
+
:source-highlighter: highlight.js
|
|
10
|
+
:reproducible:
|
|
11
|
+
:experimental:
|
|
12
|
+
:idprefix:
|
|
13
|
+
:idseparator: -
|
|
14
|
+
|
|
15
|
+
Represents a collection of `xref:Cell.adoc[Cell]` objects that form a cohesive game piece or a pattern to be "stamped" onto the grid.
|
|
16
|
+
|
|
17
|
+
== Definition
|
|
18
|
+
|
|
19
|
+
[source,typescript]
|
|
20
|
+
----
|
|
21
|
+
export type Piece = Cell[];
|
|
22
|
+
----
|
|
23
|
+
|
|
24
|
+
== General Usage
|
|
25
|
+
|
|
26
|
+
The `Piece` type is the main unit of interaction for complex grid operations. By working with an array of `xref:Cell.adoc[Cell]` instead of raw `xref:Coordinate.adoc[Coordinate]`, the engine can preserve properties like color and value during movement and transformation.
|
|
27
|
+
|
|
28
|
+
Common operations involving pieces include:
|
|
29
|
+
|
|
30
|
+
* **Stamping**: Permanently applying the piece's cells to the grid.
|
|
31
|
+
* **Movement**: Shifting all cells within a piece simultaneously while checking for collisions.
|
|
32
|
+
* **Transformation**: Rotating, mirroring, or projecting the piece onto different grid locations.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
= RendererMetrics Reference
|
|
2
|
+
:description: Defines the calculated dimensions and offsets for the physical layout.
|
|
3
|
+
:keywords: metrics, renderer, layout, dimensions, offsets
|
|
4
|
+
:toc: left
|
|
5
|
+
:toclevels: 3
|
|
6
|
+
:sectnums:
|
|
7
|
+
:sectlinks:
|
|
8
|
+
:icons: font
|
|
9
|
+
:source-highlighter: highlight.js
|
|
10
|
+
:reproducible:
|
|
11
|
+
:experimental:
|
|
12
|
+
:idprefix:
|
|
13
|
+
:idseparator: -
|
|
14
|
+
|
|
15
|
+
Defines the calculated dimensions and offsets for the physical layout.
|
|
16
|
+
|
|
17
|
+
== Attributes
|
|
18
|
+
|
|
19
|
+
[cols="1,1,3"]
|
|
20
|
+
|===
|
|
21
|
+
|Name |Type |Description
|
|
22
|
+
|`display` |`object` |Contains `width`, `height`, and `origin` (xref:Coordinate.adoc[Coordinate]) for the main screen.
|
|
23
|
+
|`hud` |`object` |Contains `width`, `height`, and `origin` (xref:Coordinate.adoc[Coordinate]) for the HUD area.
|
|
24
|
+
|`cell` |`object` |Contains the `size` (number) in pixels of a single grid cell.
|
|
25
|
+
|===
|
|
26
|
+
|
|
27
|
+
== General Usage
|
|
28
|
+
|
|
29
|
+
This data is calculated by the `xref:../modules/GameRenderer.adoc[GameRenderer]` and consumed by specialized sub-renderers like `xref:../modules/DisplayRenderer.adoc[DisplayRenderer]`, `xref:../modules/HudRenderer.adoc[HudRenderer]`, and `xref:../modules/GameText.adoc[GameText]` to ensure alignment.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
= Vector Reference
|
|
2
|
+
:description: Represents a generic 2D vector for directional or magnitude calculations.
|
|
3
|
+
:keywords: vector, direction, magnitude, 2d, transformation
|
|
4
|
+
:toc: left
|
|
5
|
+
:toclevels: 3
|
|
6
|
+
:sectnums:
|
|
7
|
+
:sectlinks:
|
|
8
|
+
:icons: font
|
|
9
|
+
:source-highlighter: highlight.js
|
|
10
|
+
:reproducible:
|
|
11
|
+
:experimental:
|
|
12
|
+
:idprefix:
|
|
13
|
+
:idseparator: -
|
|
14
|
+
|
|
15
|
+
Represents a generic 2D vector for directional or magnitude calculations.
|
|
16
|
+
|
|
17
|
+
== Attributes
|
|
18
|
+
|
|
19
|
+
[cols="1,1,3"]
|
|
20
|
+
|===
|
|
21
|
+
|Name |Type |Description
|
|
22
|
+
|`x` |`-1 \| 0 \| 1` |Horizontal direction offset.
|
|
23
|
+
|`y` |`-1 \| 0 \| 1` |Vertical direction offset.
|
|
24
|
+
|===
|
|
25
|
+
|
|
26
|
+
== General Usage
|
|
27
|
+
|
|
28
|
+
Unlike `xref:Coordinate.adoc[Coordinate]`, which usually implies a position, `Vector` is used for transformations, velocities, and offsets applied to coordinates.
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
= Testing Best Practices with Vitest
|
|
2
|
+
:toc: left
|
|
3
|
+
:icons: font
|
|
4
|
+
|
|
5
|
+
This document defines the standards and best practices for unit testing in the Brick Engine project using **Vitest**. It is designed to be easily parsed by both developers and AI assistants.
|
|
6
|
+
|
|
7
|
+
== Core Pattern: Triple A (AAA)
|
|
8
|
+
|
|
9
|
+
All tests must follow the **Arrange, Act, Assert** pattern. Use explicit comments to demarcate these phases, as this helps AI models understand the test logic context.
|
|
10
|
+
|
|
11
|
+
=== [ARRANGE]
|
|
12
|
+
Set up the test environment, prepare data, and initialize the object under test.
|
|
13
|
+
[source,typescript]
|
|
14
|
+
----
|
|
15
|
+
// [ARRANGE]
|
|
16
|
+
const grid = new GameGrid();
|
|
17
|
+
const coordinate = { x: 5, y: 5 };
|
|
18
|
+
----
|
|
19
|
+
|
|
20
|
+
=== [ACT]
|
|
21
|
+
Execute the specific method or behavior being tested. Limit this to a single action if possible.
|
|
22
|
+
[source,typescript]
|
|
23
|
+
----
|
|
24
|
+
// [ACT]
|
|
25
|
+
const result = grid.isValidCoordinate(coordinate);
|
|
26
|
+
----
|
|
27
|
+
|
|
28
|
+
=== [ASSERT]
|
|
29
|
+
Verify the outcome. Use descriptive expectations.
|
|
30
|
+
[source,typescript]
|
|
31
|
+
----
|
|
32
|
+
// [ASSERT]
|
|
33
|
+
expect(result).toBe(true);
|
|
34
|
+
----
|
|
35
|
+
|
|
36
|
+
== Naming Conventions
|
|
37
|
+
|
|
38
|
+
Test descriptions should follow the pattern: `should [expected result] when [scenario or action]`.
|
|
39
|
+
|
|
40
|
+
* *Bad:* `test grid validation`
|
|
41
|
+
* *Good:* `should return true when coordinate is within grid boundaries`
|
|
42
|
+
|
|
43
|
+
== AI-Assisted Testing Best Practices
|
|
44
|
+
|
|
45
|
+
To facilitate AI-driven test generation and debugging:
|
|
46
|
+
|
|
47
|
+
1. **Be Explicit**: Use the `// [ARRANGE]`, `// [ACT]`, and `// [ASSERT]` tags.
|
|
48
|
+
2. **Context Injection**: When asking an AI to write a test, provide the interface of the module and dependencies.
|
|
49
|
+
3. **One Logic per Test**: Avoid "Giant Tests". Test one specific behavior per `it` block.
|
|
50
|
+
4. **Mocking Constants**: Always mock global configurations (like `configs`) to ensure tests are deterministic.
|
|
51
|
+
|
|
52
|
+
== Vitest Configuration Standard
|
|
53
|
+
|
|
54
|
+
* **Globals**: Use `globals: true` to avoid importing `describe`, `it`, `expect` in every file.
|
|
55
|
+
* **Environment**: Use `@vitest-environment jsdom` at the top of files that interact with DOM or p5.js.
|
|
56
|
+
* **Coverage**: Target at least 80% coverage for "Engines" and "Helpers".
|
|
57
|
+
* **Aliases**: If using bundler aliases (e.g., `@client-game`), define them in `vitest.config.ts` using `resolve.alias`.
|
|
58
|
+
|
|
59
|
+
== Advanced Mocking & Stubs
|
|
60
|
+
|
|
61
|
+
=== Mocking Browser APIs
|
|
62
|
+
For tests requiring browser features in JSDOM:
|
|
63
|
+
|
|
64
|
+
[source,typescript]
|
|
65
|
+
----
|
|
66
|
+
// [ARRANGE]
|
|
67
|
+
vi.stubGlobal('localStorage', {
|
|
68
|
+
getItem: vi.fn(),
|
|
69
|
+
setItem: vi.fn(),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
vi.stubGlobal('AudioContext', vi.fn().mockImplementation(function() {
|
|
73
|
+
return {
|
|
74
|
+
createGain: vi.fn().mockReturnThis(),
|
|
75
|
+
destination: {},
|
|
76
|
+
};
|
|
77
|
+
}));
|
|
78
|
+
----
|
|
79
|
+
|
|
80
|
+
=== Constructible Mocks
|
|
81
|
+
When mocking a class that will be instantiated with `new`, Vitest requires the mock to be a `function` or `class`:
|
|
82
|
+
|
|
83
|
+
[source,typescript]
|
|
84
|
+
----
|
|
85
|
+
vi.mock('./MyModule', () => ({
|
|
86
|
+
default: vi.fn().mockImplementation(function() {
|
|
87
|
+
return {
|
|
88
|
+
doSomething: vi.fn()
|
|
89
|
+
};
|
|
90
|
+
})
|
|
91
|
+
}));
|
|
92
|
+
----
|
|
93
|
+
|
|
94
|
+
=== Hoisted Variables
|
|
95
|
+
If you need to share variables between your test and the `vi.mock` factory (which is hoisted), use `vi.hoisted`:
|
|
96
|
+
|
|
97
|
+
[source,typescript]
|
|
98
|
+
----
|
|
99
|
+
const { mockRef } = vi.hoisted(() => ({
|
|
100
|
+
mockRef: { id: 1 }
|
|
101
|
+
}));
|
|
102
|
+
|
|
103
|
+
vi.mock('./module', () => ({
|
|
104
|
+
default: () => mockRef
|
|
105
|
+
}));
|
|
106
|
+
----
|
|
107
|
+
|
|
108
|
+
== Testing Entry Points (main.ts)
|
|
109
|
+
|
|
110
|
+
Tests for entry points that execute code on import require isolation:
|
|
111
|
+
|
|
112
|
+
1. Use `vi.resetModules()` in `beforeEach`.
|
|
113
|
+
2. Use dynamic `import()` within the `it` block.
|
|
114
|
+
3. Set environment flags (like `APP_MODE`) *before* the dynamic import.
|
|
115
|
+
|
|
116
|
+
[source,typescript]
|
|
117
|
+
----
|
|
118
|
+
it('should init in client mode', async () => {
|
|
119
|
+
(isClientMode as vi.Mock).mockReturnValue(true);
|
|
120
|
+
await import('./main'); // Triggers execution
|
|
121
|
+
expect(p5).toHaveBeenCalled();
|
|
122
|
+
});
|
|
123
|
+
----
|
|
124
|
+
|
|
125
|
+
=== Workaround for Dynamic Imports with Webpack/TS (TS1323)
|
|
126
|
+
|
|
127
|
+
When the project uses a `tsconfig.json` meant for the browser (e.g., configuring `module: commonjs`), running bundlers like `webpack` over the test files can trigger **TS1323** because the TS compiler doesn't understand the dynamic inputs naturally.
|
|
128
|
+
|
|
129
|
+
**To resolve this properly without ANY `@ts-expect-error`:**
|
|
130
|
+
1. Set the `module` resolving option in `tsconfig.json` to `"ESNext"` or `"ES2020"` so TS allows dynamic imports. Webpack can still easily compile it targeting ES5.
|
|
131
|
+
2. Create ambient definition files (e.g., `src/client-game.d.ts`) containing module declarations (`declare module '@client-game';`) to resolve TS2307 dynamically missing paths.
|
|
132
|
+
|
|
133
|
+
[source,typescript]
|
|
134
|
+
----
|
|
135
|
+
it('should init in client mode', async () => {
|
|
136
|
+
// Both dynamic imports work natively without errors!
|
|
137
|
+
const { isClientMode } = await import('./config/env');
|
|
138
|
+
(isClientMode as unknown as Mock).mockReturnValue(true);
|
|
139
|
+
|
|
140
|
+
// Import and execute
|
|
141
|
+
await import('./main');
|
|
142
|
+
|
|
143
|
+
// ... assertions ...
|
|
144
|
+
});
|
|
145
|
+
----
|
|
146
|
+
|
|
147
|
+
== ESLint & Type Safety in Tests
|
|
148
|
+
|
|
149
|
+
Maintain code quality even in tests:
|
|
150
|
+
|
|
151
|
+
* **Avoid `any`**: Use `unknown as vi.Mock` or cast to specific interfaces.
|
|
152
|
+
* **Private Members**: Use `// @ts-expect-error` or `(instance as any)._privateProp` only when absolutely necessary to verify internal state, but prefer testing public behavior.
|
|
153
|
+
* **Mock Dependencies**: Mock sub-packages (e.g., `view` or `manager`) when testing core orchestrators to isolate logic.
|
|
154
|
+
|
|
155
|
+
== Example: Testing a Grid Engine
|
|
156
|
+
|
|
157
|
+
[source,typescript]
|
|
158
|
+
----
|
|
159
|
+
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
160
|
+
import GridAnalysisEngine from './GridAnalysisEngine';
|
|
161
|
+
import { Grid } from '../../../types/modules';
|
|
162
|
+
|
|
163
|
+
describe('GridAnalysisEngine', () => {
|
|
164
|
+
let engine: GridAnalysisEngine;
|
|
165
|
+
let mockGrid: Grid;
|
|
166
|
+
|
|
167
|
+
beforeEach(() => {
|
|
168
|
+
// [ARRANGE]
|
|
169
|
+
mockGrid = {
|
|
170
|
+
width: 10,
|
|
171
|
+
height: 20,
|
|
172
|
+
isCellActive: vi.fn(),
|
|
173
|
+
// ... other properties
|
|
174
|
+
} as unknown as Grid;
|
|
175
|
+
engine = new GridAnalysisEngine(mockGrid);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('should identify full rows when all cells in a row are active', () => {
|
|
179
|
+
// [ARRANGE]
|
|
180
|
+
vi.mocked(mockGrid.isCellActive).mockImplementation(({ y }) => y === 5);
|
|
181
|
+
|
|
182
|
+
// [ACT]
|
|
183
|
+
const fullRows = engine.getFullRows();
|
|
184
|
+
|
|
185
|
+
// [ASSERT]
|
|
186
|
+
expect(fullRows).toContain(5);
|
|
187
|
+
expect(fullRows.length).toBe(1);
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
----
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import globals from 'globals';
|
|
2
|
+
import pluginJs from '@eslint/js';
|
|
3
|
+
import tseslint from 'typescript-eslint';
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
{
|
|
7
|
+
ignores: ['dist/', 'node_modules/', 'docs/', 'public/docs/', 'scripts/'],
|
|
8
|
+
},
|
|
9
|
+
// Base config for all files
|
|
10
|
+
pluginJs.configs.recommended,
|
|
11
|
+
...tseslint.configs.recommended,
|
|
12
|
+
|
|
13
|
+
// Browser globals for most files
|
|
14
|
+
{
|
|
15
|
+
files: ['**/*.{js,mjs,cjs,ts}'],
|
|
16
|
+
languageOptions: { globals: globals.browser },
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
// Node globals for config files
|
|
20
|
+
{
|
|
21
|
+
files: ['**/webpack.config.js', 'eslint.config.mjs'],
|
|
22
|
+
languageOptions: { globals: globals.node },
|
|
23
|
+
rules: {
|
|
24
|
+
'@typescript-eslint/no-require-imports': 'off',
|
|
25
|
+
'@typescript-eslint/no-var-requires': 'off',
|
|
26
|
+
'no-undef': 'off', // globals.node should handle this, but just in case
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
];
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "brick-engine-js",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A lightweight brick engine built with p5.js and TypeScript",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "dist/brick-engine.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"license": "ISC",
|
|
9
|
+
"author": "LeonardoPinheiroLacerda",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"start": "webpack serve --open",
|
|
12
|
+
"build": "webpack --mode production && npm run docs:build",
|
|
13
|
+
"build:types": "tsc --emitDeclarationOnly",
|
|
14
|
+
"lint": "eslint .",
|
|
15
|
+
"format": "npx prettier -w .",
|
|
16
|
+
"format:check": "npx prettier -c .",
|
|
17
|
+
"docs:diagram": "./scripts/generate-diagrams.sh",
|
|
18
|
+
"docs:build": "node ./scripts/generate-docs.js",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"test:watch": "vitest",
|
|
21
|
+
"coverage": "vitest run --coverage",
|
|
22
|
+
"prepublishOnly": "npm run build && npm run build:types"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"colord": "^2.9.3",
|
|
26
|
+
"p5": "^2.2.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@eslint/js": "^10.0.1",
|
|
30
|
+
"@types/p5": "^1.7.7",
|
|
31
|
+
"@types/webpack-env": "^1.18.8",
|
|
32
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
33
|
+
"asciidoctor": "^3.0.4",
|
|
34
|
+
"copy-webpack-plugin": "^13.0.1",
|
|
35
|
+
"css-loader": "^7.1.3",
|
|
36
|
+
"dotenv": "^17.3.1",
|
|
37
|
+
"eslint": "^10.0.0",
|
|
38
|
+
"globals": "^17.3.0",
|
|
39
|
+
"html-webpack-plugin": "^5.6.6",
|
|
40
|
+
"jsdom": "^28.1.0",
|
|
41
|
+
"mini-css-extract-plugin": "^2.10.0",
|
|
42
|
+
"prettier": "^3.8.1",
|
|
43
|
+
"ts-loader": "^9.5.4",
|
|
44
|
+
"typescript": "^5.9.3",
|
|
45
|
+
"typescript-eslint": "^8.56.0",
|
|
46
|
+
"vitest": "^4.0.18",
|
|
47
|
+
"webpack": "^5.105.1",
|
|
48
|
+
"webpack-cli": "^6.0.1",
|
|
49
|
+
"webpack-dev-server": "^5.2.3"
|
|
50
|
+
},
|
|
51
|
+
"overrides": {
|
|
52
|
+
"minimatch": "^10.2.1"
|
|
53
|
+
}
|
|
54
|
+
}
|
package/public/CNAME
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
brickengine.com.br
|