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,610 @@
|
|
|
1
|
+
import configs from '../../../config/configs';
|
|
2
|
+
import { Color } from '../../types/enums';
|
|
3
|
+
import CellHelper from '../../helpers/CellHelper';
|
|
4
|
+
import { Cell, Coordinate, Vector, Piece, Axis } from '../../types/Types';
|
|
5
|
+
import { Debuggable } from '../../types/Interfaces';
|
|
6
|
+
import { Grid } from '../../types/modules';
|
|
7
|
+
import GridMovementEngine from './engines/GridMovementEngine';
|
|
8
|
+
import GridTransformEngine from './engines/GridTransformEngine';
|
|
9
|
+
import GridAnalysisEngine from './engines/GridAnalysisEngine';
|
|
10
|
+
import GridLineEngine from './engines/GridLineEngine';
|
|
11
|
+
import GridRegionEngine from './engines/GridRegionEngine';
|
|
12
|
+
import { Serializable } from '../../types/Interfaces';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Manages the game's logical grid state and operations.
|
|
16
|
+
*
|
|
17
|
+
* Provides a robust API for cell manipulation, row/column management,
|
|
18
|
+
* collision detection, and mass grid modifications.
|
|
19
|
+
*/
|
|
20
|
+
export default class GameGrid implements Grid, Debuggable, Serializable {
|
|
21
|
+
/**
|
|
22
|
+
* The internal 2D array representing the game grid [y][x].
|
|
23
|
+
*/
|
|
24
|
+
protected _grid: Cell[][] = [];
|
|
25
|
+
|
|
26
|
+
private _movementEngine: GridMovementEngine;
|
|
27
|
+
private _transformEngine: GridTransformEngine;
|
|
28
|
+
private _analysisEngine: GridAnalysisEngine;
|
|
29
|
+
private _lineEngine: GridLineEngine;
|
|
30
|
+
private _regionEngine: GridRegionEngine;
|
|
31
|
+
|
|
32
|
+
serialId: string = 'grid';
|
|
33
|
+
|
|
34
|
+
constructor() {
|
|
35
|
+
this._movementEngine = new GridMovementEngine(this);
|
|
36
|
+
this._transformEngine = new GridTransformEngine(this);
|
|
37
|
+
this._analysisEngine = new GridAnalysisEngine(this);
|
|
38
|
+
this._lineEngine = new GridLineEngine(this);
|
|
39
|
+
this._regionEngine = new GridRegionEngine(this);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// --- CORE & UTILITIES ---
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Gets the current grid state as a 2D array of cells.
|
|
46
|
+
*
|
|
47
|
+
* @returns {Cell[][]} The underlying grid data.
|
|
48
|
+
*/
|
|
49
|
+
getGrid(): Cell[][] {
|
|
50
|
+
return this._grid;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Gets the number of columns in the grid.
|
|
55
|
+
*
|
|
56
|
+
* @returns {number} The grid width.
|
|
57
|
+
*/
|
|
58
|
+
get width(): number {
|
|
59
|
+
return configs.screenLayout.grid.columns;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Gets the number of rows in the grid.
|
|
64
|
+
*
|
|
65
|
+
* @returns {number} The grid height.
|
|
66
|
+
*/
|
|
67
|
+
get height(): number {
|
|
68
|
+
return configs.screenLayout.grid.rows;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Initializes the grid by resetting its content to an empty state.
|
|
73
|
+
*
|
|
74
|
+
* @returns {void}
|
|
75
|
+
*/
|
|
76
|
+
setup(): void {
|
|
77
|
+
this.resetGrid();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Resets the entire grid state based on the dimensions defined in the configuration.
|
|
82
|
+
*
|
|
83
|
+
* Populates the grid with empty cells using {@link CellHelper.emptyCell}.
|
|
84
|
+
*
|
|
85
|
+
* @returns {void}
|
|
86
|
+
*/
|
|
87
|
+
resetGrid(): void {
|
|
88
|
+
this._grid = [];
|
|
89
|
+
for (let y = 0; y < this.height; y++) {
|
|
90
|
+
this._grid[y] = [];
|
|
91
|
+
for (let x = 0; x < this.width; x++) {
|
|
92
|
+
this._grid[y][x] = CellHelper.emptyCell({ x, y });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Iterates over every cell in the grid and executes a callback.
|
|
99
|
+
*
|
|
100
|
+
* @param {function(Cell): void} callback - The function to execute for each cell.
|
|
101
|
+
* @returns {void}
|
|
102
|
+
*/
|
|
103
|
+
forEach(callback: (cell: Cell) => void): void {
|
|
104
|
+
for (let y = 0; y < this.height; y++) {
|
|
105
|
+
for (let x = 0; x < this.width; x++) {
|
|
106
|
+
callback(this._grid[y][x]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Verifies if a given coordinate is within the grid boundaries.
|
|
113
|
+
*
|
|
114
|
+
* @param {Coordinate} coordinate - The coordinate to validate.
|
|
115
|
+
* @returns {boolean} True if the coordinate is valid, false otherwise.
|
|
116
|
+
*/
|
|
117
|
+
isValidCoordinate(coordinate: Coordinate): boolean {
|
|
118
|
+
return coordinate.x >= 0 && coordinate.x < this.width && coordinate.y >= 0 && coordinate.y < this.height;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Retrieves a cell at a specific coordinate.
|
|
123
|
+
*
|
|
124
|
+
* @param {Coordinate} coordinate - The coordinate of the cell.
|
|
125
|
+
* @returns {Cell | null} The cell object, or null if out of bounds.
|
|
126
|
+
*/
|
|
127
|
+
getCell(coordinate: Coordinate): Cell | null {
|
|
128
|
+
if (!this.isValidCoordinate(coordinate)) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
return this._grid[coordinate.y][coordinate.x];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Updates the status value of a cell at a specific coordinate.
|
|
136
|
+
*
|
|
137
|
+
* @param {Coordinate} coordinate - The target coordinate.
|
|
138
|
+
* @param {number} value - The new value (e.g., 0 for inactive, >0 for active).
|
|
139
|
+
* @returns {void}
|
|
140
|
+
*/
|
|
141
|
+
setCellValue(coordinate: Coordinate, value: number): void {
|
|
142
|
+
if (!this.isValidCoordinate(coordinate)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
this._grid[coordinate.y][coordinate.x].value = value;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Updates the color of a cell at a specific coordinate.
|
|
150
|
+
*
|
|
151
|
+
* @param {Coordinate} coordinate - The target coordinate.
|
|
152
|
+
* @param {Color} color - The new color enum value.
|
|
153
|
+
* @returns {void}
|
|
154
|
+
*/
|
|
155
|
+
setCellColor(coordinate: Coordinate, color: Color): void {
|
|
156
|
+
if (!this.isValidCoordinate(coordinate)) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
this._grid[coordinate.y][coordinate.x].color = color;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a cell at a specific coordinate is active (value > 0).
|
|
164
|
+
*
|
|
165
|
+
* @param {Coordinate} coordinate - The coordinate to check.
|
|
166
|
+
* @returns {boolean} True if active, false otherwise.
|
|
167
|
+
*/
|
|
168
|
+
isCellActive(coordinate: Coordinate): boolean {
|
|
169
|
+
const cell = this.getCell(coordinate);
|
|
170
|
+
return cell !== null && cell.value > 0;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Checks if a cell at a specific coordinate is inactive (value === 0).
|
|
175
|
+
*
|
|
176
|
+
* @param {Coordinate} coordinate - The coordinate to check.
|
|
177
|
+
* @returns {boolean} True if inactive, false otherwise.
|
|
178
|
+
*/
|
|
179
|
+
isCellInactive(coordinate: Coordinate): boolean {
|
|
180
|
+
const cell = this.getCell(coordinate);
|
|
181
|
+
return cell !== null && cell.value === 0;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// --- ROW OPERATIONS ---
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Checks if every cell in a specific row is active.
|
|
188
|
+
*
|
|
189
|
+
* @param {number} y - The row index.
|
|
190
|
+
* @returns {boolean} True if the row is completely full.
|
|
191
|
+
*/
|
|
192
|
+
isRowFull(y: number): boolean {
|
|
193
|
+
return this._lineEngine.isRowFull(y);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Checks if every cell in a specific row is inactive.
|
|
198
|
+
*
|
|
199
|
+
* @param {number} y - The row index.
|
|
200
|
+
* @returns {boolean} True if the row is completely empty.
|
|
201
|
+
*/
|
|
202
|
+
isRowEmpty(y: number): boolean {
|
|
203
|
+
return this._lineEngine.isRowEmpty(y);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Resets all cells in a specific row to their default empty state.
|
|
208
|
+
*
|
|
209
|
+
* @param {number} y - The row index to clear.
|
|
210
|
+
* @returns {void}
|
|
211
|
+
*/
|
|
212
|
+
clearRow(y: number): void {
|
|
213
|
+
this._lineEngine.clearRow(y);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Shifts all rows above a certain index down by one position.
|
|
218
|
+
*
|
|
219
|
+
* Clears the top-most row after shifting.
|
|
220
|
+
*
|
|
221
|
+
* @param {number} fromY - The starting row index for the shift down.
|
|
222
|
+
* @returns {void}
|
|
223
|
+
*/
|
|
224
|
+
shiftRowsDown(fromY: number): void {
|
|
225
|
+
this._lineEngine.shiftRowsDown(fromY);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Shifts all rows below a certain index up by one position.
|
|
230
|
+
*
|
|
231
|
+
* Clears the bottom-most row after shifting.
|
|
232
|
+
*
|
|
233
|
+
* @param {number} fromY - The starting row index for the shift up.
|
|
234
|
+
* @returns {void}
|
|
235
|
+
*/
|
|
236
|
+
shiftRowsUp(fromY: number): void {
|
|
237
|
+
this._lineEngine.shiftRowsUp(fromY);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Scans the grid for full rows, clears them, and shifts remaining rows down.
|
|
242
|
+
*
|
|
243
|
+
* Re-checks the same index after a shift to handle consecutive full rows.
|
|
244
|
+
*
|
|
245
|
+
* @returns {number} The total number of rows cleared during the operation.
|
|
246
|
+
*/
|
|
247
|
+
clearFullRows(): number {
|
|
248
|
+
return this._lineEngine.clearFullRows();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// --- COLUMN OPERATIONS ---
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Checks if every cell in a specific column is active.
|
|
255
|
+
*
|
|
256
|
+
* @param {number} x - The column index.
|
|
257
|
+
* @returns {boolean} True if the column is completely full.
|
|
258
|
+
*/
|
|
259
|
+
isColumnFull(x: number): boolean {
|
|
260
|
+
return this._lineEngine.isColumnFull(x);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Checks if every cell in a specific column is inactive.
|
|
265
|
+
*
|
|
266
|
+
* @param {number} x - The column index.
|
|
267
|
+
* @returns {boolean} True if the column is completely empty.
|
|
268
|
+
*/
|
|
269
|
+
isColumnEmpty(x: number): boolean {
|
|
270
|
+
return this._lineEngine.isColumnEmpty(x);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Resets all cells in a specific column to their default empty state.
|
|
275
|
+
*
|
|
276
|
+
* @param {number} x - The column index to clear.
|
|
277
|
+
* @returns {void}
|
|
278
|
+
*/
|
|
279
|
+
clearColumn(x: number): void {
|
|
280
|
+
this._lineEngine.clearColumn(x);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Shifts all columns to the left of a certain index one position to the right.
|
|
285
|
+
*
|
|
286
|
+
* Clears the left-most column (index 0) after shifting.
|
|
287
|
+
*
|
|
288
|
+
* @param {number} fromX - The starting column index for the shift right.
|
|
289
|
+
* @returns {void}
|
|
290
|
+
*/
|
|
291
|
+
shiftColumnsRight(fromX: number): void {
|
|
292
|
+
this._lineEngine.shiftColumnsRight(fromX);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Shifts all columns to the right of a certain index one position to the left.
|
|
297
|
+
*
|
|
298
|
+
* Clears the right-most column after shifting.
|
|
299
|
+
*
|
|
300
|
+
* @param {number} fromX - The starting column index for the shift left.
|
|
301
|
+
* @returns {void}
|
|
302
|
+
*/
|
|
303
|
+
shiftColumnsLeft(fromX: number): void {
|
|
304
|
+
this._lineEngine.shiftColumnsLeft(fromX);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Scans the grid for full columns, clears them, and shifts remaining columns right.
|
|
309
|
+
*
|
|
310
|
+
* @returns {number} The total number of columns cleared during the operation.
|
|
311
|
+
*/
|
|
312
|
+
clearFullColumns(): number {
|
|
313
|
+
return this._lineEngine.clearFullColumns();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// --- ADVANCED OPERATIONS ---
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Checks if any of the provided coordinates are already occupied (active) or out of bounds.
|
|
320
|
+
*
|
|
321
|
+
* @param {Coordinate[]} coordinates - An array of coordinates to check.
|
|
322
|
+
* @returns {boolean} True if the area is occupied or invalid, false if completely clear.
|
|
323
|
+
*/
|
|
324
|
+
isAreaOccupied(coordinates: Coordinate[]): boolean {
|
|
325
|
+
return this._regionEngine.isAreaOccupied(coordinates);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Fills a rectangular region defined by two corners with a specific value and color.
|
|
330
|
+
*
|
|
331
|
+
* Automatically handles bounds and coordinate order.
|
|
332
|
+
*
|
|
333
|
+
* @param {Coordinate} start - One corner of the rectangle.
|
|
334
|
+
* @param {Coordinate} end - The opposite corner of the rectangle.
|
|
335
|
+
* @param {number} value - The cell status value to apply.
|
|
336
|
+
* @param {Color} color - The color to apply.
|
|
337
|
+
* @returns {void}
|
|
338
|
+
*/
|
|
339
|
+
fillArea(start: Coordinate, end: Coordinate, value: number, color: Color): void {
|
|
340
|
+
this._regionEngine.fillArea(start, end, value, color);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Updates multiple coordinates simultaneously with their specific values and colors.
|
|
345
|
+
*
|
|
346
|
+
* Effectively "stamps" a piece's shape onto the static grid.
|
|
347
|
+
*
|
|
348
|
+
* @param {Piece} piece - The collection of cells to stamp.
|
|
349
|
+
* @returns {void}
|
|
350
|
+
*/
|
|
351
|
+
stampPiece(piece: Piece): void {
|
|
352
|
+
this._regionEngine.stampPiece(piece);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Updates a single coordinate with a specific value and color from a Cell.
|
|
357
|
+
*
|
|
358
|
+
* @param {Cell} cell - The cell containing coordinate, value and color.
|
|
359
|
+
* @returns {void}
|
|
360
|
+
*/
|
|
361
|
+
stampCell(cell: Cell): void {
|
|
362
|
+
this._regionEngine.stampCell(cell);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Attempts to shift a collection of cells (a piece) in a given direction.
|
|
367
|
+
*
|
|
368
|
+
* Validates that all new positions are within grid boundaries and are not
|
|
369
|
+
* occupied by other active cells (excluding the cells that are part of the original piece).
|
|
370
|
+
*
|
|
371
|
+
* @param {Piece} piece - The current piece (collection of cells).
|
|
372
|
+
* @param {Vector} direction - The movement vector (e.g., {x: -1, y: 0} for left).
|
|
373
|
+
* @returns {Piece | null} The new piece with updated coordinates if the move is valid, or null if blocked.
|
|
374
|
+
*/
|
|
375
|
+
movePiece(piece: Piece, direction: Vector): Piece | null {
|
|
376
|
+
return this._movementEngine.movePiece(piece, direction);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Alias for {@link movePiece} shifting one unit to the left.
|
|
381
|
+
* @param {Piece} piece - The current piece.
|
|
382
|
+
* @returns {Piece | null}
|
|
383
|
+
*/
|
|
384
|
+
movePieceLeft(piece: Piece): Piece | null {
|
|
385
|
+
return this._movementEngine.movePieceLeft(piece);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Alias for {@link movePiece} shifting one unit to the right.
|
|
390
|
+
* @param {Piece} piece - The current piece.
|
|
391
|
+
* @returns {Piece | null}
|
|
392
|
+
*/
|
|
393
|
+
movePieceRight(piece: Piece): Piece | null {
|
|
394
|
+
return this._movementEngine.movePieceRight(piece);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Alias for {@link movePiece} shifting one unit up.
|
|
399
|
+
* @param {Piece} piece - The current piece.
|
|
400
|
+
* @returns {Piece | null}
|
|
401
|
+
*/
|
|
402
|
+
movePieceUp(piece: Piece): Piece | null {
|
|
403
|
+
return this._movementEngine.movePieceUp(piece);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Alias for {@link movePiece} shifting one unit down.
|
|
408
|
+
* @param {Piece} piece - The current piece.
|
|
409
|
+
* @returns {Piece | null}
|
|
410
|
+
*/
|
|
411
|
+
movePieceDown(piece: Piece): Piece | null {
|
|
412
|
+
return this._movementEngine.movePieceDown(piece);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Attempts to shift a single cell in a given direction.
|
|
417
|
+
*
|
|
418
|
+
* Validates that the new position is within grid boundaries and is not occupied.
|
|
419
|
+
*
|
|
420
|
+
* @param {Cell} cell - The current cell.
|
|
421
|
+
* @param {Vector} direction - The movement vector.
|
|
422
|
+
* @returns {Cell | null} The new cell with updated coordinate if the move is valid, or null if blocked.
|
|
423
|
+
*/
|
|
424
|
+
moveCell(cell: Cell, direction: Vector): Cell | null {
|
|
425
|
+
return this._movementEngine.moveCell(cell, direction);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Alias for {@link moveCell} shifting one unit to the left.
|
|
430
|
+
* @param {Cell} cell - The current cell.
|
|
431
|
+
* @returns {Cell | null}
|
|
432
|
+
*/
|
|
433
|
+
moveCellLeft(cell: Cell): Cell | null {
|
|
434
|
+
return this._movementEngine.moveCellLeft(cell);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Alias for {@link moveCell} shifting one unit to the right.
|
|
439
|
+
* @param {Cell} cell - The current cell.
|
|
440
|
+
* @returns {Cell | null}
|
|
441
|
+
*/
|
|
442
|
+
moveCellRight(cell: Cell): Cell | null {
|
|
443
|
+
return this._movementEngine.moveCellRight(cell);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Alias for {@link moveCell} shifting one unit up.
|
|
448
|
+
* @param {Cell} cell - The current cell.
|
|
449
|
+
* @returns {Cell | null}
|
|
450
|
+
*/
|
|
451
|
+
moveCellUp(cell: Cell): Cell | null {
|
|
452
|
+
return this._movementEngine.moveCellUp(cell);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Alias for {@link moveCell} shifting one unit down.
|
|
457
|
+
* @param {Cell} cell - The current cell.
|
|
458
|
+
* @returns {Cell | null}
|
|
459
|
+
*/
|
|
460
|
+
moveCellDown(cell: Cell): Cell | null {
|
|
461
|
+
return this._movementEngine.moveCellDown(cell);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Attempts to rotate a piece 90 degrees around a specific origin.
|
|
466
|
+
*
|
|
467
|
+
* @param {Piece} piece - The current piece.
|
|
468
|
+
* @param {Coordinate} origin - The center of rotation.
|
|
469
|
+
* @param {boolean} [clockwise=true] - Direction of rotation.
|
|
470
|
+
* @returns {Piece | null} The new piece if rotation is valid, or null if blocked.
|
|
471
|
+
*/
|
|
472
|
+
rotatePiece(piece: Piece, origin: Coordinate, clockwise: boolean = true): Piece | null {
|
|
473
|
+
return this._transformEngine.rotatePiece(piece, origin, clockwise);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Identifies all rows that are completely filled with active cells.
|
|
478
|
+
*
|
|
479
|
+
* @returns {number[]} Array of row indices (y).
|
|
480
|
+
*/
|
|
481
|
+
getFullRows(): number[] {
|
|
482
|
+
return this._analysisEngine.getFullRows();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Identifies all columns that are completely filled with active cells.
|
|
487
|
+
*
|
|
488
|
+
* @returns {number[]} Array of column indices (x).
|
|
489
|
+
*/
|
|
490
|
+
getFullColumns(): number[] {
|
|
491
|
+
return this._analysisEngine.getFullColumns();
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Calculates the final resting position of a piece if it were dropped continuously.
|
|
496
|
+
*
|
|
497
|
+
* @param {Piece} piece - The piece to project.
|
|
498
|
+
* @returns {Piece} The piece at its final vertical resting position.
|
|
499
|
+
*/
|
|
500
|
+
getDropPath(piece: Piece): Piece {
|
|
501
|
+
return this._movementEngine.getDropPath(piece);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Calculates the final resting position of a piece if it were moved continuously upwards.
|
|
506
|
+
*
|
|
507
|
+
* @param {Piece} piece - The piece to project.
|
|
508
|
+
* @returns {Piece} The piece at its highest vertical resting position.
|
|
509
|
+
*/
|
|
510
|
+
getRisePath(piece: Piece): Piece {
|
|
511
|
+
return this._movementEngine.getRisePath(piece);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Calculates the final resting position of a piece if it were moved continuously to the left.
|
|
516
|
+
*
|
|
517
|
+
* @param {Piece} piece - The piece to project.
|
|
518
|
+
* @returns {Piece} The piece at its leftmost resting position.
|
|
519
|
+
*/
|
|
520
|
+
getReachPathLeft(piece: Piece): Piece {
|
|
521
|
+
return this._movementEngine.getReachPathLeft(piece);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Calculates the final resting position of a piece if it were moved continuously to the right.
|
|
526
|
+
*
|
|
527
|
+
* @param {Piece} piece - The piece to project.
|
|
528
|
+
* @returns {Piece} The piece at its rightmost resting position.
|
|
529
|
+
*/
|
|
530
|
+
getReachPathRight(piece: Piece): Piece {
|
|
531
|
+
return this._movementEngine.getReachPathRight(piece);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Returns the active cells adjacent to a specific coordinate.
|
|
536
|
+
*
|
|
537
|
+
* @param {Coordinate} coord - The center coordinate.
|
|
538
|
+
* @param {boolean} [includeDiagonal=false] - Whether to include 8 neighbors or just 4.
|
|
539
|
+
* @returns {Cell[]} List of neighboring cells.
|
|
540
|
+
*/
|
|
541
|
+
getNeighbors(coord: Coordinate, includeDiagonal: boolean = false): Cell[] {
|
|
542
|
+
return this._analysisEngine.getNeighbors(coord, includeDiagonal);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Finds all connected active cells of the same value starting from a specific coordinate.
|
|
547
|
+
* Uses a Breadth-First Search (BFS) algorithm.
|
|
548
|
+
*
|
|
549
|
+
* @param {Coordinate} coord - Starting coordinate.
|
|
550
|
+
* @returns {Piece} Collection of connected cells.
|
|
551
|
+
*/
|
|
552
|
+
findConnectedCells(coord: Coordinate): Piece {
|
|
553
|
+
return this._analysisEngine.findConnectedCells(coord);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Mirrors a piece across a specific axis relative to its bounding box.
|
|
558
|
+
*
|
|
559
|
+
* @param {Piece} piece - The piece to mirror.
|
|
560
|
+
* @param {Axis} axis - The axis to flip across ('x' for horizontal flip, 'y' for vertical).
|
|
561
|
+
* @returns {Piece} The mirrored piece.
|
|
562
|
+
*/
|
|
563
|
+
mirrorPiece(piece: Piece, axis: Axis): Piece {
|
|
564
|
+
return this._transformEngine.mirrorPiece(piece, axis);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Swaps the values and colors of two cells.
|
|
569
|
+
*
|
|
570
|
+
* @param {Coordinate} a - First coordinate.
|
|
571
|
+
* @param {Coordinate} b - Second coordinate.
|
|
572
|
+
* @returns {void}
|
|
573
|
+
*/
|
|
574
|
+
swapCells(a: Coordinate, b: Coordinate): void {
|
|
575
|
+
this._analysisEngine.swapCells(a, b);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Private helper to get piece bounds, delegated to transform engine.
|
|
580
|
+
*/
|
|
581
|
+
protected getPieceBounds(piece: Piece): { min: Coordinate; max: Coordinate } {
|
|
582
|
+
return this._transformEngine.getPieceBounds(piece);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Returns metadata for the real-time debugger.
|
|
587
|
+
*
|
|
588
|
+
* @returns {Record<string, string | number | boolean>} Technical debugging data.
|
|
589
|
+
*/
|
|
590
|
+
getDebugData(): Record<string, string | number | boolean> {
|
|
591
|
+
return {
|
|
592
|
+
width: this.width,
|
|
593
|
+
height: this.height,
|
|
594
|
+
activeCells: this._grid.flat().filter(cell => cell.value > 0).length,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
serialize(): string {
|
|
599
|
+
console.log('serialize');
|
|
600
|
+
return JSON.stringify({
|
|
601
|
+
grid: this._grid,
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
deserialize(data: string): void {
|
|
606
|
+
console.log('deserialize');
|
|
607
|
+
const parsed = JSON.parse(data);
|
|
608
|
+
this._grid = parsed.grid;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import GameHudGrid from './GameHudGrid';
|
|
3
|
+
|
|
4
|
+
describe('GameHudGrid', () => {
|
|
5
|
+
let hudGrid: GameHudGrid;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
hudGrid = new GameHudGrid();
|
|
9
|
+
hudGrid.setup();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should have fixed dimensions 4x4', () => {
|
|
13
|
+
expect(hudGrid.width).toBe(4);
|
|
14
|
+
expect(hudGrid.height).toBe(4);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should initialize a 4x4 internal grid', () => {
|
|
18
|
+
const data = hudGrid.getGrid();
|
|
19
|
+
expect(data.length).toBe(4);
|
|
20
|
+
expect(data[0].length).toBe(4);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Serializable } from '../../types/Interfaces';
|
|
2
|
+
import GameGrid from './GameGrid';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A specialized grid implementation for the Heads-Up Display (HUD).
|
|
6
|
+
* Typically used for previewing the "next piece" in Tetris-like games.
|
|
7
|
+
* It has fixed dimensions (usually 4x4).
|
|
8
|
+
*/
|
|
9
|
+
export default class GameHudGrid extends GameGrid implements Serializable {
|
|
10
|
+
serialId: string = 'hud_grid';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The fixed width of the HUD grid.
|
|
14
|
+
*
|
|
15
|
+
* @returns {number} Always returns 4.
|
|
16
|
+
*/
|
|
17
|
+
get width(): number {
|
|
18
|
+
return 4;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The fixed height of the HUD grid.
|
|
23
|
+
*
|
|
24
|
+
* @returns {number} Always returns 4.
|
|
25
|
+
*/
|
|
26
|
+
get height(): number {
|
|
27
|
+
return 4;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
serialize(): string {
|
|
31
|
+
return JSON.stringify({
|
|
32
|
+
grid: this._grid,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
deserialize(data: string): void {
|
|
37
|
+
const parsed = JSON.parse(data);
|
|
38
|
+
this._grid = parsed.grid;
|
|
39
|
+
}
|
|
40
|
+
}
|