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,25 +0,0 @@
1
- import p5 from 'p5';
2
- import configs from '../../../config/configs';
3
-
4
- /**
5
- * Creates the decorative frame for the game.
6
- *
7
- * Adds a visual frame around the game area and includes the branding text "Brick Game".
8
- *
9
- * @param p - The p5 instance.
10
- * @param container - The parent container element.
11
- * @returns The created frame element.
12
- */
13
- export default function FrameLayout(p: p5, container: p5.Element): p5.Element {
14
- const frame = p.createDiv();
15
- frame.parent(container);
16
- frame.id(configs.selectors.viewElementIds.frame);
17
-
18
- const div = p.createDiv();
19
- div.parent(frame);
20
-
21
- const paragraph = p.createP('Brick Game');
22
- paragraph.parent(div);
23
-
24
- return frame;
25
- }
@@ -1,28 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import type p5 from 'p5';
3
- import BigButton from './BigButton';
4
-
5
- describe('BigButton', () => {
6
- it('should create a large button with requested label', () => {
7
- // [ARRANGE]
8
- const mockElement = {
9
- parent: vi.fn(),
10
- addClass: vi.fn(),
11
- };
12
- const mockP5 = {
13
- createDiv: vi.fn().mockReturnValue(mockElement),
14
- createButton: vi.fn().mockReturnValue(mockElement),
15
- } as unknown as p5;
16
- const mockContainer = {} as p5.Element;
17
-
18
- // [ACT]
19
- const result = BigButton(mockP5, mockContainer, 'Action');
20
-
21
- // [ASSERT]
22
- expect(mockP5.createDiv).toHaveBeenCalled();
23
- expect(mockP5.createButton).toHaveBeenCalledWith('Action');
24
- expect(mockElement.addClass).toHaveBeenCalledWith('lg-btn-container');
25
- expect(mockElement.addClass).toHaveBeenCalledWith('lg-btn');
26
- expect(result).toBe(mockElement);
27
- });
28
- });
@@ -1,31 +0,0 @@
1
- import p5 from 'p5';
2
-
3
- /**
4
- * Creates the large action button.
5
- *
6
- * This button is typically used for the primary game action (e.g., rotate, fire).
7
- * It creates a specific container and applies large button styles.
8
- *
9
- * @param p - The p5 instance.
10
- * @param container - The container element to attach the button to.
11
- * @param label - The text label for the button (currently used for aria-label or internal logic as visual label is commented out).
12
- * @returns The created button element.
13
- */
14
- export default function BigButton(p: p5, container: p5.Element, label: string) {
15
- //Container
16
- const buttonContainer = p.createDiv();
17
- buttonContainer.parent(container);
18
- buttonContainer.addClass('lg-btn-container');
19
-
20
- // //Label
21
- // const paragraph = p.createP(label);
22
- // paragraph.parent(buttonContainer);
23
- // paragraph.addClass('lg-btn-p');
24
-
25
- //Button
26
- const button = p.createButton(label);
27
- button.parent(buttonContainer);
28
- button.addClass('lg-btn');
29
-
30
- return button;
31
- }
@@ -1,30 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import type p5 from 'p5';
3
- import Button from './Button';
4
-
5
- describe('Button', () => {
6
- it('should create a button with requested label and classes', () => {
7
- // [ARRANGE]
8
- const mockElement = {
9
- parent: vi.fn(),
10
- addClass: vi.fn(),
11
- };
12
- const mockP5 = {
13
- createDiv: vi.fn().mockReturnValue(mockElement),
14
- createButton: vi.fn().mockReturnValue(mockElement),
15
- } as unknown as p5;
16
- const mockContainer = {} as p5.Element;
17
-
18
- // [ACT]
19
- const result = Button(mockP5, mockContainer, 'UP');
20
-
21
- // [ASSERT]
22
- expect(mockP5.createDiv).toHaveBeenCalled();
23
- expect(mockP5.createButton).toHaveBeenCalledWith('UP');
24
- expect(mockElement.parent).toHaveBeenCalledWith(mockContainer); // Div parent
25
- expect(mockElement.parent).toHaveBeenCalledWith(mockElement); // Button parent (self-referencing mock)
26
- expect(mockElement.addClass).toHaveBeenCalledWith('btn-container');
27
- expect(mockElement.addClass).toHaveBeenCalledWith('btn');
28
- expect(result).toBe(mockElement);
29
- });
30
- });
@@ -1,30 +0,0 @@
1
- import p5 from 'p5';
2
-
3
- /**
4
- * Creates a standard directional button.
5
- *
6
- * These buttons are used for the D-pad controls (Up, Down, Left, Right).
7
- *
8
- * @param p - The p5 instance.
9
- * @param container - The container element to attach the button to.
10
- * @param label - The text label for the button.
11
- * @returns The created button element.
12
- */
13
- export default function Button(p: p5, container: p5.Element, label: string) {
14
- //Container
15
- const buttonContainer = p.createDiv();
16
- buttonContainer.parent(container);
17
- buttonContainer.addClass('btn-container');
18
-
19
- //Button
20
- const button = p.createButton(label);
21
- button.parent(buttonContainer);
22
- button.addClass('btn');
23
-
24
- //Label
25
- // const paragraph = p.createP(label);
26
- // paragraph.parent(buttonContainer);
27
- // paragraph.addClass('btn-p');
28
-
29
- return button;
30
- }
@@ -1,32 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import type p5 from 'p5';
3
- import Canvas from './Canvas';
4
-
5
- describe('Canvas', () => {
6
- it('should create a canvas with calculated dimensions from configs', () => {
7
- // [ARRANGE]
8
- const mockElement = {
9
- parent: vi.fn(),
10
- id: vi.fn(),
11
- };
12
- const mockP5 = {
13
- createCanvas: vi.fn().mockReturnValue(mockElement),
14
- } as unknown as p5;
15
- const mockContainer = {} as p5.Element;
16
-
17
- // Ratios from actual configs: widthRatio: 0.7, aspectRatio: 1.114
18
- const width = 500;
19
- const expectedWidth = 500 * 0.7; // 350
20
- const expectedHeight = expectedWidth * 1.114; // 389.9
21
-
22
- // [ACT]
23
- const result = Canvas(mockP5, mockContainer, width);
24
-
25
- // [ASSERT]
26
- expect(mockP5.createCanvas).toHaveBeenCalledWith(expectedWidth, expectedHeight);
27
- expect(mockElement.parent).toHaveBeenCalledWith(mockContainer);
28
- expect(mockElement.id).toHaveBeenCalledWith('brick-game-canvas');
29
- expect(result.canvasWidth).toBe(expectedWidth);
30
- expect(result.canvasHeight).toBe(expectedHeight);
31
- });
32
- });
@@ -1,34 +0,0 @@
1
- import p5 from 'p5';
2
-
3
- import configs from '../../../config/configs';
4
-
5
- /**
6
- * Response object containing canvas dimensions and element reference.
7
- */
8
- interface CanvasResponse {
9
- canvasWidth: number;
10
- canvasHeight: number;
11
- canvas: p5.Element;
12
- }
13
-
14
- /**
15
- * Creates the main p5 canvas for rendering the game.
16
- *
17
- * It calculates the canvas size based on the provided container width, maintaining a specific aspect ratio
18
- * defined by `configs.viewLayout.canvas.aspectRatio`.
19
- *
20
- * @param {p5} p - The p5 instance.
21
- * @param {p5.Element} container - The frame container to attach the canvas to.
22
- * @param {number} width - The width of the outer container, used to calculate canvas dimensions with `configs.viewLayout.canvas.widthRatio`.
23
- * @returns {CanvasResponse} Object containing the canvas element and its calculated dimensions.
24
- */
25
- export default function Canvas(p: p5, container: p5.Element, width: number): CanvasResponse {
26
- const canvasWidth = width * configs.viewLayout.canvas.widthRatio;
27
- const canvasHeight = canvasWidth * configs.viewLayout.canvas.aspectRatio;
28
-
29
- const canvas = p.createCanvas(canvasWidth, canvasHeight);
30
- canvas.parent(container);
31
- canvas.id(configs.selectors.viewElementIds.canvas);
32
-
33
- return { canvasWidth, canvasHeight, canvas };
34
- }
@@ -1,48 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import type p5 from 'p5';
3
- import SmallButton from './SmallButton';
4
-
5
- describe('SmallButton', () => {
6
- it('should create a small button with paragraph label', () => {
7
- // [ARRANGE]
8
- const mockElement = {
9
- parent: vi.fn(),
10
- addClass: vi.fn(),
11
- };
12
- const mockP5 = {
13
- createDiv: vi.fn().mockReturnValue(mockElement),
14
- createButton: vi.fn().mockReturnValue(mockElement),
15
- createP: vi.fn().mockReturnValue(mockElement),
16
- } as unknown as p5;
17
- const mockContainer = {} as p5.Element;
18
-
19
- // [ACT]
20
- const result = SmallButton(mockP5, mockContainer, 'Reset', true);
21
-
22
- // [ASSERT]
23
- expect(mockP5.createDiv).toHaveBeenCalled();
24
- expect(mockP5.createButton).toHaveBeenCalledWith('');
25
- expect(mockP5.createP).toHaveBeenCalledWith('Reset');
26
- expect(mockElement.addClass).toHaveBeenCalledWith('sm-btn-container');
27
- expect(mockElement.addClass).toHaveBeenCalledWith('sm-btn-container-top');
28
- expect(mockElement.addClass).toHaveBeenCalledWith('sm-btn');
29
- expect(mockElement.addClass).toHaveBeenCalledWith('sm-btn-p');
30
- expect(result).toBe(mockElement);
31
- });
32
-
33
- it('should use bottom class when top is false', () => {
34
- // [ARRANGE]
35
- const mockElement = { parent: vi.fn(), addClass: vi.fn() };
36
- const mockP5 = {
37
- createDiv: vi.fn().mockReturnValue(mockElement),
38
- createButton: vi.fn().mockReturnValue(mockElement),
39
- createP: vi.fn().mockReturnValue(mockElement),
40
- } as unknown as p5;
41
-
42
- // [ACT]
43
- SmallButton(mockP5, {} as p5.Element, 'Test', false);
44
-
45
- // [ASSERT]
46
- expect(mockElement.addClass).toHaveBeenCalledWith('sm-btn-container-bottom');
47
- });
48
- });
@@ -1,32 +0,0 @@
1
- import p5 from 'p5';
2
-
3
- /**
4
- * Creates a small system button (e.g., Reset, Sound).
5
- *
6
- * These buttons have a distinct style and include a visible paragraph label next to them.
7
- *
8
- * @param {p5} p - The p5 instance.
9
- * @param {p5.Element} container - The container element to attach the button to.
10
- * @param {string} label - The visible text label displayed near the button.
11
- * @param {boolean} top - Determines position/styling nuance (e.g. if it belongs to the top row of small buttons).
12
- * @returns {p5.Element} The created button element.
13
- */
14
- export default function SmallButton(p: p5, container: p5.Element, label: string, top: boolean) {
15
- //Container
16
- const buttonContainer = p.createDiv();
17
- buttonContainer.parent(container);
18
- buttonContainer.addClass('sm-btn-container');
19
- buttonContainer.addClass(top ? 'sm-btn-container-top' : 'sm-btn-container-bottom');
20
-
21
- //Button
22
- const button = p.createButton('');
23
- button.parent(buttonContainer);
24
- button.addClass('sm-btn');
25
-
26
- //Label
27
- const paragraph = p.createP(label);
28
- paragraph.parent(buttonContainer);
29
- paragraph.addClass('sm-btn-p');
30
-
31
- return button;
32
- }
@@ -1,47 +0,0 @@
1
- /** @vitest-environment jsdom */
2
- import { describe, it, expect, vi, beforeEach } from 'vitest';
3
- import applyColors from './applyColors';
4
-
5
- describe('applyColors', () => {
6
- let root: HTMLElement;
7
-
8
- beforeEach(() => {
9
- // Setup JSDOM :root element styles
10
- root = document.documentElement;
11
- root.style.cssText = '';
12
-
13
- // Default location mock
14
- vi.stubGlobal('location', {
15
- href: 'http://localhost/',
16
- });
17
- });
18
-
19
- it('should apply default colors when no query params are present', () => {
20
- // [ACT]
21
- applyColors();
22
-
23
- // [ASSERT]
24
- // Default bodyMain is rgb(0, 68, 187)
25
- expect(root.style.getPropertyValue('--main-color')).toBe('rgb(0, 68, 187)');
26
- expect(root.style.getPropertyValue('--button-color')).toBe('rgb(247, 222, 57)');
27
- });
28
-
29
- it('should apply colors from query parameters', () => {
30
- // [ARRANGE]
31
- // body-color and button-color are the keys in configs
32
- vi.stubGlobal('location', {
33
- href: 'http://localhost/?body-color=%23ff0000&button-color=%2300ff00',
34
- });
35
-
36
- // [ACT]
37
- applyColors();
38
-
39
- // [ASSERT]
40
- // JSDOM might return rgb(255, 0, 0) for #ff0000
41
- const mainColor = root.style.getPropertyValue('--main-color');
42
- expect(mainColor === '#ff0000' || mainColor === 'rgb(255, 0, 0)').toBe(true);
43
-
44
- const buttonColor = root.style.getPropertyValue('--button-color');
45
- expect(buttonColor === '#00ff00' || buttonColor === 'rgb(0, 255, 0)').toBe(true);
46
- });
47
- });
@@ -1,38 +0,0 @@
1
- import { colord } from 'colord';
2
-
3
- import configs from '../../config/configs';
4
-
5
- // prettier-ignore
6
- /**
7
- * Applies color themes to the application by setting CSS variables.
8
- *
9
- * It checks for `configs.inputQueryParams.mainColor` and `configs.inputQueryParams.buttonColor` query parameters in the URL.
10
- * If present, these values are used; otherwise, default `configs.colors` are applied.
11
- * It also calculates and sets shadow and reflection variations for these colors.
12
- *
13
- * @returns {void}
14
- */
15
- export default function applyColors() {
16
- const root: HTMLElement = document.querySelector(':root');
17
-
18
- const paramsString = window.location.href.substring(
19
- window.location.href.indexOf('?') + 1,
20
- );
21
- const searchParams = new URLSearchParams(paramsString);
22
-
23
- const mainColor = searchParams.has(configs.inputQueryParams.mainColor)
24
- ? searchParams.get(configs.inputQueryParams.mainColor)
25
- : configs.colors.bodyMain;
26
-
27
- const buttonColor = searchParams.has(configs.inputQueryParams.buttonColor)
28
- ? searchParams.get(configs.inputQueryParams.buttonColor)
29
- : configs.colors.bodyButton;
30
-
31
- root.style.setProperty('--main-color' , mainColor);
32
- root.style.setProperty('--button-color' , buttonColor);
33
-
34
- root.style.setProperty('--color-shadow' , colord(mainColor) .darken(0.15).toHex());
35
- root.style.setProperty('--color-shadow-reflexion', colord(mainColor) .lighten(0.15).toHex());
36
- root.style.setProperty('--button-color-reflexion', colord(buttonColor).lighten(0.15).toHex());
37
- root.style.setProperty('--button-color-shadow' , colord(buttonColor).darken(0.15).toHex());
38
- }
@@ -1,34 +0,0 @@
1
- /** @vitest-environment jsdom */
2
- import { describe, it, expect, beforeEach } from 'vitest';
3
- import dimensions from './dimensions';
4
-
5
- describe('dimensions', () => {
6
- let root: HTMLElement;
7
-
8
- beforeEach(() => {
9
- root = document.documentElement;
10
- // Clear properties
11
- root.style.cssText = '';
12
- });
13
-
14
- it('should set CSS variables based on input dimensions', () => {
15
- // [ARRANGE]
16
- const width = 400;
17
- const height = 800;
18
- const canvasWidth = 300;
19
- const canvasHeight = 600;
20
-
21
- // [ACT]
22
- dimensions(width, height, canvasWidth, canvasHeight);
23
-
24
- // [ASSERT]
25
- expect(root.style.getPropertyValue('--width')).toBe('400px');
26
- expect(root.style.getPropertyValue('--height')).toBe('800px');
27
- expect(root.style.getPropertyValue('--canvas-width')).toBe('300px');
28
- expect(root.style.getPropertyValue('--canvas-height')).toBe('600px');
29
-
30
- // Multiplier from configs: 1.9
31
- // borderRadiusRatio: 0.05 -> 400 * 0.05 = 20px
32
- expect(root.style.getPropertyValue('--border-radius')).toBe('20px');
33
- });
34
- });
@@ -1,53 +0,0 @@
1
- import configs from '../../config/configs';
2
-
3
- // prettier-ignore
4
- /**
5
- * Calculates and sets various CSS variables for responsive sizing of the game UI.
6
- *
7
- * This function defines sizes for the main container, canvas, borders, buttons (including mobile variations),
8
- * and fonts based on the provided dimensions.
9
- *
10
- * @param width - The width of the game container.
11
- * @param height - The height of the game container.
12
- * @param canvasWidth - The width of the game canvas.
13
- * @param canvasHeight - The height of the game canvas.
14
- * @returns
15
- */
16
- export default function dimensions(
17
- width: number,
18
- height: number,
19
- canvasWidth: number,
20
- canvasHeight: number,
21
- ) {
22
- const root: HTMLElement = document.querySelector(':root');
23
-
24
- root.style.setProperty('--dispersion' , configs.viewLayout.shadowDispersion);
25
-
26
- root.style.setProperty('--width' , `${width}px`);
27
- root.style.setProperty('--height' , `${height}px`);
28
-
29
- root.style.setProperty('--canvas-width' , `${canvasWidth}px`);
30
- root.style.setProperty('--canvas-height' , `${canvasHeight}px`);
31
-
32
- root.style.setProperty('--border-radius' , `${width * configs.viewLayout.dimensions.borderRadiusRatio}px`);
33
- root.style.setProperty('--border' , `${width * configs.viewLayout.dimensions.borderWidthRatio}px solid black`);
34
-
35
- root.style.setProperty('--sm-button-size' , `${width * configs.viewLayout.dimensions.button.smSizeRatio}px`);
36
- root.style.setProperty('--button-size' , `${width * configs.viewLayout.dimensions.button.mdSizeRatio}px`);
37
- root.style.setProperty('--lg-button-size' , `${width * configs.viewLayout.dimensions.button.lgSizeRatio}px`);
38
-
39
- root.style.setProperty('--sm-button-size-mobile' , `${width * configs.viewLayout.dimensions.button.mobile.smSizeRatio}px`);
40
- root.style.setProperty('--button-size-mobile' , `${width * configs.viewLayout.dimensions.button.mobile.mdSizeRatio}px`);
41
- root.style.setProperty('--lg-button-size-mobile' , `${width * configs.viewLayout.dimensions.button.mobile.lgSizeRatio}px`);
42
-
43
- root.style.setProperty('--sm-button-size-mobile-font-size' , `${width * configs.viewLayout.dimensions.button.mobile.smFontRatio}px`);
44
- root.style.setProperty('--sm-button-size-mobile-line-height' , `${width * configs.viewLayout.dimensions.button.mobile.smFontRatio}px`);
45
-
46
- root.style.setProperty('--button-size-mobile-font-size' , `${width * configs.viewLayout.dimensions.button.mobile.fontRatio}px`);
47
- root.style.setProperty('--lg-button-size-mobile-font-size' , `${width * configs.viewLayout.dimensions.button.mobile.lgFontRatio}px`);
48
-
49
- root.style.setProperty('--button-size-mobile-spacing' , `${width * configs.viewLayout.dimensions.button.mobile.spacingRatio}px`);
50
-
51
- root.style.setProperty('--button-border' , `${width * configs.viewLayout.dimensions.button.borderRatio}px solid black`);
52
- root.style.setProperty('--button-animation-duration' , configs.viewLayout.dimensions.button.animationDuration);
53
- }
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./dist/",
4
- "noImplicitAny": true,
5
- "module": "ESNext",
6
- "target": "es5",
7
- "jsx": "react",
8
- "allowJs": true,
9
- "moduleResolution": "node",
10
- "resolveJsonModule": true,
11
- "skipLibCheck": true,
12
- "types": ["node", "webpack-env", "p5"],
13
- "declaration": true
14
- },
15
- "include": ["src/**/*"]
16
- }
package/vitest.config.ts DELETED
@@ -1,14 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
- import path from 'path';
3
-
4
- export default defineConfig({
5
- resolve: {
6
- alias: {
7
- '@client-game': path.resolve(__dirname, './src/core/Game.ts'),
8
- },
9
- },
10
- test: {
11
- globals: true,
12
- environment: 'node',
13
- },
14
- });
package/webpack.config.js DELETED
@@ -1,133 +0,0 @@
1
- const HtmlWebpackPlugin = require('html-webpack-plugin');
2
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
3
- const CopyWebpackPlugin = require('copy-webpack-plugin');
4
- const path = require('path');
5
- const webpack = require('webpack');
6
- const dotenv = require('dotenv');
7
- const fs = require('fs');
8
-
9
- module.exports = (env = {}, argv) => {
10
- const isProduction = argv.mode === 'production';
11
- const appMode = env.mode || 'server'; // 'server' or 'client'
12
- const clientGamePath = env.game ? path.resolve(process.cwd(), env.game) : path.resolve(__dirname, 'src/menu/GameMenu.ts');
13
-
14
- // Load .env files, .env.local takes precedence.
15
- const envFileLocal = path.resolve(__dirname, '.env.local');
16
- const envFile = path.resolve(__dirname, '.env');
17
-
18
- let envConfig = {};
19
- if (fs.existsSync(envFile)) {
20
- Object.assign(envConfig, dotenv.config({ path: envFile }).parsed);
21
- }
22
- if (fs.existsSync(envFileLocal)) {
23
- Object.assign(envConfig, dotenv.config({ path: envFileLocal }).parsed);
24
- }
25
-
26
- // Fallback logic for webpack
27
- const SUPABASE_URL = process.env.SUPABASE_URL || envConfig.SUPABASE_URL || 'http://127.0.0.1:54321';
28
- const SUPABASE_ANON_KEY = process.env.SUPABASE_ANON_KEY || envConfig.SUPABASE_ANON_KEY || '';
29
-
30
- return {
31
- mode: isProduction ? 'production' : 'development',
32
- entry: {
33
- 'brick-engine': './src/index.ts',
34
- app: './src/main.ts',
35
- },
36
- devtool: isProduction ? 'source-map' : 'eval-source-map',
37
- output: {
38
- filename: '[name].js',
39
- path: path.resolve(__dirname, 'dist'),
40
- clean: true, // Clean the output directory before emit.
41
- publicPath: 'auto',
42
- library: {
43
- name: 'BrickEngine',
44
- type: 'umd',
45
- },
46
- },
47
- externals: {
48
- p5: 'p5',
49
- },
50
- module: {
51
- rules: [
52
- {
53
- test: /\.ts$/,
54
- use: 'ts-loader',
55
- exclude: /node_modules/,
56
- },
57
- {
58
- test: /\.css$/i,
59
- use: [
60
- {
61
- loader: MiniCssExtractPlugin.loader,
62
- options: {
63
- publicPath: '../', // CSS is in css/ folder, needs to go up to find images/fonts
64
- },
65
- },
66
- 'css-loader',
67
- ],
68
- },
69
- {
70
- test: /\.(woff|woff2|eot|ttf|otf)$/i, // Fonts (Required for CSS url() resolution)
71
- type: 'asset/resource',
72
- generator: {
73
- filename: 'fonts/[name][ext]',
74
- },
75
- },
76
- ],
77
- },
78
- resolve: {
79
- extensions: ['.tsx', '.ts', '.js', '.css', '.wav', '.png', '.ico', '.gif', '.json', '.svg', '.webmanifest'],
80
- alias: {
81
- '@client-game': clientGamePath,
82
- },
83
- },
84
- devServer: {
85
- static: [
86
- {
87
- directory: path.resolve(__dirname, 'dist'),
88
- },
89
- ],
90
- port: 9000,
91
- open: true,
92
- hot: true,
93
- historyApiFallback: true,
94
- },
95
- plugins: [
96
- new webpack.DefinePlugin({
97
- 'process.env.APP_MODE': JSON.stringify(appMode),
98
- 'process.env.SUPABASE_URL': JSON.stringify(SUPABASE_URL),
99
- 'process.env.SUPABASE_ANON_KEY': JSON.stringify(SUPABASE_ANON_KEY),
100
- }),
101
- new HtmlWebpackPlugin({
102
- template: './public/index.html',
103
- filename: 'index.html', // Output file name
104
- favicon: './public/favicon.ico',
105
- inject: 'body',
106
- chunks: ['app'], // Only inject the app bundle, not the library
107
- minify: isProduction
108
- ? {
109
- removeComments: true,
110
- collapseWhitespace: true,
111
- removeAttributeQuotes: true,
112
- }
113
- : false,
114
- }),
115
- new MiniCssExtractPlugin({
116
- filename: isProduction ? 'css/[name].[contenthash].css' : 'css/[name].bundle.css',
117
- }),
118
- new CopyWebpackPlugin({
119
- patterns: [
120
- { from: 'node_modules/p5/lib/p5.min.js', to: 'vendor/p5.min.js' },
121
- { from: 'public/images', to: 'images' },
122
- { from: 'public/sounds', to: 'sounds' },
123
- { from: 'public/docs', to: 'docs' },
124
- { from: 'public/favicon.ico', to: './' },
125
- { from: 'public/CNAME', to: './' },
126
- ],
127
- }),
128
- ],
129
- optimization: {
130
- minimize: isProduction,
131
- },
132
- };
133
- };