brick-engine-js 1.0.1 → 1.0.3

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 (131) 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 +8 -1
  13. package/public/docs/GAME_DEVELOPER_GUIDE.html +1 -1
  14. package/public/docs/brick-engine-guide.html +1 -1
  15. package/public/docs/getting-started.html +1 -1
  16. package/public/docs/jsdoc_standard.html +1 -1
  17. package/public/docs/publishing.html +1 -1
  18. package/public/docs/reference/interfaces/modules/Session.html +1 -1
  19. package/public/docs/reference/modules/GameMenu.html +1 -1
  20. package/public/docs/reference/modules/GameSession.html +1 -1
  21. package/public/docs/reference/modules/InitialStateSnapshot.html +1 -1
  22. package/public/docs/reference/modules/SessionModal.html +1 -1
  23. package/public/docs/testing_best_practices.html +1 -1
  24. package/.env.local.example +0 -2
  25. package/.github/workflows/publish.yml +0 -73
  26. package/.prettierignore +0 -2
  27. package/.prettierrc.json +0 -8
  28. package/eslint.config.mjs +0 -29
  29. package/scripts/generate-diagrams.sh +0 -20
  30. package/scripts/generate-docs.js +0 -111
  31. package/src/client-game.d.ts +0 -1
  32. package/src/config/configs.test.ts +0 -20
  33. package/src/config/configs.ts +0 -197
  34. package/src/config/env.test.ts +0 -59
  35. package/src/config/env.ts +0 -7
  36. package/src/config/styles.ts +0 -5
  37. package/src/core/Game.test.ts +0 -167
  38. package/src/core/Game.ts +0 -307
  39. package/src/core/InitialStateSnapshot.test.ts +0 -51
  40. package/src/core/InitialStateSnapshot.ts +0 -46
  41. package/src/core/helpers/CellHelper.test.ts +0 -33
  42. package/src/core/helpers/CellHelper.ts +0 -21
  43. package/src/core/helpers/ControlInputHandlerHelper.test.ts +0 -116
  44. package/src/core/helpers/ControlInputHandlerHelper.ts +0 -68
  45. package/src/core/helpers/CoordinateHelper.test.ts +0 -113
  46. package/src/core/helpers/CoordinateHelper.ts +0 -82
  47. package/src/core/helpers/InterfaceIdentifierHelper.test.ts +0 -122
  48. package/src/core/helpers/InterfaceIdentifierHelper.ts +0 -43
  49. package/src/core/helpers/RelativeValuesHelper.test.ts +0 -47
  50. package/src/core/helpers/RelativeValuesHelper.ts +0 -29
  51. package/src/core/module/control/GameControl.test.ts +0 -82
  52. package/src/core/module/control/GameControl.ts +0 -142
  53. package/src/core/module/control/GameControlKeyBinding.test.ts +0 -59
  54. package/src/core/module/control/GameControlKeyBinding.ts +0 -92
  55. package/src/core/module/grid/GameGrid.test.ts +0 -83
  56. package/src/core/module/grid/GameGrid.ts +0 -610
  57. package/src/core/module/grid/GameHudGrid.test.ts +0 -22
  58. package/src/core/module/grid/GameHudGrid.ts +0 -40
  59. package/src/core/module/grid/engines/GridAnalysisEngine.test.ts +0 -157
  60. package/src/core/module/grid/engines/GridAnalysisEngine.ts +0 -124
  61. package/src/core/module/grid/engines/GridLineEngine.test.ts +0 -132
  62. package/src/core/module/grid/engines/GridLineEngine.ts +0 -165
  63. package/src/core/module/grid/engines/GridMovementEngine.test.ts +0 -125
  64. package/src/core/module/grid/engines/GridMovementEngine.ts +0 -113
  65. package/src/core/module/grid/engines/GridRegionEngine.test.ts +0 -136
  66. package/src/core/module/grid/engines/GridRegionEngine.ts +0 -52
  67. package/src/core/module/grid/engines/GridTransformEngine.test.ts +0 -98
  68. package/src/core/module/grid/engines/GridTransformEngine.ts +0 -70
  69. package/src/core/module/renderer/DisplayRenderer.test.ts +0 -86
  70. package/src/core/module/renderer/DisplayRenderer.ts +0 -152
  71. package/src/core/module/renderer/GameRenderer.test.ts +0 -103
  72. package/src/core/module/renderer/GameRenderer.ts +0 -144
  73. package/src/core/module/renderer/HudRenderer.test.ts +0 -108
  74. package/src/core/module/renderer/HudRenderer.ts +0 -203
  75. package/src/core/module/score/GameScore.test.ts +0 -71
  76. package/src/core/module/score/GameScore.ts +0 -188
  77. package/src/core/module/session/GameSession.test.ts +0 -176
  78. package/src/core/module/session/GameSession.ts +0 -103
  79. package/src/core/module/sound/GameSound.test.ts +0 -117
  80. package/src/core/module/sound/GameSound.ts +0 -229
  81. package/src/core/module/state/GameState.test.ts +0 -101
  82. package/src/core/module/state/GameState.ts +0 -339
  83. package/src/core/module/text/GameText.test.ts +0 -87
  84. package/src/core/module/text/GameText.ts +0 -150
  85. package/src/core/module/time/GameTime.test.ts +0 -86
  86. package/src/core/module/time/GameTime.ts +0 -144
  87. package/src/core/types/Interfaces.ts +0 -59
  88. package/src/core/types/Types.ts +0 -124
  89. package/src/core/types/enums.ts +0 -113
  90. package/src/core/types/modules.ts +0 -841
  91. package/src/index.test.ts +0 -15
  92. package/src/index.ts +0 -9
  93. package/src/main.test.ts +0 -137
  94. package/src/main.ts +0 -77
  95. package/src/menu/GameMenu.test.ts +0 -157
  96. package/src/menu/GameMenu.ts +0 -124
  97. package/src/menu/GameMenuSingleton.test.ts +0 -26
  98. package/src/menu/GameMenuSingleton.ts +0 -13
  99. package/src/menu/GameRepository.test.ts +0 -46
  100. package/src/menu/GameRepository.ts +0 -47
  101. package/src/menu/manager/GameManager.test.ts +0 -68
  102. package/src/menu/manager/GameManager.ts +0 -50
  103. package/src/types/global.d.ts +0 -8
  104. package/src/types/interfaces.ts +0 -5
  105. package/src/view/Debugger.test.ts +0 -152
  106. package/src/view/Debugger.ts +0 -124
  107. package/src/view/GameView.test.ts +0 -95
  108. package/src/view/GameView.ts +0 -244
  109. package/src/view/SessionModal.test.ts +0 -141
  110. package/src/view/SessionModal.ts +0 -73
  111. package/src/view/components/layout/ButtonLayout.test.ts +0 -28
  112. package/src/view/components/layout/ButtonLayout.ts +0 -63
  113. package/src/view/components/layout/ContainerLayout.test.ts +0 -48
  114. package/src/view/components/layout/ContainerLayout.ts +0 -50
  115. package/src/view/components/layout/FrameLayout.test.ts +0 -24
  116. package/src/view/components/layout/FrameLayout.ts +0 -25
  117. package/src/view/components/ui/BigButton.test.ts +0 -28
  118. package/src/view/components/ui/BigButton.ts +0 -31
  119. package/src/view/components/ui/Button.test.ts +0 -30
  120. package/src/view/components/ui/Button.ts +0 -30
  121. package/src/view/components/ui/Canvas.test.ts +0 -32
  122. package/src/view/components/ui/Canvas.ts +0 -34
  123. package/src/view/components/ui/SmallButton.test.ts +0 -48
  124. package/src/view/components/ui/SmallButton.ts +0 -32
  125. package/src/view/theme/applyColors.test.ts +0 -47
  126. package/src/view/theme/applyColors.ts +0 -38
  127. package/src/view/theme/dimensions.test.ts +0 -34
  128. package/src/view/theme/dimensions.ts +0 -53
  129. package/tsconfig.json +0 -16
  130. package/vitest.config.ts +0 -14
  131. 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
- };