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,157 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import GridAnalysisEngine from './GridAnalysisEngine';
|
|
3
|
+
import { Grid } from '../../../types/modules';
|
|
4
|
+
import { Color } from '../../../types/enums';
|
|
5
|
+
|
|
6
|
+
describe('GridAnalysisEngine', () => {
|
|
7
|
+
let engine: GridAnalysisEngine;
|
|
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
|
+
getCell: vi.fn(),
|
|
18
|
+
stampCell: vi.fn(),
|
|
19
|
+
} as unknown as Grid;
|
|
20
|
+
engine = new GridAnalysisEngine(mockGrid);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('getFullRows', () => {
|
|
24
|
+
it('should return indices of rows where all cells are active', () => {
|
|
25
|
+
// [ARRANGE] Row 2 is full, others are not
|
|
26
|
+
vi.mocked(mockGrid.isCellActive).mockImplementation(({ y }) => y === 2);
|
|
27
|
+
|
|
28
|
+
// [ACT]
|
|
29
|
+
const result = engine.getFullRows();
|
|
30
|
+
|
|
31
|
+
// [ASSERT]
|
|
32
|
+
expect(result).toEqual([2]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should return an empty array if no rows are full', () => {
|
|
36
|
+
// [ARRANGE]
|
|
37
|
+
vi.mocked(mockGrid.isCellActive).mockReturnValue(false);
|
|
38
|
+
|
|
39
|
+
// [ACT]
|
|
40
|
+
const result = engine.getFullRows();
|
|
41
|
+
|
|
42
|
+
// [ASSERT]
|
|
43
|
+
expect(result).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('getFullColumns', () => {
|
|
48
|
+
it('should return indices of columns where all cells are active', () => {
|
|
49
|
+
// [ARRANGE] Column 5 is full
|
|
50
|
+
vi.mocked(mockGrid.isCellActive).mockImplementation(({ x }) => x === 5);
|
|
51
|
+
|
|
52
|
+
// [ACT]
|
|
53
|
+
const result = engine.getFullColumns();
|
|
54
|
+
|
|
55
|
+
// [ASSERT]
|
|
56
|
+
expect(result).toEqual([5]);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('getNeighbors', () => {
|
|
61
|
+
it('should return only orthogonally adjacent cells by default', () => {
|
|
62
|
+
// [ARRANGE]
|
|
63
|
+
const coord = { x: 5, y: 5 };
|
|
64
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
65
|
+
vi.mocked(mockGrid.getCell).mockImplementation(c => ({ coordinate: c, value: 1, color: Color.DEFAULT }));
|
|
66
|
+
|
|
67
|
+
// [ACT]
|
|
68
|
+
const result = engine.getNeighbors(coord);
|
|
69
|
+
|
|
70
|
+
// [ASSERT]
|
|
71
|
+
expect(result).toHaveLength(4);
|
|
72
|
+
expect(result.map(c => c.coordinate)).toContainEqual({ x: 4, y: 5 });
|
|
73
|
+
expect(result.map(c => c.coordinate)).toContainEqual({ x: 6, y: 5 });
|
|
74
|
+
expect(result.map(c => c.coordinate)).toContainEqual({ x: 5, y: 4 });
|
|
75
|
+
expect(result.map(c => c.coordinate)).toContainEqual({ x: 5, y: 6 });
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should return 8 neighbors if includeDiagonal is true', () => {
|
|
79
|
+
// [ARRANGE]
|
|
80
|
+
const coord = { x: 5, y: 5 };
|
|
81
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
82
|
+
vi.mocked(mockGrid.getCell).mockImplementation(c => ({ coordinate: c, value: 1, color: Color.DEFAULT }));
|
|
83
|
+
|
|
84
|
+
// [ACT]
|
|
85
|
+
const result = engine.getNeighbors(coord, true);
|
|
86
|
+
|
|
87
|
+
// [ASSERT]
|
|
88
|
+
expect(result).toHaveLength(8);
|
|
89
|
+
expect(result.map(c => c.coordinate)).toContainEqual({ x: 4, y: 4 });
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should skip invalid coordinates (e.g., edges)', () => {
|
|
93
|
+
// [ARRANGE] Center at (0,0)
|
|
94
|
+
const coord = { x: 0, y: 0 };
|
|
95
|
+
vi.mocked(mockGrid.isValidCoordinate).mockImplementation(c => c.x >= 0 && c.y >= 0);
|
|
96
|
+
vi.mocked(mockGrid.getCell).mockImplementation(c => ({ coordinate: c, value: 1, color: Color.DEFAULT }));
|
|
97
|
+
|
|
98
|
+
// [ACT]
|
|
99
|
+
const result = engine.getNeighbors(coord);
|
|
100
|
+
|
|
101
|
+
// [ASSERT]
|
|
102
|
+
// Only (1,0) and (0,1) are valid
|
|
103
|
+
expect(result).toHaveLength(2);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('findConnectedCells', () => {
|
|
108
|
+
it('should return an empty array if starting cell is inactive', () => {
|
|
109
|
+
// [ARRANGE]
|
|
110
|
+
vi.mocked(mockGrid.isCellActive).mockReturnValue(false);
|
|
111
|
+
|
|
112
|
+
// [ACT]
|
|
113
|
+
const result = engine.findConnectedCells({ x: 5, y: 5 });
|
|
114
|
+
|
|
115
|
+
// [ASSERT]
|
|
116
|
+
expect(result).toEqual([]);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should find all connected cells with the same value using BFS', () => {
|
|
120
|
+
// [ARRANGE] Simple 2x1 block
|
|
121
|
+
const start = { x: 5, y: 5 };
|
|
122
|
+
const neighbor = { x: 6, y: 5 };
|
|
123
|
+
|
|
124
|
+
vi.mocked(mockGrid.isCellActive).mockImplementation(c => (c.x === 5 && c.y === 5) || (c.x === 6 && c.y === 5));
|
|
125
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
126
|
+
vi.mocked(mockGrid.getCell).mockImplementation(c => ({ coordinate: c, value: 1, color: Color.RED }));
|
|
127
|
+
|
|
128
|
+
// [ACT]
|
|
129
|
+
const result = engine.findConnectedCells(start);
|
|
130
|
+
|
|
131
|
+
// [ASSERT]
|
|
132
|
+
expect(result).toHaveLength(2);
|
|
133
|
+
expect(result.map(c => c.coordinate)).toContainEqual(start);
|
|
134
|
+
expect(result.map(c => c.coordinate)).toContainEqual(neighbor);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('swapCells', () => {
|
|
139
|
+
it('should swap attributes of two cells using stampCell', () => {
|
|
140
|
+
// [ARRANGE]
|
|
141
|
+
const a = { x: 1, y: 1 };
|
|
142
|
+
const b = { x: 2, y: 2 };
|
|
143
|
+
const cellA = { coordinate: a, value: 1, color: Color.RED };
|
|
144
|
+
const cellB = { coordinate: b, value: 2, color: Color.BLUE };
|
|
145
|
+
|
|
146
|
+
vi.mocked(mockGrid.getCell).mockImplementation(c => (c.x === 1 ? cellA : cellB));
|
|
147
|
+
|
|
148
|
+
// [ACT]
|
|
149
|
+
engine.swapCells(a, b);
|
|
150
|
+
|
|
151
|
+
// [ASSERT]
|
|
152
|
+
// Stamp cellB at a, and cellA at b
|
|
153
|
+
expect(mockGrid.stampCell).toHaveBeenCalledWith({ ...cellB, coordinate: a });
|
|
154
|
+
expect(mockGrid.stampCell).toHaveBeenCalledWith({ ...cellA, coordinate: b });
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Cell, Coordinate, Piece } from '../../../types/Types';
|
|
2
|
+
import { Grid } from '../../../types/modules';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Handles analysis and search operations on the grid.
|
|
6
|
+
*/
|
|
7
|
+
export default class GridAnalysisEngine {
|
|
8
|
+
constructor(private grid: Grid) {}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Identifies all rows that are completely filled with active cells.
|
|
12
|
+
*/
|
|
13
|
+
getFullRows(): number[] {
|
|
14
|
+
const fullRows: number[] = [];
|
|
15
|
+
for (let y = 0; y < this.grid.height; y++) {
|
|
16
|
+
let isFull = true;
|
|
17
|
+
for (let x = 0; x < this.grid.width; x++) {
|
|
18
|
+
if (!this.grid.isCellActive({ x, y })) {
|
|
19
|
+
isFull = false;
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (isFull) fullRows.push(y);
|
|
24
|
+
}
|
|
25
|
+
return fullRows;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Identifies all columns that are completely filled with active cells.
|
|
30
|
+
*/
|
|
31
|
+
getFullColumns(): number[] {
|
|
32
|
+
const fullColumns: number[] = [];
|
|
33
|
+
for (let x = 0; x < this.grid.width; x++) {
|
|
34
|
+
let isFull = true;
|
|
35
|
+
for (let y = 0; y < this.grid.height; y++) {
|
|
36
|
+
if (!this.grid.isCellActive({ x, y })) {
|
|
37
|
+
isFull = false;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (isFull) fullColumns.push(x);
|
|
42
|
+
}
|
|
43
|
+
return fullColumns;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Returns the active cells adjacent to a specific coordinate.
|
|
48
|
+
*/
|
|
49
|
+
getNeighbors(coord: Coordinate, includeDiagonal: boolean = false): Cell[] {
|
|
50
|
+
const neighbors: Cell[] = [];
|
|
51
|
+
const offsets = [
|
|
52
|
+
{ x: -1, y: 0 },
|
|
53
|
+
{ x: 1, y: 0 },
|
|
54
|
+
{ x: 0, y: -1 },
|
|
55
|
+
{ x: 0, y: 1 },
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
if (includeDiagonal) {
|
|
59
|
+
offsets.push({ x: -1, y: -1 }, { x: 1, y: -1 }, { x: -1, y: 1 }, { x: 1, y: 1 });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
offsets.forEach(offset => {
|
|
63
|
+
const neighborCoord = { x: coord.x + offset.x, y: coord.y + offset.y };
|
|
64
|
+
if (this.grid.isValidCoordinate(neighborCoord)) {
|
|
65
|
+
neighbors.push(this.grid.getCell(neighborCoord));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return neighbors;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Finds all connected active cells of the same value starting from a specific coordinate.
|
|
74
|
+
*/
|
|
75
|
+
findConnectedCells(coord: Coordinate): Piece {
|
|
76
|
+
if (!this.grid.isCellActive(coord)) return [];
|
|
77
|
+
|
|
78
|
+
const startCell = this.grid.getCell(coord);
|
|
79
|
+
const targetValue = startCell.value;
|
|
80
|
+
const connected: Piece = [];
|
|
81
|
+
const visited = new Set<string>();
|
|
82
|
+
const queue: Coordinate[] = [coord];
|
|
83
|
+
|
|
84
|
+
const getCoordKey = (c: Coordinate) => `${c.x},${c.y}`;
|
|
85
|
+
visited.add(getCoordKey(coord));
|
|
86
|
+
|
|
87
|
+
while (queue.length > 0) {
|
|
88
|
+
const current = queue.shift()!;
|
|
89
|
+
const cell = this.grid.getCell(current);
|
|
90
|
+
|
|
91
|
+
if (cell.value === targetValue) {
|
|
92
|
+
connected.push(cell);
|
|
93
|
+
|
|
94
|
+
const neighbors = [
|
|
95
|
+
{ x: current.x - 1, y: current.y },
|
|
96
|
+
{ x: current.x + 1, y: current.y },
|
|
97
|
+
{ x: current.x, y: current.y - 1 },
|
|
98
|
+
{ x: current.x, y: current.y + 1 },
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
neighbors.forEach(n => {
|
|
102
|
+
const key = getCoordKey(n);
|
|
103
|
+
if (this.grid.isValidCoordinate(n) && !visited.has(key) && this.grid.isCellActive(n)) {
|
|
104
|
+
visited.add(key);
|
|
105
|
+
queue.push(n);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return connected;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Swaps the values and colors of two cells.
|
|
116
|
+
*/
|
|
117
|
+
swapCells(a: Coordinate, b: Coordinate): void {
|
|
118
|
+
const cellA = { ...this.grid.getCell(a) };
|
|
119
|
+
const cellB = { ...this.grid.getCell(b) };
|
|
120
|
+
|
|
121
|
+
this.grid.stampCell({ ...cellB, coordinate: a });
|
|
122
|
+
this.grid.stampCell({ ...cellA, coordinate: b });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import GridLineEngine from './GridLineEngine';
|
|
3
|
+
import { Grid } from '../../../types/modules';
|
|
4
|
+
import { Color } from '../../../types/enums';
|
|
5
|
+
import { Cell } from '../../../types/Types';
|
|
6
|
+
|
|
7
|
+
describe('GridLineEngine', () => {
|
|
8
|
+
let engine: GridLineEngine;
|
|
9
|
+
let mockGrid: Grid;
|
|
10
|
+
let gridData: Cell[][];
|
|
11
|
+
|
|
12
|
+
const createSmallGrid = (w: number, h: number) => {
|
|
13
|
+
const data: Cell[][] = [];
|
|
14
|
+
for (let y = 0; y < h; y++) {
|
|
15
|
+
data[y] = [];
|
|
16
|
+
for (let x = 0; x < w; x++) {
|
|
17
|
+
data[y][x] = { coordinate: { x, y }, value: 0, color: Color.DEFAULT };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return data;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
gridData = createSmallGrid(3, 3);
|
|
25
|
+
mockGrid = {
|
|
26
|
+
width: 3,
|
|
27
|
+
height: 3,
|
|
28
|
+
getGrid: () => gridData,
|
|
29
|
+
} as unknown as Grid;
|
|
30
|
+
engine = new GridLineEngine(mockGrid);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('isRowFull', () => {
|
|
34
|
+
it('should return true if all cells in a row have value > 0', () => {
|
|
35
|
+
// [ARRANGE]
|
|
36
|
+
gridData[1].forEach(c => (c.value = 1));
|
|
37
|
+
|
|
38
|
+
// [ACT]
|
|
39
|
+
const result = engine.isRowFull(1);
|
|
40
|
+
|
|
41
|
+
// [ASSERT]
|
|
42
|
+
expect(result).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should return false if any cell in a row has value 0', () => {
|
|
46
|
+
// [ARRANGE]
|
|
47
|
+
gridData[1][0].value = 1;
|
|
48
|
+
gridData[1][1].value = 0; // one empty
|
|
49
|
+
|
|
50
|
+
// [ACT]
|
|
51
|
+
const result = engine.isRowFull(1);
|
|
52
|
+
|
|
53
|
+
// [ASSERT]
|
|
54
|
+
expect(result).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('clearRow', () => {
|
|
59
|
+
it('should reset all cells in a row to value 0', () => {
|
|
60
|
+
// [ARRANGE]
|
|
61
|
+
gridData[1].forEach(c => (c.value = 5));
|
|
62
|
+
|
|
63
|
+
// [ACT]
|
|
64
|
+
engine.clearRow(1);
|
|
65
|
+
|
|
66
|
+
// [ASSERT]
|
|
67
|
+
expect(gridData[1].every(c => c.value === 0)).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('shiftRowsDown', () => {
|
|
72
|
+
it('should copy values from row above and clear top row', () => {
|
|
73
|
+
// [ARRANGE]
|
|
74
|
+
gridData[0][0].value = 9; // top row
|
|
75
|
+
gridData[1][0].value = 0; // target row
|
|
76
|
+
|
|
77
|
+
// [ACT]
|
|
78
|
+
engine.shiftRowsDown(1);
|
|
79
|
+
|
|
80
|
+
// [ASSERT]
|
|
81
|
+
expect(gridData[1][0].value).toBe(9);
|
|
82
|
+
expect(gridData[0][0].value).toBe(0); // top row cleared
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('clearFullRows', () => {
|
|
87
|
+
it('should detect, clear, and shift rows, returning count', () => {
|
|
88
|
+
// [ARRANGE]
|
|
89
|
+
// Row 2 is full
|
|
90
|
+
gridData[2].forEach(c => (c.value = 1));
|
|
91
|
+
// Row 1 has a pattern
|
|
92
|
+
gridData[1][0].value = 7;
|
|
93
|
+
|
|
94
|
+
// [ACT]
|
|
95
|
+
const cleared = engine.clearFullRows();
|
|
96
|
+
|
|
97
|
+
// [ASSERT]
|
|
98
|
+
expect(cleared).toBe(1);
|
|
99
|
+
expect(gridData[2][0].value).toBe(7); // row 1 shifted to row 2
|
|
100
|
+
expect(gridData[1][0].value).toBe(0); // top row (originally 0 or 1) cleared
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('isColumnFull', () => {
|
|
105
|
+
it('should return true if all cells in a column have value > 0', () => {
|
|
106
|
+
// [ARRANGE]
|
|
107
|
+
gridData[0][0].value = 1;
|
|
108
|
+
gridData[1][0].value = 1;
|
|
109
|
+
gridData[2][0].value = 1;
|
|
110
|
+
|
|
111
|
+
// [ACT]
|
|
112
|
+
const result = engine.isColumnFull(0);
|
|
113
|
+
|
|
114
|
+
// [ASSERT]
|
|
115
|
+
expect(result).toBe(true);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('shiftColumnsRight', () => {
|
|
120
|
+
it('should copy values from left and clear first column', () => {
|
|
121
|
+
// [ARRANGE]
|
|
122
|
+
gridData[0][0].value = 8;
|
|
123
|
+
|
|
124
|
+
// [ACT]
|
|
125
|
+
engine.shiftColumnsRight(1);
|
|
126
|
+
|
|
127
|
+
// [ASSERT]
|
|
128
|
+
expect(gridData[0][1].value).toBe(8);
|
|
129
|
+
expect(gridData[0][0].value).toBe(0);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { Grid } from '../../../types/modules';
|
|
2
|
+
import CellHelper from '../../../helpers/CellHelper';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Handles line-based operations (rows and columns) on the grid.
|
|
6
|
+
*/
|
|
7
|
+
export default class GridLineEngine {
|
|
8
|
+
constructor(private grid: Grid) {}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Checks if every cell in a specific row is active.
|
|
12
|
+
*/
|
|
13
|
+
isRowFull(y: number): boolean {
|
|
14
|
+
const gridData = this.grid.getGrid();
|
|
15
|
+
if (y < 0 || y >= this.grid.height) return false;
|
|
16
|
+
return gridData[y].every(cell => cell.value > 0);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Checks if every cell in a specific row is inactive.
|
|
21
|
+
*/
|
|
22
|
+
isRowEmpty(y: number): boolean {
|
|
23
|
+
const gridData = this.grid.getGrid();
|
|
24
|
+
if (y < 0 || y >= this.grid.height) return true;
|
|
25
|
+
return gridData[y].every(cell => cell.value === 0);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Resets all cells in a specific row to their default empty state.
|
|
30
|
+
*/
|
|
31
|
+
clearRow(y: number): void {
|
|
32
|
+
const gridData = this.grid.getGrid();
|
|
33
|
+
if (y < 0 || y >= this.grid.height) return;
|
|
34
|
+
for (let x = 0; x < this.grid.width; x++) {
|
|
35
|
+
gridData[y][x] = CellHelper.emptyCell({ x, y });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Shifts all rows above a certain index down by one position.
|
|
41
|
+
*/
|
|
42
|
+
shiftRowsDown(fromY: number): void {
|
|
43
|
+
const gridData = this.grid.getGrid();
|
|
44
|
+
for (let y = fromY; y > 0; y--) {
|
|
45
|
+
for (let x = 0; x < this.grid.width; x++) {
|
|
46
|
+
const prevCell = gridData[y - 1][x];
|
|
47
|
+
gridData[y][x].value = prevCell.value;
|
|
48
|
+
gridData[y][x].color = prevCell.color;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
this.clearRow(0);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Shifts all rows below a certain index up by one position.
|
|
56
|
+
*/
|
|
57
|
+
shiftRowsUp(fromY: number): void {
|
|
58
|
+
const gridData = this.grid.getGrid();
|
|
59
|
+
for (let y = fromY; y < this.grid.height - 1; y++) {
|
|
60
|
+
for (let x = 0; x < this.grid.width; x++) {
|
|
61
|
+
const nextCell = gridData[y + 1][x];
|
|
62
|
+
gridData[y][x].value = nextCell.value;
|
|
63
|
+
gridData[y][x].color = nextCell.color;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
this.clearRow(this.grid.height - 1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Scans for full rows, clears them, and shifts remaining rows down.
|
|
71
|
+
*/
|
|
72
|
+
clearFullRows(): number {
|
|
73
|
+
let rowsCleared = 0;
|
|
74
|
+
for (let y = this.grid.height - 1; y >= 0; y--) {
|
|
75
|
+
if (this.isRowFull(y)) {
|
|
76
|
+
this.clearRow(y);
|
|
77
|
+
this.shiftRowsDown(y);
|
|
78
|
+
rowsCleared++;
|
|
79
|
+
y++; // Re-check the same row index after shifting
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return rowsCleared;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Checks if every cell in a specific column is active.
|
|
87
|
+
*/
|
|
88
|
+
isColumnFull(x: number): boolean {
|
|
89
|
+
const gridData = this.grid.getGrid();
|
|
90
|
+
if (x < 0 || x >= this.grid.width) return false;
|
|
91
|
+
for (let y = 0; y < this.grid.height; y++) {
|
|
92
|
+
if (gridData[y][x].value === 0) return false;
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Checks if every cell in a specific column is inactive.
|
|
99
|
+
*/
|
|
100
|
+
isColumnEmpty(x: number): boolean {
|
|
101
|
+
const gridData = this.grid.getGrid();
|
|
102
|
+
if (x < 0 || x >= this.grid.width) return true;
|
|
103
|
+
for (let y = 0; y < this.grid.height; y++) {
|
|
104
|
+
if (gridData[y][x].value !== 0) return false;
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Resets all cells in a specific column to their default empty state.
|
|
111
|
+
*/
|
|
112
|
+
clearColumn(x: number): void {
|
|
113
|
+
const gridData = this.grid.getGrid();
|
|
114
|
+
if (x < 0 || x >= this.grid.width) return;
|
|
115
|
+
for (let y = 0; y < this.grid.height; y++) {
|
|
116
|
+
gridData[y][x] = CellHelper.emptyCell({ x, y });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Shifts all columns to the left of a certain index one position to the right.
|
|
122
|
+
*/
|
|
123
|
+
shiftColumnsRight(fromX: number): void {
|
|
124
|
+
const gridData = this.grid.getGrid();
|
|
125
|
+
for (let x = fromX; x > 0; x--) {
|
|
126
|
+
for (let y = 0; y < this.grid.height; y++) {
|
|
127
|
+
const prevCell = gridData[y][x - 1];
|
|
128
|
+
gridData[y][x].value = prevCell.value;
|
|
129
|
+
gridData[y][x].color = prevCell.color;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.clearColumn(0);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Shifts all columns to the right of a certain index one position to the left.
|
|
137
|
+
*/
|
|
138
|
+
shiftColumnsLeft(fromX: number): void {
|
|
139
|
+
const gridData = this.grid.getGrid();
|
|
140
|
+
for (let x = fromX; x < this.grid.width - 1; x++) {
|
|
141
|
+
for (let y = 0; y < this.grid.height; y++) {
|
|
142
|
+
const nextCell = gridData[y][x + 1];
|
|
143
|
+
gridData[y][x].value = nextCell.value;
|
|
144
|
+
gridData[y][x].color = nextCell.color;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
this.clearColumn(this.grid.width - 1);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Scans for full columns, clears them, and shifts remaining columns right.
|
|
152
|
+
*/
|
|
153
|
+
clearFullColumns(): number {
|
|
154
|
+
let columnsCleared = 0;
|
|
155
|
+
for (let x = this.grid.width - 1; x >= 0; x--) {
|
|
156
|
+
if (this.isColumnFull(x)) {
|
|
157
|
+
this.clearColumn(x);
|
|
158
|
+
this.shiftColumnsRight(x);
|
|
159
|
+
columnsCleared++;
|
|
160
|
+
x++; // Re-check the same column index after shifting
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return columnsCleared;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import GridMovementEngine from './GridMovementEngine';
|
|
3
|
+
import { Grid } from '../../../types/modules';
|
|
4
|
+
import { Color } from '../../../types/enums';
|
|
5
|
+
import { Vector, Coordinate } from '../../../types/Types';
|
|
6
|
+
|
|
7
|
+
describe('GridMovementEngine', () => {
|
|
8
|
+
let engine: GridMovementEngine;
|
|
9
|
+
let mockGrid: Grid;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
// [ARRANGE] Mock Grid facade
|
|
13
|
+
mockGrid = {
|
|
14
|
+
isValidCoordinate: vi.fn(),
|
|
15
|
+
isCellActive: vi.fn(),
|
|
16
|
+
} as unknown as Grid;
|
|
17
|
+
engine = new GridMovementEngine(mockGrid);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('movePiece', () => {
|
|
21
|
+
it('should return a new piece shifted in the specified direction', () => {
|
|
22
|
+
// [ARRANGE]
|
|
23
|
+
const piece = [{ coordinate: { x: 5, y: 5 }, value: 1, color: Color.RED }];
|
|
24
|
+
const direction: Vector = { x: 1, y: 0 };
|
|
25
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
26
|
+
vi.mocked(mockGrid.isCellActive).mockReturnValue(false);
|
|
27
|
+
|
|
28
|
+
// [ACT]
|
|
29
|
+
const result = engine.movePiece(piece, direction);
|
|
30
|
+
|
|
31
|
+
// [ASSERT]
|
|
32
|
+
expect(result).not.toBeNull();
|
|
33
|
+
expect(result![0].coordinate).toEqual({ x: 6, y: 5 });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should return null if the move is out of bounds', () => {
|
|
37
|
+
// [ARRANGE]
|
|
38
|
+
const piece = [{ coordinate: { x: 0, y: 0 }, value: 1, color: Color.RED }];
|
|
39
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(false);
|
|
40
|
+
|
|
41
|
+
// [ACT]
|
|
42
|
+
const result = engine.movePieceLeft(piece);
|
|
43
|
+
|
|
44
|
+
// [ASSERT]
|
|
45
|
+
expect(result).toBeNull();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should return null if it collides with an active cell that is NOT part of self', () => {
|
|
49
|
+
// [ARRANGE]
|
|
50
|
+
const piece = [{ coordinate: { x: 5, y: 5 }, value: 1, color: Color.RED }];
|
|
51
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
52
|
+
vi.mocked(mockGrid.isCellActive).mockReturnValue(true); // Obstacle at (6,5)
|
|
53
|
+
|
|
54
|
+
// [ACT]
|
|
55
|
+
const result = engine.movePieceRight(piece);
|
|
56
|
+
|
|
57
|
+
// [ASSERT]
|
|
58
|
+
expect(result).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should NOT return null if it collides with its own current position (diagonal or overlapping)', () => {
|
|
62
|
+
// [ARRANGE] Piece with 2 cells
|
|
63
|
+
const piece = [
|
|
64
|
+
{ coordinate: { x: 5, y: 5 }, value: 1, color: Color.RED },
|
|
65
|
+
{ coordinate: { x: 6, y: 5 }, value: 1, color: Color.RED },
|
|
66
|
+
];
|
|
67
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
68
|
+
|
|
69
|
+
// isCellActive is true for (5,5) and (6,5)
|
|
70
|
+
vi.mocked(mockGrid.isCellActive).mockImplementation((c: Coordinate) => c.x === 5 || c.x === 6);
|
|
71
|
+
|
|
72
|
+
// [ACT] Move right: (5,5)->(6,5) and (6,5)->(7,5)
|
|
73
|
+
// (6,5) is active, but it matches the original piece's second cell
|
|
74
|
+
const result = engine.movePieceRight(piece);
|
|
75
|
+
|
|
76
|
+
// [ASSERT]
|
|
77
|
+
expect(result).not.toBeNull();
|
|
78
|
+
expect(result![0].coordinate).toEqual({ x: 6, y: 5 });
|
|
79
|
+
expect(result![1].coordinate).toEqual({ x: 7, y: 5 });
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('getDropPath', () => {
|
|
84
|
+
it('should return the furthest possible position downwards', () => {
|
|
85
|
+
// [ARRANGE]
|
|
86
|
+
const piece = [{ coordinate: { x: 5, y: 0 }, value: 1, color: Color.RED }];
|
|
87
|
+
vi.mocked(mockGrid.isValidCoordinate).mockImplementation((c: Coordinate) => c.y >= 0 && c.y <= 10);
|
|
88
|
+
vi.mocked(mockGrid.isCellActive).mockReturnValue(false);
|
|
89
|
+
|
|
90
|
+
// [ACT]
|
|
91
|
+
const result = engine.getDropPath(piece);
|
|
92
|
+
|
|
93
|
+
// [ASSERT]
|
|
94
|
+
expect(result[0].coordinate.y).toBe(10);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('moveCell', () => {
|
|
99
|
+
it('should move a single cell if path is clear', () => {
|
|
100
|
+
// [ARRANGE]
|
|
101
|
+
const cell = { coordinate: { x: 1, y: 1 }, value: 1, color: Color.RED };
|
|
102
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
103
|
+
vi.mocked(mockGrid.isCellActive).mockReturnValue(false);
|
|
104
|
+
|
|
105
|
+
// [ACT]
|
|
106
|
+
const result = engine.moveCellDown(cell);
|
|
107
|
+
|
|
108
|
+
// [ASSERT]
|
|
109
|
+
expect(result?.coordinate).toEqual({ x: 1, y: 2 });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should return null if single cell path is blocked', () => {
|
|
113
|
+
// [ARRANGE]
|
|
114
|
+
const cell = { coordinate: { x: 1, y: 1 }, value: 1, color: Color.RED };
|
|
115
|
+
vi.mocked(mockGrid.isValidCoordinate).mockReturnValue(true);
|
|
116
|
+
vi.mocked(mockGrid.isCellActive).mockReturnValue(true);
|
|
117
|
+
|
|
118
|
+
// [ACT]
|
|
119
|
+
const result = engine.moveCellDown(cell);
|
|
120
|
+
|
|
121
|
+
// [ASSERT]
|
|
122
|
+
expect(result).toBeNull();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|