brick-engine-js 1.0.1 → 1.0.2

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.
Files changed (225) hide show
  1. package/dist/docs/GAME_DEVELOPER_GUIDE.html +1 -1
  2. package/dist/docs/brick-engine-guide.html +1 -1
  3. package/dist/docs/getting-started.html +1 -1
  4. package/dist/docs/jsdoc_standard.html +1 -1
  5. package/dist/docs/publishing.html +1 -1
  6. package/dist/docs/reference/interfaces/modules/Session.html +1 -1
  7. package/dist/docs/reference/modules/GameMenu.html +1 -1
  8. package/dist/docs/reference/modules/GameSession.html +1 -1
  9. package/dist/docs/reference/modules/InitialStateSnapshot.html +1 -1
  10. package/dist/docs/reference/modules/SessionModal.html +1 -1
  11. package/dist/docs/testing_best_practices.html +1 -1
  12. package/package.json +7 -1
  13. package/.env.local.example +0 -2
  14. package/.github/workflows/publish.yml +0 -73
  15. package/.prettierignore +0 -2
  16. package/.prettierrc.json +0 -8
  17. package/eslint.config.mjs +0 -29
  18. package/public/CNAME +0 -1
  19. package/public/docs/GAME_DEVELOPER_GUIDE.html +0 -727
  20. package/public/docs/brick-engine-guide.html +0 -610
  21. package/public/docs/diagrams/lifecycle.mmd +0 -19
  22. package/public/docs/documentation_style_guide.html +0 -994
  23. package/public/docs/getting-started.html +0 -648
  24. package/public/docs/images/lifecycle.svg +0 -1
  25. package/public/docs/index.html +0 -593
  26. package/public/docs/jsdoc_standard.html +0 -656
  27. package/public/docs/publishing.html +0 -573
  28. package/public/docs/reference/enums/Color.html +0 -533
  29. package/public/docs/reference/enums/ControlEventType.html +0 -505
  30. package/public/docs/reference/enums/ControlKey.html +0 -529
  31. package/public/docs/reference/enums/FontAlignment.html +0 -545
  32. package/public/docs/reference/enums/FontSize.html +0 -517
  33. package/public/docs/reference/enums/Sound.html +0 -558
  34. package/public/docs/reference/enums/StateProperty.html +0 -525
  35. package/public/docs/reference/helpers/CellHelper.html +0 -520
  36. package/public/docs/reference/helpers/ControlInputHandlerHelper.html +0 -569
  37. package/public/docs/reference/helpers/CoordinateHelper.html +0 -703
  38. package/public/docs/reference/helpers/RelativeValuesHelper.html +0 -560
  39. package/public/docs/reference/interfaces/Debuggable.html +0 -501
  40. package/public/docs/reference/interfaces/GameModules.html +0 -544
  41. package/public/docs/reference/interfaces/Initializable.html +0 -495
  42. package/public/docs/reference/interfaces/RendererInitializable.html +0 -517
  43. package/public/docs/reference/interfaces/StateSyncable.html +0 -542
  44. package/public/docs/reference/interfaces/modules/Control.html +0 -648
  45. package/public/docs/reference/interfaces/modules/Grid.html +0 -1256
  46. package/public/docs/reference/interfaces/modules/Renderer.html +0 -522
  47. package/public/docs/reference/interfaces/modules/RendererComposite.html +0 -577
  48. package/public/docs/reference/interfaces/modules/Score.html +0 -669
  49. package/public/docs/reference/interfaces/modules/Session.html +0 -585
  50. package/public/docs/reference/interfaces/modules/State.html +0 -897
  51. package/public/docs/reference/interfaces/modules/Text.html +0 -668
  52. package/public/docs/reference/interfaces/modules/Time.html +0 -684
  53. package/public/docs/reference/modules/Debugger.html +0 -579
  54. package/public/docs/reference/modules/DisplayRenderer.html +0 -557
  55. package/public/docs/reference/modules/Game.html +0 -909
  56. package/public/docs/reference/modules/GameControl.html +0 -716
  57. package/public/docs/reference/modules/GameGrid.html +0 -1910
  58. package/public/docs/reference/modules/GameHudGrid.html +0 -508
  59. package/public/docs/reference/modules/GameMenu.html +0 -538
  60. package/public/docs/reference/modules/GameRenderer.html +0 -589
  61. package/public/docs/reference/modules/GameScore.html +0 -664
  62. package/public/docs/reference/modules/GameSession.html +0 -533
  63. package/public/docs/reference/modules/GameSound.html +0 -636
  64. package/public/docs/reference/modules/GameState.html +0 -922
  65. package/public/docs/reference/modules/GameText.html +0 -701
  66. package/public/docs/reference/modules/GameTime.html +0 -696
  67. package/public/docs/reference/modules/HudRenderer.html +0 -568
  68. package/public/docs/reference/modules/InitialStateSnapshot.html +0 -557
  69. package/public/docs/reference/modules/SessionModal.html +0 -520
  70. package/public/docs/reference/types/Axis.html +0 -505
  71. package/public/docs/reference/types/Cell.html +0 -514
  72. package/public/docs/reference/types/ControlCallback.html +0 -488
  73. package/public/docs/reference/types/Coordinate.html +0 -510
  74. package/public/docs/reference/types/GameEntry.html +0 -514
  75. package/public/docs/reference/types/GameEvent.html +0 -514
  76. package/public/docs/reference/types/Piece.html +0 -506
  77. package/public/docs/reference/types/RendererMetrics.html +0 -514
  78. package/public/docs/reference/types/Vector.html +0 -509
  79. package/public/docs/testing_best_practices.html +0 -770
  80. package/public/favicon.ico +0 -0
  81. package/public/fonts/digital-7.monoitalic.ttf +0 -0
  82. package/public/images/cell.svg +0 -32
  83. package/public/images/close.png +0 -0
  84. package/public/images/games.png +0 -0
  85. package/public/images/github.png +0 -0
  86. package/public/images/letter-a.png +0 -0
  87. package/public/images/letter-d.png +0 -0
  88. package/public/images/letter-j.png +0 -0
  89. package/public/images/letter-s.png +0 -0
  90. package/public/images/letter-w.png +0 -0
  91. package/public/images/meta-image.png +0 -0
  92. package/public/images/number-1.png +0 -0
  93. package/public/images/number-2.png +0 -0
  94. package/public/images/number-3.png +0 -0
  95. package/public/images/number-4.png +0 -0
  96. package/public/images/number-5.png +0 -0
  97. package/public/images/number-6.png +0 -0
  98. package/public/images/splash.gif +0 -0
  99. package/public/index.html +0 -15
  100. package/public/sounds/sound_00.wav +0 -0
  101. package/public/sounds/sound_01.wav +0 -0
  102. package/public/sounds/sound_02.wav +0 -0
  103. package/public/sounds/sound_03.wav +0 -0
  104. package/public/sounds/sound_04.wav +0 -0
  105. package/public/sounds/sound_05.wav +0 -0
  106. package/public/sounds/sound_06.wav +0 -0
  107. package/public/sounds/sound_07.wav +0 -0
  108. package/public/sounds/sound_08.wav +0 -0
  109. package/public/sounds/sound_09.wav +0 -0
  110. package/public/sounds/sound_10.wav +0 -0
  111. package/public/sounds/sound_11.wav +0 -0
  112. package/public/sounds/sound_12.wav +0 -0
  113. package/public/sounds/sound_13.wav +0 -0
  114. package/public/sounds/sound_14.wav +0 -0
  115. package/public/sounds/sound_15.wav +0 -0
  116. package/public/style/body.css +0 -86
  117. package/public/style/buttons.css +0 -233
  118. package/public/style/debugger.css +0 -117
  119. package/public/style/sessionModal.css +0 -155
  120. package/public/style/sourceCodeAndCommands.css +0 -74
  121. package/public/style/splash.css +0 -13
  122. package/public/style/theme.css +0 -137
  123. package/scripts/generate-diagrams.sh +0 -20
  124. package/scripts/generate-docs.js +0 -111
  125. package/src/client-game.d.ts +0 -1
  126. package/src/config/configs.test.ts +0 -20
  127. package/src/config/configs.ts +0 -197
  128. package/src/config/env.test.ts +0 -59
  129. package/src/config/env.ts +0 -7
  130. package/src/config/styles.ts +0 -5
  131. package/src/core/Game.test.ts +0 -167
  132. package/src/core/Game.ts +0 -307
  133. package/src/core/InitialStateSnapshot.test.ts +0 -51
  134. package/src/core/InitialStateSnapshot.ts +0 -46
  135. package/src/core/helpers/CellHelper.test.ts +0 -33
  136. package/src/core/helpers/CellHelper.ts +0 -21
  137. package/src/core/helpers/ControlInputHandlerHelper.test.ts +0 -116
  138. package/src/core/helpers/ControlInputHandlerHelper.ts +0 -68
  139. package/src/core/helpers/CoordinateHelper.test.ts +0 -113
  140. package/src/core/helpers/CoordinateHelper.ts +0 -82
  141. package/src/core/helpers/InterfaceIdentifierHelper.test.ts +0 -122
  142. package/src/core/helpers/InterfaceIdentifierHelper.ts +0 -43
  143. package/src/core/helpers/RelativeValuesHelper.test.ts +0 -47
  144. package/src/core/helpers/RelativeValuesHelper.ts +0 -29
  145. package/src/core/module/control/GameControl.test.ts +0 -82
  146. package/src/core/module/control/GameControl.ts +0 -142
  147. package/src/core/module/control/GameControlKeyBinding.test.ts +0 -59
  148. package/src/core/module/control/GameControlKeyBinding.ts +0 -92
  149. package/src/core/module/grid/GameGrid.test.ts +0 -83
  150. package/src/core/module/grid/GameGrid.ts +0 -610
  151. package/src/core/module/grid/GameHudGrid.test.ts +0 -22
  152. package/src/core/module/grid/GameHudGrid.ts +0 -40
  153. package/src/core/module/grid/engines/GridAnalysisEngine.test.ts +0 -157
  154. package/src/core/module/grid/engines/GridAnalysisEngine.ts +0 -124
  155. package/src/core/module/grid/engines/GridLineEngine.test.ts +0 -132
  156. package/src/core/module/grid/engines/GridLineEngine.ts +0 -165
  157. package/src/core/module/grid/engines/GridMovementEngine.test.ts +0 -125
  158. package/src/core/module/grid/engines/GridMovementEngine.ts +0 -113
  159. package/src/core/module/grid/engines/GridRegionEngine.test.ts +0 -136
  160. package/src/core/module/grid/engines/GridRegionEngine.ts +0 -52
  161. package/src/core/module/grid/engines/GridTransformEngine.test.ts +0 -98
  162. package/src/core/module/grid/engines/GridTransformEngine.ts +0 -70
  163. package/src/core/module/renderer/DisplayRenderer.test.ts +0 -86
  164. package/src/core/module/renderer/DisplayRenderer.ts +0 -152
  165. package/src/core/module/renderer/GameRenderer.test.ts +0 -103
  166. package/src/core/module/renderer/GameRenderer.ts +0 -144
  167. package/src/core/module/renderer/HudRenderer.test.ts +0 -108
  168. package/src/core/module/renderer/HudRenderer.ts +0 -203
  169. package/src/core/module/score/GameScore.test.ts +0 -71
  170. package/src/core/module/score/GameScore.ts +0 -188
  171. package/src/core/module/session/GameSession.test.ts +0 -176
  172. package/src/core/module/session/GameSession.ts +0 -103
  173. package/src/core/module/sound/GameSound.test.ts +0 -117
  174. package/src/core/module/sound/GameSound.ts +0 -229
  175. package/src/core/module/state/GameState.test.ts +0 -101
  176. package/src/core/module/state/GameState.ts +0 -339
  177. package/src/core/module/text/GameText.test.ts +0 -87
  178. package/src/core/module/text/GameText.ts +0 -150
  179. package/src/core/module/time/GameTime.test.ts +0 -86
  180. package/src/core/module/time/GameTime.ts +0 -144
  181. package/src/core/types/Interfaces.ts +0 -59
  182. package/src/core/types/Types.ts +0 -124
  183. package/src/core/types/enums.ts +0 -113
  184. package/src/core/types/modules.ts +0 -841
  185. package/src/index.test.ts +0 -15
  186. package/src/index.ts +0 -9
  187. package/src/main.test.ts +0 -137
  188. package/src/main.ts +0 -77
  189. package/src/menu/GameMenu.test.ts +0 -157
  190. package/src/menu/GameMenu.ts +0 -124
  191. package/src/menu/GameMenuSingleton.test.ts +0 -26
  192. package/src/menu/GameMenuSingleton.ts +0 -13
  193. package/src/menu/GameRepository.test.ts +0 -46
  194. package/src/menu/GameRepository.ts +0 -47
  195. package/src/menu/manager/GameManager.test.ts +0 -68
  196. package/src/menu/manager/GameManager.ts +0 -50
  197. package/src/types/global.d.ts +0 -8
  198. package/src/types/interfaces.ts +0 -5
  199. package/src/view/Debugger.test.ts +0 -152
  200. package/src/view/Debugger.ts +0 -124
  201. package/src/view/GameView.test.ts +0 -95
  202. package/src/view/GameView.ts +0 -244
  203. package/src/view/SessionModal.test.ts +0 -141
  204. package/src/view/SessionModal.ts +0 -73
  205. package/src/view/components/layout/ButtonLayout.test.ts +0 -28
  206. package/src/view/components/layout/ButtonLayout.ts +0 -63
  207. package/src/view/components/layout/ContainerLayout.test.ts +0 -48
  208. package/src/view/components/layout/ContainerLayout.ts +0 -50
  209. package/src/view/components/layout/FrameLayout.test.ts +0 -24
  210. package/src/view/components/layout/FrameLayout.ts +0 -25
  211. package/src/view/components/ui/BigButton.test.ts +0 -28
  212. package/src/view/components/ui/BigButton.ts +0 -31
  213. package/src/view/components/ui/Button.test.ts +0 -30
  214. package/src/view/components/ui/Button.ts +0 -30
  215. package/src/view/components/ui/Canvas.test.ts +0 -32
  216. package/src/view/components/ui/Canvas.ts +0 -34
  217. package/src/view/components/ui/SmallButton.test.ts +0 -48
  218. package/src/view/components/ui/SmallButton.ts +0 -32
  219. package/src/view/theme/applyColors.test.ts +0 -47
  220. package/src/view/theme/applyColors.ts +0 -38
  221. package/src/view/theme/dimensions.test.ts +0 -34
  222. package/src/view/theme/dimensions.ts +0 -53
  223. package/tsconfig.json +0 -16
  224. package/vitest.config.ts +0 -14
  225. package/webpack.config.js +0 -133
@@ -1,610 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- });
@@ -1,40 +0,0 @@
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
- }