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.
- package/dist/docs/GAME_DEVELOPER_GUIDE.html +1 -1
- package/dist/docs/brick-engine-guide.html +1 -1
- package/dist/docs/getting-started.html +1 -1
- package/dist/docs/jsdoc_standard.html +1 -1
- package/dist/docs/publishing.html +1 -1
- package/dist/docs/reference/interfaces/modules/Session.html +1 -1
- package/dist/docs/reference/modules/GameMenu.html +1 -1
- package/dist/docs/reference/modules/GameSession.html +1 -1
- package/dist/docs/reference/modules/InitialStateSnapshot.html +1 -1
- package/dist/docs/reference/modules/SessionModal.html +1 -1
- package/dist/docs/testing_best_practices.html +1 -1
- package/package.json +7 -1
- package/.env.local.example +0 -2
- package/.github/workflows/publish.yml +0 -73
- package/.prettierignore +0 -2
- package/.prettierrc.json +0 -8
- package/eslint.config.mjs +0 -29
- package/public/CNAME +0 -1
- package/public/docs/GAME_DEVELOPER_GUIDE.html +0 -727
- package/public/docs/brick-engine-guide.html +0 -610
- package/public/docs/diagrams/lifecycle.mmd +0 -19
- package/public/docs/documentation_style_guide.html +0 -994
- package/public/docs/getting-started.html +0 -648
- package/public/docs/images/lifecycle.svg +0 -1
- package/public/docs/index.html +0 -593
- package/public/docs/jsdoc_standard.html +0 -656
- package/public/docs/publishing.html +0 -573
- package/public/docs/reference/enums/Color.html +0 -533
- package/public/docs/reference/enums/ControlEventType.html +0 -505
- package/public/docs/reference/enums/ControlKey.html +0 -529
- package/public/docs/reference/enums/FontAlignment.html +0 -545
- package/public/docs/reference/enums/FontSize.html +0 -517
- package/public/docs/reference/enums/Sound.html +0 -558
- package/public/docs/reference/enums/StateProperty.html +0 -525
- package/public/docs/reference/helpers/CellHelper.html +0 -520
- package/public/docs/reference/helpers/ControlInputHandlerHelper.html +0 -569
- package/public/docs/reference/helpers/CoordinateHelper.html +0 -703
- package/public/docs/reference/helpers/RelativeValuesHelper.html +0 -560
- package/public/docs/reference/interfaces/Debuggable.html +0 -501
- package/public/docs/reference/interfaces/GameModules.html +0 -544
- package/public/docs/reference/interfaces/Initializable.html +0 -495
- package/public/docs/reference/interfaces/RendererInitializable.html +0 -517
- package/public/docs/reference/interfaces/StateSyncable.html +0 -542
- package/public/docs/reference/interfaces/modules/Control.html +0 -648
- package/public/docs/reference/interfaces/modules/Grid.html +0 -1256
- package/public/docs/reference/interfaces/modules/Renderer.html +0 -522
- package/public/docs/reference/interfaces/modules/RendererComposite.html +0 -577
- package/public/docs/reference/interfaces/modules/Score.html +0 -669
- package/public/docs/reference/interfaces/modules/Session.html +0 -585
- package/public/docs/reference/interfaces/modules/State.html +0 -897
- package/public/docs/reference/interfaces/modules/Text.html +0 -668
- package/public/docs/reference/interfaces/modules/Time.html +0 -684
- package/public/docs/reference/modules/Debugger.html +0 -579
- package/public/docs/reference/modules/DisplayRenderer.html +0 -557
- package/public/docs/reference/modules/Game.html +0 -909
- package/public/docs/reference/modules/GameControl.html +0 -716
- package/public/docs/reference/modules/GameGrid.html +0 -1910
- package/public/docs/reference/modules/GameHudGrid.html +0 -508
- package/public/docs/reference/modules/GameMenu.html +0 -538
- package/public/docs/reference/modules/GameRenderer.html +0 -589
- package/public/docs/reference/modules/GameScore.html +0 -664
- package/public/docs/reference/modules/GameSession.html +0 -533
- package/public/docs/reference/modules/GameSound.html +0 -636
- package/public/docs/reference/modules/GameState.html +0 -922
- package/public/docs/reference/modules/GameText.html +0 -701
- package/public/docs/reference/modules/GameTime.html +0 -696
- package/public/docs/reference/modules/HudRenderer.html +0 -568
- package/public/docs/reference/modules/InitialStateSnapshot.html +0 -557
- package/public/docs/reference/modules/SessionModal.html +0 -520
- package/public/docs/reference/types/Axis.html +0 -505
- package/public/docs/reference/types/Cell.html +0 -514
- package/public/docs/reference/types/ControlCallback.html +0 -488
- package/public/docs/reference/types/Coordinate.html +0 -510
- package/public/docs/reference/types/GameEntry.html +0 -514
- package/public/docs/reference/types/GameEvent.html +0 -514
- package/public/docs/reference/types/Piece.html +0 -506
- package/public/docs/reference/types/RendererMetrics.html +0 -514
- package/public/docs/reference/types/Vector.html +0 -509
- package/public/docs/testing_best_practices.html +0 -770
- package/public/favicon.ico +0 -0
- package/public/fonts/digital-7.monoitalic.ttf +0 -0
- package/public/images/cell.svg +0 -32
- 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 +0 -15
- 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 +0 -86
- package/public/style/buttons.css +0 -233
- package/public/style/debugger.css +0 -117
- package/public/style/sessionModal.css +0 -155
- package/public/style/sourceCodeAndCommands.css +0 -74
- package/public/style/splash.css +0 -13
- package/public/style/theme.css +0 -137
- package/scripts/generate-diagrams.sh +0 -20
- package/scripts/generate-docs.js +0 -111
- package/src/client-game.d.ts +0 -1
- package/src/config/configs.test.ts +0 -20
- package/src/config/configs.ts +0 -197
- package/src/config/env.test.ts +0 -59
- package/src/config/env.ts +0 -7
- package/src/config/styles.ts +0 -5
- package/src/core/Game.test.ts +0 -167
- package/src/core/Game.ts +0 -307
- package/src/core/InitialStateSnapshot.test.ts +0 -51
- package/src/core/InitialStateSnapshot.ts +0 -46
- package/src/core/helpers/CellHelper.test.ts +0 -33
- package/src/core/helpers/CellHelper.ts +0 -21
- package/src/core/helpers/ControlInputHandlerHelper.test.ts +0 -116
- package/src/core/helpers/ControlInputHandlerHelper.ts +0 -68
- package/src/core/helpers/CoordinateHelper.test.ts +0 -113
- package/src/core/helpers/CoordinateHelper.ts +0 -82
- package/src/core/helpers/InterfaceIdentifierHelper.test.ts +0 -122
- package/src/core/helpers/InterfaceIdentifierHelper.ts +0 -43
- package/src/core/helpers/RelativeValuesHelper.test.ts +0 -47
- package/src/core/helpers/RelativeValuesHelper.ts +0 -29
- package/src/core/module/control/GameControl.test.ts +0 -82
- package/src/core/module/control/GameControl.ts +0 -142
- package/src/core/module/control/GameControlKeyBinding.test.ts +0 -59
- package/src/core/module/control/GameControlKeyBinding.ts +0 -92
- package/src/core/module/grid/GameGrid.test.ts +0 -83
- package/src/core/module/grid/GameGrid.ts +0 -610
- package/src/core/module/grid/GameHudGrid.test.ts +0 -22
- package/src/core/module/grid/GameHudGrid.ts +0 -40
- package/src/core/module/grid/engines/GridAnalysisEngine.test.ts +0 -157
- package/src/core/module/grid/engines/GridAnalysisEngine.ts +0 -124
- package/src/core/module/grid/engines/GridLineEngine.test.ts +0 -132
- package/src/core/module/grid/engines/GridLineEngine.ts +0 -165
- package/src/core/module/grid/engines/GridMovementEngine.test.ts +0 -125
- package/src/core/module/grid/engines/GridMovementEngine.ts +0 -113
- package/src/core/module/grid/engines/GridRegionEngine.test.ts +0 -136
- package/src/core/module/grid/engines/GridRegionEngine.ts +0 -52
- package/src/core/module/grid/engines/GridTransformEngine.test.ts +0 -98
- package/src/core/module/grid/engines/GridTransformEngine.ts +0 -70
- package/src/core/module/renderer/DisplayRenderer.test.ts +0 -86
- package/src/core/module/renderer/DisplayRenderer.ts +0 -152
- package/src/core/module/renderer/GameRenderer.test.ts +0 -103
- package/src/core/module/renderer/GameRenderer.ts +0 -144
- package/src/core/module/renderer/HudRenderer.test.ts +0 -108
- package/src/core/module/renderer/HudRenderer.ts +0 -203
- package/src/core/module/score/GameScore.test.ts +0 -71
- package/src/core/module/score/GameScore.ts +0 -188
- package/src/core/module/session/GameSession.test.ts +0 -176
- package/src/core/module/session/GameSession.ts +0 -103
- package/src/core/module/sound/GameSound.test.ts +0 -117
- package/src/core/module/sound/GameSound.ts +0 -229
- package/src/core/module/state/GameState.test.ts +0 -101
- package/src/core/module/state/GameState.ts +0 -339
- package/src/core/module/text/GameText.test.ts +0 -87
- package/src/core/module/text/GameText.ts +0 -150
- package/src/core/module/time/GameTime.test.ts +0 -86
- package/src/core/module/time/GameTime.ts +0 -144
- package/src/core/types/Interfaces.ts +0 -59
- package/src/core/types/Types.ts +0 -124
- package/src/core/types/enums.ts +0 -113
- package/src/core/types/modules.ts +0 -841
- package/src/index.test.ts +0 -15
- package/src/index.ts +0 -9
- package/src/main.test.ts +0 -137
- package/src/main.ts +0 -77
- package/src/menu/GameMenu.test.ts +0 -157
- package/src/menu/GameMenu.ts +0 -124
- package/src/menu/GameMenuSingleton.test.ts +0 -26
- package/src/menu/GameMenuSingleton.ts +0 -13
- package/src/menu/GameRepository.test.ts +0 -46
- package/src/menu/GameRepository.ts +0 -47
- package/src/menu/manager/GameManager.test.ts +0 -68
- package/src/menu/manager/GameManager.ts +0 -50
- package/src/types/global.d.ts +0 -8
- package/src/types/interfaces.ts +0 -5
- package/src/view/Debugger.test.ts +0 -152
- package/src/view/Debugger.ts +0 -124
- package/src/view/GameView.test.ts +0 -95
- package/src/view/GameView.ts +0 -244
- package/src/view/SessionModal.test.ts +0 -141
- package/src/view/SessionModal.ts +0 -73
- package/src/view/components/layout/ButtonLayout.test.ts +0 -28
- package/src/view/components/layout/ButtonLayout.ts +0 -63
- package/src/view/components/layout/ContainerLayout.test.ts +0 -48
- package/src/view/components/layout/ContainerLayout.ts +0 -50
- package/src/view/components/layout/FrameLayout.test.ts +0 -24
- package/src/view/components/layout/FrameLayout.ts +0 -25
- package/src/view/components/ui/BigButton.test.ts +0 -28
- package/src/view/components/ui/BigButton.ts +0 -31
- package/src/view/components/ui/Button.test.ts +0 -30
- package/src/view/components/ui/Button.ts +0 -30
- package/src/view/components/ui/Canvas.test.ts +0 -32
- package/src/view/components/ui/Canvas.ts +0 -34
- package/src/view/components/ui/SmallButton.test.ts +0 -48
- package/src/view/components/ui/SmallButton.ts +0 -32
- package/src/view/theme/applyColors.test.ts +0 -47
- package/src/view/theme/applyColors.ts +0 -38
- package/src/view/theme/dimensions.test.ts +0 -34
- package/src/view/theme/dimensions.ts +0 -53
- package/tsconfig.json +0 -16
- package/vitest.config.ts +0 -14
- package/webpack.config.js +0 -133
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/** @vitest-environment jsdom */
|
|
2
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
3
|
-
import GameControlKeyBinding from './GameControlKeyBinding';
|
|
4
|
-
import { Control } from '../../types/modules';
|
|
5
|
-
import { ControlKey } from '../../types/enums';
|
|
6
|
-
|
|
7
|
-
describe('GameControlKeyBinding', () => {
|
|
8
|
-
let binding: GameControlKeyBinding;
|
|
9
|
-
let mockControl: Control;
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
mockControl = {
|
|
13
|
-
notify: vi.fn(),
|
|
14
|
-
} as unknown as Control;
|
|
15
|
-
|
|
16
|
-
binding = new GameControlKeyBinding(mockControl);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should bind and unbind window events', () => {
|
|
20
|
-
const addSpy = vi.spyOn(window, 'addEventListener');
|
|
21
|
-
const removeSpy = vi.spyOn(window, 'removeEventListener');
|
|
22
|
-
|
|
23
|
-
binding.bindControls();
|
|
24
|
-
expect(addSpy).toHaveBeenCalledWith('keydown', expect.any(Function));
|
|
25
|
-
|
|
26
|
-
binding.unbindControls();
|
|
27
|
-
expect(removeSpy).toHaveBeenCalledWith('keydown', expect.any(Function));
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should trigger control press on valid key down', () => {
|
|
31
|
-
binding.bindControls();
|
|
32
|
-
|
|
33
|
-
// Simulating KeyboardEvent
|
|
34
|
-
const event = new KeyboardEvent('keydown', { code: 'ArrowUp' });
|
|
35
|
-
window.dispatchEvent(event);
|
|
36
|
-
|
|
37
|
-
expect(mockControl.notify).toHaveBeenCalledWith(ControlKey.UP, 'pressed');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should ignore repeated native key down events', () => {
|
|
41
|
-
binding.bindControls();
|
|
42
|
-
|
|
43
|
-
const event = new KeyboardEvent('keydown', { code: 'ArrowUp', repeat: true } as KeyboardEventInit);
|
|
44
|
-
window.dispatchEvent(event);
|
|
45
|
-
|
|
46
|
-
expect(mockControl.notify).not.toHaveBeenCalled();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should trigger control release on key up', () => {
|
|
50
|
-
binding.bindControls();
|
|
51
|
-
|
|
52
|
-
const event = new KeyboardEvent('keyup', { code: 'ArrowLeft' });
|
|
53
|
-
window.dispatchEvent(event);
|
|
54
|
-
|
|
55
|
-
// ControlInputHandler doesn't notify on release directly but we can verify it doesn't crash
|
|
56
|
-
// Actually, let's verify if handleRelease was called on the handler
|
|
57
|
-
// Since it's private, we just check if it doesn't error and maybe mock the handler if we could
|
|
58
|
-
});
|
|
59
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { ControlKey } from '../../types/enums';
|
|
2
|
-
import { Control } from '../../types/modules';
|
|
3
|
-
import ControlInputHandler from '../../helpers/ControlInputHandlerHelper';
|
|
4
|
-
|
|
5
|
-
const DEFAULT_KEY_MAP: Record<string, ControlKey> = {
|
|
6
|
-
// Arrows
|
|
7
|
-
ArrowUp: ControlKey.UP,
|
|
8
|
-
ArrowDown: ControlKey.DOWN,
|
|
9
|
-
ArrowLeft: ControlKey.LEFT,
|
|
10
|
-
ArrowRight: ControlKey.RIGHT,
|
|
11
|
-
|
|
12
|
-
// WASD
|
|
13
|
-
KeyW: ControlKey.UP,
|
|
14
|
-
KeyS: ControlKey.DOWN,
|
|
15
|
-
KeyA: ControlKey.LEFT,
|
|
16
|
-
KeyD: ControlKey.RIGHT,
|
|
17
|
-
|
|
18
|
-
// Actions
|
|
19
|
-
KeyJ: ControlKey.ACTION,
|
|
20
|
-
|
|
21
|
-
// System
|
|
22
|
-
Digit1: ControlKey.POWER,
|
|
23
|
-
Digit2: ControlKey.START_PAUSE,
|
|
24
|
-
Digit3: ControlKey.SOUND,
|
|
25
|
-
Digit4: ControlKey.RESET,
|
|
26
|
-
Digit5: ControlKey.EXIT,
|
|
27
|
-
Digit6: ControlKey.COLOR,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Handles the binding of physical keyboard events to logical control actions.
|
|
32
|
-
* Translates Browser `KeyboardEvent`s into engine `ControlKey`s.
|
|
33
|
-
*/
|
|
34
|
-
export default class GameControlKeyBinding {
|
|
35
|
-
private _inputHandler: ControlInputHandler;
|
|
36
|
-
|
|
37
|
-
private _boundHandleKeyDown: (event: KeyboardEvent) => void;
|
|
38
|
-
private _boundHandleKeyUp: (event: KeyboardEvent) => void;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Creates an instance of GameControlKeyBinding.
|
|
42
|
-
*
|
|
43
|
-
* @param {Control} control - The parent control module.
|
|
44
|
-
*/
|
|
45
|
-
constructor(control: Control) {
|
|
46
|
-
this._inputHandler = new ControlInputHandler(control);
|
|
47
|
-
this._boundHandleKeyDown = this._handleKeyDown.bind(this);
|
|
48
|
-
this._boundHandleKeyUp = this._handleKeyUp.bind(this);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Binds keyboard events to the global window object.
|
|
53
|
-
*/
|
|
54
|
-
bindControls() {
|
|
55
|
-
window.addEventListener('keydown', this._boundHandleKeyDown);
|
|
56
|
-
window.addEventListener('keyup', this._boundHandleKeyUp);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Unbinds keyboard events from the global window object.
|
|
61
|
-
*/
|
|
62
|
-
unbindControls() {
|
|
63
|
-
window.removeEventListener('keydown', this._boundHandleKeyDown);
|
|
64
|
-
window.removeEventListener('keyup', this._boundHandleKeyUp);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Internal handler for key down events.
|
|
69
|
-
*
|
|
70
|
-
* @param {KeyboardEvent} event - The browser keyboard event.
|
|
71
|
-
*/
|
|
72
|
-
private _handleKeyDown(event: KeyboardEvent) {
|
|
73
|
-
const controlKey = DEFAULT_KEY_MAP[event.code];
|
|
74
|
-
if (!controlKey) return;
|
|
75
|
-
|
|
76
|
-
if (event.repeat) return; // Ignore native repeat, fully delegating repeat logic to InputHandler
|
|
77
|
-
|
|
78
|
-
this._inputHandler.handlePress(controlKey);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Internal handler for key up events.
|
|
83
|
-
*
|
|
84
|
-
* @param {KeyboardEvent} event - The browser keyboard event.
|
|
85
|
-
*/
|
|
86
|
-
private _handleKeyUp(event: KeyboardEvent) {
|
|
87
|
-
const controlKey = DEFAULT_KEY_MAP[event.code];
|
|
88
|
-
if (!controlKey) return;
|
|
89
|
-
|
|
90
|
-
this._inputHandler.handleRelease(controlKey);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
-
import GameGrid from './GameGrid';
|
|
3
|
-
import { Color } from '../../types/enums';
|
|
4
|
-
import CellHelper from '../../helpers/CellHelper';
|
|
5
|
-
|
|
6
|
-
describe('GameGrid', () => {
|
|
7
|
-
let grid: GameGrid;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
grid = new GameGrid();
|
|
11
|
-
grid.setup();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('Core & Utilities', () => {
|
|
15
|
-
it('should initialize with empty cells', () => {
|
|
16
|
-
const data = grid.getGrid();
|
|
17
|
-
expect(data.length).toBe(grid.height);
|
|
18
|
-
expect(data[0].length).toBe(grid.width);
|
|
19
|
-
expect(data[0][0].value).toBe(0);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should validate coordinates', () => {
|
|
23
|
-
expect(grid.isValidCoordinate({ x: 0, y: 0 })).toBe(true);
|
|
24
|
-
expect(grid.isValidCoordinate({ x: -1, y: 0 })).toBe(false);
|
|
25
|
-
expect(grid.isValidCoordinate({ x: grid.width, y: 0 })).toBe(false);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should get and set cell values/colors', () => {
|
|
29
|
-
const coord = { x: 5, y: 5 };
|
|
30
|
-
grid.setCellValue(coord, 1);
|
|
31
|
-
grid.setCellColor(coord, Color.RED);
|
|
32
|
-
|
|
33
|
-
expect(grid.isCellActive(coord)).toBe(true);
|
|
34
|
-
expect(grid.getCell(coord)?.color).toBe(Color.RED);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should return null for out of bounds cell access', () => {
|
|
38
|
-
expect(grid.getCell({ x: -1, y: 0 })).toBeNull();
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('Iteration', () => {
|
|
43
|
-
it('should iterate over all cells', () => {
|
|
44
|
-
let count = 0;
|
|
45
|
-
grid.forEach(() => count++);
|
|
46
|
-
expect(count).toBe(grid.width * grid.height);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('Delegation', () => {
|
|
51
|
-
// We verify that calling grid methods calls the internal engines
|
|
52
|
-
// Since engines are private, we can't easily mock them without reaching into internals
|
|
53
|
-
// but given the implementation, we can just check if the methods exist and work as expected
|
|
54
|
-
// as high-level integration tests.
|
|
55
|
-
|
|
56
|
-
it('should clear full rows (delegated to line engine)', () => {
|
|
57
|
-
// Fill a row
|
|
58
|
-
for (let x = 0; x < grid.width; x++) grid.setCellValue({ x, y: 0 }, 1);
|
|
59
|
-
|
|
60
|
-
const cleared = grid.clearFullRows();
|
|
61
|
-
expect(cleared).toBe(1);
|
|
62
|
-
expect(grid.isRowEmpty(0)).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should move piece (delegated to movement engine)', () => {
|
|
66
|
-
const piece = [CellHelper.emptyCell({ x: 5, y: 5 })];
|
|
67
|
-
piece[0].value = 1;
|
|
68
|
-
|
|
69
|
-
const moved = grid.movePiece(piece, { x: 1, y: 0 });
|
|
70
|
-
expect(moved![0].coordinate).toEqual({ x: 6, y: 5 });
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe('Debug', () => {
|
|
75
|
-
it('should return correct debug data', () => {
|
|
76
|
-
grid.setCellValue({ x: 0, y: 0 }, 1);
|
|
77
|
-
const debug = grid.getDebugData();
|
|
78
|
-
expect(debug.activeCells).toBe(1);
|
|
79
|
-
expect(debug.width).toBe(grid.width);
|
|
80
|
-
expect(debug.height).toBe(grid.height);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|