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,113 @@
|
|
|
1
|
+
import { Cell, Coordinate, Vector, Piece } from '../../../types/Types';
|
|
2
|
+
import { Grid } from '../../../types/modules';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Handles movement and projection logic for the game grid.
|
|
6
|
+
*/
|
|
7
|
+
export default class GridMovementEngine {
|
|
8
|
+
constructor(private grid: Grid) {}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Attempts to shift a collection of cells (a piece) in a given direction.
|
|
12
|
+
*/
|
|
13
|
+
movePiece(piece: Piece, direction: Vector): Piece | null {
|
|
14
|
+
const newPiece: Piece = piece.map(cell => ({
|
|
15
|
+
...cell,
|
|
16
|
+
coordinate: {
|
|
17
|
+
x: cell.coordinate.x + (direction.x || 0),
|
|
18
|
+
y: cell.coordinate.y + (direction.y || 0),
|
|
19
|
+
},
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
const isPartofSelf = (coord: Coordinate) => piece.some(c => c.coordinate.x === coord.x && c.coordinate.y === coord.y);
|
|
23
|
+
|
|
24
|
+
const isInvalid = newPiece.some(cell => {
|
|
25
|
+
if (!this.grid.isValidCoordinate(cell.coordinate)) return true;
|
|
26
|
+
return this.grid.isCellActive(cell.coordinate) && !isPartofSelf(cell.coordinate);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return isInvalid ? null : newPiece;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
movePieceLeft(piece: Piece): Piece | null {
|
|
33
|
+
return this.movePiece(piece, { x: -1, y: 0 });
|
|
34
|
+
}
|
|
35
|
+
movePieceRight(piece: Piece): Piece | null {
|
|
36
|
+
return this.movePiece(piece, { x: 1, y: 0 });
|
|
37
|
+
}
|
|
38
|
+
movePieceUp(piece: Piece): Piece | null {
|
|
39
|
+
return this.movePiece(piece, { x: 0, y: -1 });
|
|
40
|
+
}
|
|
41
|
+
movePieceDown(piece: Piece): Piece | null {
|
|
42
|
+
return this.movePiece(piece, { x: 0, y: 1 });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Attempts to shift a single cell in a given direction.
|
|
47
|
+
*/
|
|
48
|
+
moveCell(cell: Cell, direction: Vector): Cell | null {
|
|
49
|
+
const newCoord = {
|
|
50
|
+
x: cell.coordinate.x + (direction.x || 0),
|
|
51
|
+
y: cell.coordinate.y + (direction.y || 0),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
if (!this.grid.isValidCoordinate(newCoord) || this.grid.isCellActive(newCoord)) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return { ...cell, coordinate: newCoord };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
moveCellLeft(cell: Cell): Cell | null {
|
|
62
|
+
return this.moveCell(cell, { x: -1, y: 0 });
|
|
63
|
+
}
|
|
64
|
+
moveCellRight(cell: Cell): Cell | null {
|
|
65
|
+
return this.moveCell(cell, { x: 1, y: 0 });
|
|
66
|
+
}
|
|
67
|
+
moveCellUp(cell: Cell): Cell | null {
|
|
68
|
+
return this.moveCell(cell, { x: 0, y: -1 });
|
|
69
|
+
}
|
|
70
|
+
moveCellDown(cell: Cell): Cell | null {
|
|
71
|
+
return this.moveCell(cell, { x: 0, y: 1 });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getDropPath(piece: Piece): Piece {
|
|
75
|
+
let currentPiece = piece;
|
|
76
|
+
let nextPiece = this.movePieceDown(currentPiece);
|
|
77
|
+
while (nextPiece !== null) {
|
|
78
|
+
currentPiece = nextPiece;
|
|
79
|
+
nextPiece = this.movePieceDown(currentPiece);
|
|
80
|
+
}
|
|
81
|
+
return currentPiece;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getRisePath(piece: Piece): Piece {
|
|
85
|
+
let currentPiece = piece;
|
|
86
|
+
let nextPiece = this.movePieceUp(currentPiece);
|
|
87
|
+
while (nextPiece !== null) {
|
|
88
|
+
currentPiece = nextPiece;
|
|
89
|
+
nextPiece = this.movePieceUp(currentPiece);
|
|
90
|
+
}
|
|
91
|
+
return currentPiece;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getReachPathLeft(piece: Piece): Piece {
|
|
95
|
+
let currentPiece = piece;
|
|
96
|
+
let nextPiece = this.movePieceLeft(currentPiece);
|
|
97
|
+
while (nextPiece !== null) {
|
|
98
|
+
currentPiece = nextPiece;
|
|
99
|
+
nextPiece = this.movePieceLeft(currentPiece);
|
|
100
|
+
}
|
|
101
|
+
return currentPiece;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getReachPathRight(piece: Piece): Piece {
|
|
105
|
+
let currentPiece = piece;
|
|
106
|
+
let nextPiece = this.movePieceRight(currentPiece);
|
|
107
|
+
while (nextPiece !== null) {
|
|
108
|
+
currentPiece = nextPiece;
|
|
109
|
+
nextPiece = this.movePieceRight(currentPiece);
|
|
110
|
+
}
|
|
111
|
+
return currentPiece;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import GridRegionEngine from './GridRegionEngine';
|
|
3
|
+
import { Grid } from '../../../types/modules';
|
|
4
|
+
import { Color } from '../../../types/enums';
|
|
5
|
+
|
|
6
|
+
describe('GridRegionEngine', () => {
|
|
7
|
+
let engine: GridRegionEngine;
|
|
8
|
+
let mockGrid: Grid;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
// [ARRANGE] Mock Grid facade
|
|
12
|
+
mockGrid = {
|
|
13
|
+
width: 10,
|
|
14
|
+
height: 20,
|
|
15
|
+
isValidCoordinate: vi.fn(),
|
|
16
|
+
isCellActive: vi.fn(),
|
|
17
|
+
setCellValue: vi.fn(),
|
|
18
|
+
setCellColor: vi.fn(),
|
|
19
|
+
stampCell: vi.fn(),
|
|
20
|
+
} as unknown as Grid;
|
|
21
|
+
engine = new GridRegionEngine(mockGrid);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('isAreaOccupied', () => {
|
|
25
|
+
it('should return true if any coordinate is out of bounds', () => {
|
|
26
|
+
// [ARRANGE]
|
|
27
|
+
const coords = [
|
|
28
|
+
{ x: 0, y: 0 },
|
|
29
|
+
{ x: -1, y: 0 },
|
|
30
|
+
];
|
|
31
|
+
vi.mocked(mockGrid.isValidCoordinate).mockImplementation(c => c.x >= 0);
|
|
32
|
+
|
|
33
|
+
// [ACT]
|
|
34
|
+
const result = engine.isAreaOccupied(coords);
|
|
35
|
+
|
|
36
|
+
// [ASSERT]
|
|
37
|
+
expect(result).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should return true if any coordinate is already active', () => {
|
|
41
|
+
// [ARRANGE]
|
|
42
|
+
const coords = [
|
|
43
|
+
{ x: 1, y: 1 },
|
|
44
|
+
{ x: 2, y: 2 },
|
|
45
|
+
];
|
|
46
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
47
|
+
vi.mocked(mockGrid.isCellActive).mockImplementation(c => c.x === 2);
|
|
48
|
+
|
|
49
|
+
// [ACT]
|
|
50
|
+
const result = engine.isAreaOccupied(coords);
|
|
51
|
+
|
|
52
|
+
// [ASSERT]
|
|
53
|
+
expect(result).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should return false if all coordinates are valid and inactive', () => {
|
|
57
|
+
// [ARRANGE]
|
|
58
|
+
const coords = [
|
|
59
|
+
{ x: 1, y: 1 },
|
|
60
|
+
{ x: 2, y: 2 },
|
|
61
|
+
];
|
|
62
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
63
|
+
vi.mocked(mockGrid.isCellActive).mockReturnValue(false);
|
|
64
|
+
|
|
65
|
+
// [ACT]
|
|
66
|
+
const result = engine.isAreaOccupied(coords);
|
|
67
|
+
|
|
68
|
+
// [ASSERT]
|
|
69
|
+
expect(result).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('fillArea', () => {
|
|
74
|
+
it('should call setCellValue and setCellColor for every cell in the defined rectangle', () => {
|
|
75
|
+
// [ARRANGE]
|
|
76
|
+
const start = { x: 1, y: 1 };
|
|
77
|
+
const end = { x: 2, y: 2 };
|
|
78
|
+
const value = 5;
|
|
79
|
+
const color = Color.RED;
|
|
80
|
+
|
|
81
|
+
// [ACT]
|
|
82
|
+
engine.fillArea(start, end, value, color);
|
|
83
|
+
|
|
84
|
+
// [ASSERT]
|
|
85
|
+
// (1,1), (1,2), (2,1), (2,2) -> 4 cells
|
|
86
|
+
expect(mockGrid.setCellValue).toHaveBeenCalledTimes(4);
|
|
87
|
+
expect(mockGrid.setCellValue).toHaveBeenCalledWith({ x: 1, y: 1 }, 5);
|
|
88
|
+
expect(mockGrid.setCellColor).toHaveBeenCalledWith({ x: 1, y: 1 }, Color.RED);
|
|
89
|
+
expect(mockGrid.setCellValue).toHaveBeenCalledWith({ x: 2, y: 2 }, 5);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should handle coordinates provided in reverse order', () => {
|
|
93
|
+
// [ARRANGE]
|
|
94
|
+
const start = { x: 2, y: 2 };
|
|
95
|
+
const end = { x: 1, y: 1 };
|
|
96
|
+
|
|
97
|
+
// [ACT]
|
|
98
|
+
engine.fillArea(start, end, 5, Color.RED);
|
|
99
|
+
|
|
100
|
+
// [ASSERT]
|
|
101
|
+
expect(mockGrid.setCellValue).toHaveBeenCalledTimes(4);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe('stampPiece', () => {
|
|
106
|
+
it('should call grid.stampCell for each cell in the piece', () => {
|
|
107
|
+
// [ARRANGE]
|
|
108
|
+
const piece = [
|
|
109
|
+
{ coordinate: { x: 1, y: 1 }, value: 1, color: Color.RED },
|
|
110
|
+
{ coordinate: { x: 1, y: 2 }, value: 1, color: Color.RED },
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
// [ACT]
|
|
114
|
+
engine.stampPiece(piece);
|
|
115
|
+
|
|
116
|
+
// [ASSERT]
|
|
117
|
+
expect(mockGrid.stampCell).toHaveBeenCalledTimes(2);
|
|
118
|
+
expect(mockGrid.stampCell).toHaveBeenCalledWith(piece[0]);
|
|
119
|
+
expect(mockGrid.stampCell).toHaveBeenCalledWith(piece[1]);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('stampCell', () => {
|
|
124
|
+
it('should delegate to setCellValue and setCellColor', () => {
|
|
125
|
+
// [ARRANGE]
|
|
126
|
+
const cell = { coordinate: { x: 5, y: 5 }, value: 2, color: Color.BLUE };
|
|
127
|
+
|
|
128
|
+
// [ACT]
|
|
129
|
+
engine.stampCell(cell);
|
|
130
|
+
|
|
131
|
+
// [ASSERT]
|
|
132
|
+
expect(mockGrid.setCellValue).toHaveBeenCalledWith({ x: 5, y: 5 }, 2);
|
|
133
|
+
expect(mockGrid.setCellColor).toHaveBeenCalledWith({ x: 5, y: 5 }, Color.BLUE);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Color } from '../../../types/enums';
|
|
2
|
+
import { Cell, Coordinate, Piece } from '../../../types/Types';
|
|
3
|
+
import { Grid } from '../../../types/modules';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Handles region-based operations (areas, stamps, and occupancy) on the grid.
|
|
7
|
+
*/
|
|
8
|
+
export default class GridRegionEngine {
|
|
9
|
+
constructor(private grid: Grid) {}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Checks if any of the provided coordinates are already occupied or out of bounds.
|
|
13
|
+
*/
|
|
14
|
+
isAreaOccupied(coordinates: Coordinate[]): boolean {
|
|
15
|
+
return coordinates.some(coord => {
|
|
16
|
+
if (!this.grid.isValidCoordinate(coord)) return true;
|
|
17
|
+
return this.grid.isCellActive(coord);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Fills a rectangular region defined by two corners with a specific value and color.
|
|
23
|
+
*/
|
|
24
|
+
fillArea(start: Coordinate, end: Coordinate, value: number, color: Color): void {
|
|
25
|
+
const xMin = Math.max(0, Math.min(start.x, end.x));
|
|
26
|
+
const xMax = Math.min(this.grid.width - 1, Math.max(start.x, end.x));
|
|
27
|
+
const yMin = Math.max(0, Math.min(start.y, end.y));
|
|
28
|
+
const yMax = Math.min(this.grid.height - 1, Math.max(start.y, end.y));
|
|
29
|
+
|
|
30
|
+
for (let y = yMin; y <= yMax; y++) {
|
|
31
|
+
for (let x = xMin; x <= xMax; x++) {
|
|
32
|
+
this.grid.setCellValue({ x, y }, value);
|
|
33
|
+
this.grid.setCellColor({ x, y }, color);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Updates multiple coordinates simultaneously with their specific values and colors.
|
|
40
|
+
*/
|
|
41
|
+
stampPiece(piece: Piece): void {
|
|
42
|
+
piece.forEach(cell => this.grid.stampCell(cell));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Updates a single coordinate with a specific value and color from a Cell.
|
|
47
|
+
*/
|
|
48
|
+
stampCell(cell: Cell): void {
|
|
49
|
+
this.grid.setCellValue(cell.coordinate, cell.value);
|
|
50
|
+
this.grid.setCellColor(cell.coordinate, cell.color);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import GridTransformEngine from './GridTransformEngine';
|
|
3
|
+
import { Grid } from '../../../types/modules';
|
|
4
|
+
import { Color } from '../../../types/enums';
|
|
5
|
+
|
|
6
|
+
describe('GridTransformEngine', () => {
|
|
7
|
+
let engine: GridTransformEngine;
|
|
8
|
+
let mockGrid: Grid;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
// [ARRANGE] Mock Grid facade
|
|
12
|
+
mockGrid = {
|
|
13
|
+
isValidCoordinate: vi.fn(),
|
|
14
|
+
isCellActive: vi.fn(),
|
|
15
|
+
} as unknown as Grid;
|
|
16
|
+
engine = new GridTransformEngine(mockGrid);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('rotatePiece', () => {
|
|
20
|
+
it('should rotate a piece 90 degrees clockwise around origin', () => {
|
|
21
|
+
// [ARRANGE]
|
|
22
|
+
// Origin (5,5), Cell at (5,4) (above)
|
|
23
|
+
// Clockwise rotation should move it to (6,5) (right)
|
|
24
|
+
const piece = [{ coordinate: { x: 5, y: 4 }, value: 1, color: Color.RED }];
|
|
25
|
+
const origin = { x: 5, y: 5 };
|
|
26
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
27
|
+
vi.mocked(mockGrid.isCellActive).mockReturnValue(false);
|
|
28
|
+
|
|
29
|
+
// [ACT]
|
|
30
|
+
const result = engine.rotatePiece(piece, origin, true);
|
|
31
|
+
|
|
32
|
+
// [ASSERT]
|
|
33
|
+
expect(result).not.toBeNull();
|
|
34
|
+
expect(result![0].coordinate).toEqual({ x: 6, y: 5 });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should return null if rotation results in a collision', () => {
|
|
38
|
+
// [ARRANGE]
|
|
39
|
+
const piece = [{ coordinate: { x: 5, y: 4 }, value: 1, color: Color.RED }];
|
|
40
|
+
const origin = { x: 5, y: 5 };
|
|
41
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
42
|
+
vi.mocked(mockGrid.isCellActive).mockReturnValue(true); // Obstacle at (6,5)
|
|
43
|
+
|
|
44
|
+
// [ACT]
|
|
45
|
+
const result = engine.rotatePiece(piece, origin, true);
|
|
46
|
+
|
|
47
|
+
// [ASSERT]
|
|
48
|
+
expect(result).toBeNull();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('getPieceBounds', () => {
|
|
53
|
+
it('should return correct min and max coordinates', () => {
|
|
54
|
+
// [ARRANGE]
|
|
55
|
+
const piece = [
|
|
56
|
+
{ coordinate: { x: 1, y: 10 }, value: 1, color: Color.RED },
|
|
57
|
+
{ coordinate: { x: 5, y: 2 }, value: 1, color: Color.RED },
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
// [ACT]
|
|
61
|
+
const bounds = engine.getPieceBounds(piece);
|
|
62
|
+
|
|
63
|
+
// [ASSERT]
|
|
64
|
+
expect(bounds.min).toEqual({ x: 1, y: 2 });
|
|
65
|
+
expect(bounds.max).toEqual({ x: 5, y: 10 });
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('mirrorPiece', () => {
|
|
70
|
+
it('should mirror piece across X axis (horizontal mirror)', () => {
|
|
71
|
+
// [ARRANGE]
|
|
72
|
+
// Piece at X: 1, 2, 3. Center is 2.
|
|
73
|
+
// 1 mirrors to 3, 2 stays 2, 3 mirrors to 1.
|
|
74
|
+
const piece = [
|
|
75
|
+
{ coordinate: { x: 1, y: 1 }, value: 1, color: Color.RED },
|
|
76
|
+
{ coordinate: { x: 3, y: 1 }, value: 1, color: Color.RED },
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
// [ACT]
|
|
80
|
+
const result = engine.mirrorPiece(piece, 'x');
|
|
81
|
+
|
|
82
|
+
// [ASSERT]
|
|
83
|
+
expect(result.map(c => c.coordinate.x)).toContain(1);
|
|
84
|
+
expect(result.map(c => c.coordinate.x)).toContain(3);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should handle single cell pieces for mirroring', () => {
|
|
88
|
+
// [ARRANGE]
|
|
89
|
+
const piece = [{ coordinate: { x: 5, y: 5 }, value: 1, color: Color.RED }];
|
|
90
|
+
|
|
91
|
+
// [ACT]
|
|
92
|
+
const result = engine.mirrorPiece(piece, 'y');
|
|
93
|
+
|
|
94
|
+
// [ASSERT]
|
|
95
|
+
expect(result[0].coordinate).toEqual({ x: 5, y: 5 });
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Coordinate, Axis, Piece } from '../../../types/Types';
|
|
2
|
+
import { Grid } from '../../../types/modules';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Handles geometric transformations for pieces on the grid.
|
|
6
|
+
*/
|
|
7
|
+
export default class GridTransformEngine {
|
|
8
|
+
constructor(private grid: Grid) {}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Attempts to rotate a piece 90 degrees around a specific origin.
|
|
12
|
+
*/
|
|
13
|
+
rotatePiece(piece: Piece, origin: Coordinate, clockwise: boolean = true): Piece | null {
|
|
14
|
+
const newPiece: Piece = piece.map(cell => {
|
|
15
|
+
const relX = cell.coordinate.x - origin.x;
|
|
16
|
+
const relY = cell.coordinate.y - origin.y;
|
|
17
|
+
|
|
18
|
+
const newRelX = clockwise ? -relY : relY;
|
|
19
|
+
const newRelY = clockwise ? relX : -relX;
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
...cell,
|
|
23
|
+
coordinate: {
|
|
24
|
+
x: origin.x + newRelX,
|
|
25
|
+
y: origin.y + newRelY,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const isPartofSelf = (coord: Coordinate) => piece.some(c => c.coordinate.x === coord.x && c.coordinate.y === coord.y);
|
|
31
|
+
|
|
32
|
+
const isInvalid = newPiece.some(cell => {
|
|
33
|
+
if (!this.grid.isValidCoordinate(cell.coordinate)) return true;
|
|
34
|
+
return this.grid.isCellActive(cell.coordinate) && !isPartofSelf(cell.coordinate);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return isInvalid ? null : newPiece;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Mirrors a piece across a specific axis relative to its bounding box.
|
|
42
|
+
*/
|
|
43
|
+
mirrorPiece(piece: Piece, axis: Axis): Piece {
|
|
44
|
+
if (piece.length === 0) return [];
|
|
45
|
+
|
|
46
|
+
const bounds = this.getPieceBounds(piece);
|
|
47
|
+
const center = axis === 'x' ? (bounds.min.x + bounds.max.x) / 2 : (bounds.min.y + bounds.max.y) / 2;
|
|
48
|
+
|
|
49
|
+
return piece.map(cell => ({
|
|
50
|
+
...cell,
|
|
51
|
+
coordinate: {
|
|
52
|
+
x: axis === 'x' ? Math.round(2 * center - cell.coordinate.x) : cell.coordinate.x,
|
|
53
|
+
y: axis === 'y' ? Math.round(2 * center - cell.coordinate.y) : cell.coordinate.y,
|
|
54
|
+
},
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Calculates the bounding box of a piece.
|
|
60
|
+
*/
|
|
61
|
+
getPieceBounds(piece: Piece): { min: Coordinate; max: Coordinate } {
|
|
62
|
+
const xs = piece.map(c => c.coordinate.x);
|
|
63
|
+
const ys = piece.map(c => c.coordinate.y);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
min: { x: Math.min(...xs), y: Math.min(...ys) },
|
|
67
|
+
max: { x: Math.max(...xs), y: Math.max(...ys) },
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import type p5 from 'p5';
|
|
3
|
+
import DisplayRenderer from './DisplayRenderer';
|
|
4
|
+
import { Color } from '../../types/enums';
|
|
5
|
+
import { GameModules } from '../../types/Types';
|
|
6
|
+
import { State } from '../../types/modules';
|
|
7
|
+
|
|
8
|
+
describe('DisplayRenderer', () => {
|
|
9
|
+
let renderer: DisplayRenderer;
|
|
10
|
+
let mockP5: Record<string, unknown>;
|
|
11
|
+
let mockGraphics: Record<string, unknown>;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
mockGraphics = {
|
|
15
|
+
background: vi.fn(),
|
|
16
|
+
strokeWeight: vi.fn(),
|
|
17
|
+
noFill: vi.fn(),
|
|
18
|
+
stroke: vi.fn(),
|
|
19
|
+
rect: vi.fn(),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
mockP5 = {
|
|
23
|
+
createGraphics: vi.fn().mockReturnValue(mockGraphics),
|
|
24
|
+
push: vi.fn(),
|
|
25
|
+
pop: vi.fn(),
|
|
26
|
+
image: vi.fn(),
|
|
27
|
+
translate: vi.fn(),
|
|
28
|
+
strokeWeight: vi.fn(),
|
|
29
|
+
stroke: vi.fn(),
|
|
30
|
+
noFill: vi.fn(),
|
|
31
|
+
rect: vi.fn(),
|
|
32
|
+
fill: vi.fn(),
|
|
33
|
+
width: 1000,
|
|
34
|
+
height: 1000,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
renderer = new DisplayRenderer(mockP5 as unknown as p5);
|
|
38
|
+
renderer.setup({
|
|
39
|
+
display: { width: 600, height: 900, origin: { x: 50, y: 50 } },
|
|
40
|
+
hud: { width: 400, height: 900, origin: { x: 650, y: 50 } },
|
|
41
|
+
cell: { size: 50 },
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('render', () => {
|
|
46
|
+
it('should draw static background and then grid cells', () => {
|
|
47
|
+
// [ARRANGE]
|
|
48
|
+
const grid = [[{ coordinate: { x: 0, y: 0 }, value: 1, color: Color.RED }]];
|
|
49
|
+
const mockModules = {
|
|
50
|
+
state: { isColorEnabled: () => true, isPlaying: () => true },
|
|
51
|
+
} as unknown as GameModules;
|
|
52
|
+
|
|
53
|
+
// [ACT]
|
|
54
|
+
renderer.render(grid, mockModules);
|
|
55
|
+
|
|
56
|
+
// [ASSERT]
|
|
57
|
+
expect(mockP5.image).toHaveBeenCalledWith(mockGraphics, 0, 0);
|
|
58
|
+
expect(mockP5.translate).toHaveBeenCalledWith(50, 50); // display origin + 0*50
|
|
59
|
+
expect(mockP5.rect).toHaveBeenCalled();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('renderCell', () => {
|
|
64
|
+
it('should use DEFAULT color if color mode is disabled', () => {
|
|
65
|
+
const cell = { coordinate: { x: 0, y: 0 }, value: 1, color: Color.RED };
|
|
66
|
+
const mockState = { isColorEnabled: () => false, isPlaying: () => true } as unknown as State;
|
|
67
|
+
|
|
68
|
+
// [ACT]
|
|
69
|
+
(renderer as unknown as { renderCell: (c: unknown, s: unknown) => void })['renderCell'](cell, mockState);
|
|
70
|
+
|
|
71
|
+
// [ASSERT]
|
|
72
|
+
expect(mockP5.stroke).toHaveBeenCalledWith(Color.DEFAULT);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should use INACTIVE color if cell value is 0', () => {
|
|
76
|
+
const cell = { coordinate: { x: 0, y: 0 }, value: 0, color: Color.RED };
|
|
77
|
+
const mockState = { isColorEnabled: () => true, isPlaying: () => true } as unknown as State;
|
|
78
|
+
|
|
79
|
+
// [ACT]
|
|
80
|
+
(renderer as unknown as { renderCell: (c: unknown, s: unknown) => void })['renderCell'](cell, mockState);
|
|
81
|
+
|
|
82
|
+
// [ASSERT]
|
|
83
|
+
expect(mockP5.stroke).toHaveBeenCalledWith(Color.INACTIVE);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|