brick-engine-js 1.0.38 → 1.0.40
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/README.adoc +1 -1
- package/dist/docs/index.html +2 -2
- package/dist/docs/reference/enums/ControlKey.html +4 -0
- package/dist/docs/reference/enums/ScoreProperty.html +526 -0
- package/dist/docs/reference/enums/StateProperty.html +4 -0
- package/dist/docs/reference/interfaces/StateSyncable.html +1 -1
- package/dist/docs/reference/interfaces/modules/Score.html +182 -32
- package/dist/docs/reference/interfaces/modules/State.html +88 -36
- package/dist/docs/reference/interfaces/modules/Time.html +61 -145
- package/dist/docs/reference/modules/GameEventRegistry.html +10 -4
- package/dist/docs/reference/modules/GameScore.html +339 -71
- package/dist/docs/reference/modules/GameState.html +256 -163
- package/dist/docs/reference/modules/GameTime.html +136 -149
- package/dist/game.bundle.js +1 -1
- package/dist/types/config/configs.d.ts +2 -4
- package/dist/types/core/Game.d.ts +17 -10
- package/dist/types/core/module/score/GameScore.d.ts +24 -0
- package/dist/types/core/module/time/GameTime.d.ts +62 -63
- package/dist/types/core/types/enums.d.ts +11 -0
- package/dist/types/core/types/modules.d.ts +70 -60
- package/dist/types/view/ShortcutsModal.test.d.ts +1 -0
- package/package.json +1 -1
|
@@ -2,18 +2,21 @@ import { Debuggable } from '../../types/Interfaces';
|
|
|
2
2
|
import { Time } from '../../types/modules';
|
|
3
3
|
import { Serializable } from '../../types/Interfaces';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Orchestrates the engine's logical clock and performance metrics.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
* of the browser
|
|
9
|
-
*
|
|
10
|
-
* host device's
|
|
7
|
+
* Designed to decouple deterministic game logic "ticks" from the unpredictable
|
|
8
|
+
* visual frame rate of the browser. By maintaining an internal time accumulator,
|
|
9
|
+
* it ensures that gameplay events (like physics, timers, and difficulty scaling)
|
|
10
|
+
* execute at a consistent speed regardless of the host device's hardware
|
|
11
|
+
* performance or FPS fluctuations.
|
|
12
|
+
*
|
|
13
|
+
* Implements the {@link Time} interface to provide a standardized timing
|
|
14
|
+
* contract for all engine modules.
|
|
11
15
|
*/
|
|
12
16
|
export default class GameTime implements Time, Debuggable, Serializable {
|
|
13
17
|
protected _tickAccumulator: number;
|
|
14
18
|
/** The tick interval at the start of the game session. Used for resets. */
|
|
15
19
|
private _initialTickInterval;
|
|
16
|
-
private _minTickInterval;
|
|
17
20
|
private _tickInterval;
|
|
18
21
|
private _fps;
|
|
19
22
|
private _tps;
|
|
@@ -22,26 +25,58 @@ export default class GameTime implements Time, Debuggable, Serializable {
|
|
|
22
25
|
private _timeSinceLastTpsUpdate;
|
|
23
26
|
private _totalElapsedTime;
|
|
24
27
|
serialId: string;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the total number of ticks since the game started.
|
|
30
|
+
*
|
|
31
|
+
* @returns {number} Total tick count.
|
|
32
|
+
*/
|
|
33
|
+
get totalTicks(): number;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the total elapsed time in milliseconds.
|
|
36
|
+
*
|
|
37
|
+
* @returns {number} Elapsed time in ms.
|
|
38
|
+
*/
|
|
39
|
+
get elapsedTime(): number;
|
|
25
40
|
/**
|
|
26
41
|
* Initializes the time module's core state.
|
|
27
|
-
* Resets all internal timers and statistical accumulators securely.
|
|
28
42
|
*
|
|
29
|
-
*
|
|
43
|
+
* Resets all internal timers and statistical accumulators to their
|
|
44
|
+
* baseline values, ensuring a clean state for a new game session.
|
|
45
|
+
*
|
|
46
|
+
* @returns {void}
|
|
30
47
|
*/
|
|
31
48
|
setup(): void;
|
|
32
49
|
/**
|
|
33
|
-
* Updates the
|
|
34
|
-
* Must be invoked strictly once per hardware visual frame.
|
|
50
|
+
* Updates the physical performance metrics.
|
|
35
51
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
52
|
+
* Calculates the current Frames Per Second (FPS) and updates the Ticks
|
|
53
|
+
* Per Second (TPS) statistics. This method should be called exactly
|
|
54
|
+
* once per visual frame in the main loop.
|
|
55
|
+
*
|
|
56
|
+
* @param {number} deltaTime - The physical time physically elapsed since the last rendering frame in milliseconds.
|
|
57
|
+
* @returns {void}
|
|
38
58
|
*/
|
|
39
59
|
update(deltaTime: number): void;
|
|
40
60
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
61
|
+
* Adds elapsed time to the simulation accumulator.
|
|
62
|
+
*
|
|
63
|
+
* This time is used to determine when the next logical tick should
|
|
64
|
+
* be processed. It allows the engine to "catch up" if the frame
|
|
65
|
+
* rate drops below the target tick rate.
|
|
66
|
+
*
|
|
67
|
+
* @param {number} deltaTime - Time in milliseconds to add to the logic simulation.
|
|
68
|
+
* @returns {void}
|
|
69
|
+
*/
|
|
70
|
+
accumulate(deltaTime: number): void;
|
|
71
|
+
/**
|
|
72
|
+
* Evaluates if the engine should execute a logical simulation tick.
|
|
43
73
|
*
|
|
44
|
-
*
|
|
74
|
+
* Checks if the accumulated time exceeds the required tick interval.
|
|
75
|
+
* If so, it consumes all pending time in the accumulator and
|
|
76
|
+
* increments the logical counters.
|
|
77
|
+
*
|
|
78
|
+
* @internal Used specifically by the engine's core orchestration loop.
|
|
79
|
+
* @returns {boolean} `true` if at least one tick's worth of time was consumed.
|
|
45
80
|
*/
|
|
46
81
|
shouldTick(): boolean;
|
|
47
82
|
/**
|
|
@@ -51,30 +86,24 @@ export default class GameTime implements Time, Debuggable, Serializable {
|
|
|
51
86
|
*/
|
|
52
87
|
reset(): void;
|
|
53
88
|
/**
|
|
54
|
-
*
|
|
89
|
+
* Checks if enough logical time has passed based on a specific millisecond interval.
|
|
90
|
+
* Use for time-based triggers that need to be stable even if the frame rate varies.
|
|
55
91
|
*
|
|
56
|
-
* @
|
|
92
|
+
* @param {number} ms - The millisecond interval to check.
|
|
93
|
+
* @returns {boolean} True if the logical clock just crossed a multiple of the interval.
|
|
57
94
|
*/
|
|
58
|
-
|
|
95
|
+
atInterval(ms: number): boolean;
|
|
59
96
|
/**
|
|
60
|
-
*
|
|
97
|
+
* Executes a callback function every N milliseconds of logical game time.
|
|
61
98
|
*
|
|
62
|
-
*
|
|
63
|
-
|
|
64
|
-
set tickInterval(interval: number);
|
|
65
|
-
/**
|
|
66
|
-
* Increments the tick interval (slowing down the game).
|
|
99
|
+
* Provides a declarative functional approach to handling recurring game logic,
|
|
100
|
+
* such as spawning enemies or updating timers.
|
|
67
101
|
*
|
|
68
|
-
* @param {number}
|
|
102
|
+
* @param {number} ms - The millisecond interval between executions.
|
|
103
|
+
* @param {() => void} action - The callback function to execute if the interval is crossed.
|
|
104
|
+
* @returns {void}
|
|
69
105
|
*/
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Decrements the tick interval (speeding up the game).
|
|
73
|
-
* Enforces a minimum interval of 10ms.
|
|
74
|
-
*
|
|
75
|
-
* @param {number} amount - The amount to subtract from the interval.
|
|
76
|
-
*/
|
|
77
|
-
decrementTickInterval(amount: number): void;
|
|
106
|
+
every(ms: number, action: () => void): void;
|
|
78
107
|
/**
|
|
79
108
|
* Retrieves debug information about the time system.
|
|
80
109
|
*
|
|
@@ -83,34 +112,4 @@ export default class GameTime implements Time, Debuggable, Serializable {
|
|
|
83
112
|
getDebugData(): Record<string, string | number | boolean>;
|
|
84
113
|
serialize(): string;
|
|
85
114
|
deserialize(data: string): void;
|
|
86
|
-
setTickInterval(interval: number): void;
|
|
87
|
-
setMinTickInterval(interval: number): void;
|
|
88
|
-
/**
|
|
89
|
-
* Gets the total number of ticks since the game started.
|
|
90
|
-
*
|
|
91
|
-
* @returns {number} Total tick count.
|
|
92
|
-
*/
|
|
93
|
-
get totalTicks(): number;
|
|
94
|
-
/**
|
|
95
|
-
* Gets the total elapsed time in milliseconds.
|
|
96
|
-
*
|
|
97
|
-
* @returns {number} Elapsed time in ms.
|
|
98
|
-
*/
|
|
99
|
-
get elapsedTime(): number;
|
|
100
|
-
/**
|
|
101
|
-
* Checks if the current total tick count is a multiple of the provided interval.
|
|
102
|
-
*
|
|
103
|
-
* @param {number} interval - The tick interval to check.
|
|
104
|
-
* @returns {boolean} True if the current tick is a multiple of the interval.
|
|
105
|
-
*/
|
|
106
|
-
isTickEvery(interval: number): boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Captures the current tick interval as the deterministic initial baseline state.
|
|
109
|
-
*
|
|
110
|
-
* This is useful for restoring the intended baseline game speed on session
|
|
111
|
-
* resets rather than reverting to the engine's hardcoded default.
|
|
112
|
-
*
|
|
113
|
-
* @returns {void} Returns nothing.
|
|
114
|
-
*/
|
|
115
|
-
captureInitialState(): void;
|
|
116
115
|
}
|
|
@@ -116,3 +116,14 @@ export declare enum StateProperty {
|
|
|
116
116
|
MUTED = "muted",
|
|
117
117
|
TRACKPAD = "trackpadEnabled"
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Enumerates all observable score and progression properties.
|
|
121
|
+
* These keys are used for score subscriptions.
|
|
122
|
+
*/
|
|
123
|
+
export declare enum ScoreProperty {
|
|
124
|
+
SCORE = "score",
|
|
125
|
+
LEVEL = "level",
|
|
126
|
+
MULTIPLIER = "multiplier",
|
|
127
|
+
MAX_LEVEL = "maxLevel",
|
|
128
|
+
HIGH_SCORE = "highScore"
|
|
129
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import p5 from 'p5';
|
|
2
|
-
import { Color, ControlKey, FontAlign, FontSize, FontVerticalAlign, Sound, TextTheme } from './enums';
|
|
2
|
+
import { Color, ControlKey, FontAlign, FontSize, FontVerticalAlign, ScoreProperty, Sound, TextTheme } from './enums';
|
|
3
3
|
import { Debuggable, Initializable, RendererInitializable, StateSyncable, Serializable } from './Interfaces';
|
|
4
4
|
import { Cell, ControlCallback, ControlEventType, Coordinate, RendererMetrics, GameModules, StateProperty, Vector, Piece, Axis } from './Types';
|
|
5
5
|
/**
|
|
@@ -583,58 +583,66 @@ export interface State extends Initializable {
|
|
|
583
583
|
*/
|
|
584
584
|
unsubscribe(property: StateProperty, callback: (value: boolean | number) => void): void;
|
|
585
585
|
/**
|
|
586
|
-
*
|
|
586
|
+
* Subscribes to changes in a specific state property only when in the Title Screen.
|
|
587
|
+
*
|
|
587
588
|
* @param {StateProperty} property - The state property to monitor.
|
|
588
|
-
* @param {function(boolean | number): void} callback - The function to execute
|
|
589
|
+
* @param {function(boolean | number): void} callback - The function to execute.
|
|
589
590
|
* @returns {void} Returns nothing.
|
|
590
591
|
*/
|
|
591
592
|
subscribeForTitleScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
|
|
592
593
|
/**
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
* @param {
|
|
594
|
+
* Unsubscribes a callback from Title Screen scoped notifications.
|
|
595
|
+
*
|
|
596
|
+
* @param {StateProperty} property - The state property being monitored.
|
|
597
|
+
* @param {function(boolean | number): void} callback - The callback to remove.
|
|
596
598
|
* @returns {void} Returns nothing.
|
|
597
599
|
*/
|
|
598
600
|
unsubscribeForTitleScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
|
|
599
601
|
/**
|
|
600
|
-
*
|
|
602
|
+
* Subscribes to changes in a specific state property only when in the Game Over screen.
|
|
603
|
+
*
|
|
601
604
|
* @param {StateProperty} property - The state property to monitor.
|
|
602
|
-
* @param {function(boolean | number): void} callback - The function to execute
|
|
605
|
+
* @param {function(boolean | number): void} callback - The function to execute.
|
|
603
606
|
* @returns {void} Returns nothing.
|
|
604
607
|
*/
|
|
605
608
|
subscribeForGameOverScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
|
|
606
609
|
/**
|
|
607
|
-
*
|
|
608
|
-
*
|
|
609
|
-
* @param {
|
|
610
|
+
* Unsubscribes a callback from Game Over scoped notifications.
|
|
611
|
+
*
|
|
612
|
+
* @param {StateProperty} property - The state property being monitored.
|
|
613
|
+
* @param {function(boolean | number): void} callback - The callback to remove.
|
|
610
614
|
* @returns {void} Returns nothing.
|
|
611
615
|
*/
|
|
612
616
|
unsubscribeForGameOverScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
|
|
613
617
|
/**
|
|
614
|
-
*
|
|
618
|
+
* Subscribes to changes in a specific state property only during active Gameplay.
|
|
619
|
+
*
|
|
615
620
|
* @param {StateProperty} property - The state property to monitor.
|
|
616
|
-
* @param {function(boolean | number): void} callback - The function to execute
|
|
621
|
+
* @param {function(boolean | number): void} callback - The function to execute.
|
|
617
622
|
* @returns {void} Returns nothing.
|
|
618
623
|
*/
|
|
619
624
|
subscribeForPlayingScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
|
|
620
625
|
/**
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
* @param {
|
|
626
|
+
* Unsubscribes a callback from Playing scoped notifications.
|
|
627
|
+
*
|
|
628
|
+
* @param {StateProperty} property - The state property being monitored.
|
|
629
|
+
* @param {function(boolean | number): void} callback - The callback to remove.
|
|
624
630
|
* @returns {void} Returns nothing.
|
|
625
631
|
*/
|
|
626
632
|
unsubscribeForPlayingScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
|
|
627
633
|
/**
|
|
628
|
-
*
|
|
634
|
+
* Subscribes to changes in a specific state property only when the game is Paused.
|
|
635
|
+
*
|
|
629
636
|
* @param {StateProperty} property - The state property to monitor.
|
|
630
|
-
* @param {function(boolean | number): void} callback - The function to execute
|
|
637
|
+
* @param {function(boolean | number): void} callback - The function to execute.
|
|
631
638
|
* @returns {void} Returns nothing.
|
|
632
639
|
*/
|
|
633
640
|
subscribeForPausedScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
|
|
634
641
|
/**
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
* @param {
|
|
642
|
+
* Unsubscribes a callback from Paused scoped notifications.
|
|
643
|
+
*
|
|
644
|
+
* @param {StateProperty} property - The state property being monitored.
|
|
645
|
+
* @param {function(boolean | number): void} callback - The callback to remove.
|
|
638
646
|
* @returns {void} Returns nothing.
|
|
639
647
|
*/
|
|
640
648
|
unsubscribeForPausedScreen(property: StateProperty, callback: (value: boolean | number) => void): void;
|
|
@@ -814,73 +822,61 @@ export interface Control extends Initializable {
|
|
|
814
822
|
* Manages the game loop timing, ticks, and delta time.
|
|
815
823
|
*/
|
|
816
824
|
export interface Time extends Initializable {
|
|
817
|
-
/** The interval between logic ticks in milliseconds. */
|
|
818
|
-
tickInterval: number;
|
|
819
825
|
/** The total number of ticks since the game started. */
|
|
820
826
|
readonly totalTicks: number;
|
|
821
827
|
/** Total elapsed time in milliseconds since the game started. */
|
|
822
828
|
readonly elapsedTime: number;
|
|
823
829
|
/**
|
|
824
|
-
* Checks if enough time has passed
|
|
830
|
+
* Checks if enough time has passed based on a specific millisecond interval.
|
|
825
831
|
*
|
|
826
|
-
* @param {number}
|
|
827
|
-
* @returns {boolean} `true` if the
|
|
832
|
+
* @param {number} ms - The millisecond interval to check.
|
|
833
|
+
* @returns {boolean} `true` if the logical clock just crossed a multiple of the interval.
|
|
828
834
|
*/
|
|
829
|
-
|
|
835
|
+
atInterval(ms: number): boolean;
|
|
830
836
|
/**
|
|
831
|
-
*
|
|
837
|
+
* Executes a callback function every N milliseconds of logical game time.
|
|
832
838
|
*
|
|
833
|
-
*
|
|
834
|
-
*
|
|
835
|
-
*/
|
|
836
|
-
update(deltaTime: number): void;
|
|
837
|
-
/**
|
|
838
|
-
* Determines if a logic tick should occur based on the accumulator.
|
|
839
|
+
* Provides a declarative functional approach to handling recurring game logic,
|
|
840
|
+
* such as spawning enemies or updating timers.
|
|
839
841
|
*
|
|
840
|
-
* @
|
|
842
|
+
* @param {number} ms - The millisecond interval between executions.
|
|
843
|
+
* @param {() => void} action - The callback function to execute if the interval is crossed.
|
|
844
|
+
* @returns {void}
|
|
841
845
|
*/
|
|
842
|
-
|
|
846
|
+
every(ms: number, action: () => void): void;
|
|
843
847
|
/**
|
|
844
|
-
*
|
|
848
|
+
* Updates the system clock, total elapsed time, and performance metrics (FPS/TPS).
|
|
845
849
|
*
|
|
846
|
-
*
|
|
847
|
-
|
|
848
|
-
reset(): void;
|
|
849
|
-
/**
|
|
850
|
-
* Increases the tick interval (slowing down the game logic).
|
|
850
|
+
* Should be invoked strictly once per hardware visual frame, even when the
|
|
851
|
+
* game is paused, to maintain accurate UI animations and performance tracking.
|
|
851
852
|
*
|
|
852
|
-
* @param {number}
|
|
853
|
+
* @param {number} deltaTime - Time elapsed since last frame in milliseconds.
|
|
853
854
|
* @returns {void} Returns nothing.
|
|
854
855
|
*/
|
|
855
|
-
|
|
856
|
+
update(deltaTime: number): void;
|
|
856
857
|
/**
|
|
857
|
-
*
|
|
858
|
+
* Accumulates time specifically for the logical engine ticks.
|
|
858
859
|
*
|
|
859
|
-
*
|
|
860
|
-
*
|
|
861
|
-
|
|
862
|
-
decrementTickInterval(amount: number): void;
|
|
863
|
-
/**
|
|
864
|
-
* Sets the tick interval.
|
|
860
|
+
* This should only be invoked when the game logic is active (not paused
|
|
861
|
+
* or on title screens) to prevent the logic from "catching up" after
|
|
862
|
+
* periods of inactivity.
|
|
865
863
|
*
|
|
866
|
-
* @param {number}
|
|
864
|
+
* @param {number} deltaTime - Time to add to the logic accumulator.
|
|
867
865
|
* @returns {void} Returns nothing.
|
|
868
866
|
*/
|
|
869
|
-
|
|
867
|
+
accumulate(deltaTime: number): void;
|
|
870
868
|
/**
|
|
871
|
-
*
|
|
869
|
+
* Determines if a logic tick should occur based on the accumulator.
|
|
872
870
|
*
|
|
873
|
-
* @
|
|
874
|
-
* @returns {void} Returns nothing.
|
|
871
|
+
* @returns {boolean} `true` if a tick is due.
|
|
875
872
|
*/
|
|
876
|
-
|
|
873
|
+
shouldTick(): boolean;
|
|
877
874
|
/**
|
|
878
|
-
*
|
|
879
|
-
* Use this after games have set their starting speed.
|
|
875
|
+
* Resets internal time accumulators and counters.
|
|
880
876
|
*
|
|
881
877
|
* @returns {void} Returns nothing.
|
|
882
878
|
*/
|
|
883
|
-
|
|
879
|
+
reset(): void;
|
|
884
880
|
}
|
|
885
881
|
/**
|
|
886
882
|
* Interface for the audio module.
|
|
@@ -993,6 +989,20 @@ export interface Score {
|
|
|
993
989
|
* @returns {void} Returns nothing.
|
|
994
990
|
*/
|
|
995
991
|
setupGameHighScore(id: string): void;
|
|
992
|
+
/**
|
|
993
|
+
* Subscribes a callback for a specific score property.
|
|
994
|
+
* @param {ScoreProperty} property - The property to subscribe to.
|
|
995
|
+
* @param {function} callback - The callback function.
|
|
996
|
+
* @returns {void} Returns nothing.
|
|
997
|
+
*/
|
|
998
|
+
subscribe(property: ScoreProperty, callback: (score: number) => void): void;
|
|
999
|
+
/**
|
|
1000
|
+
* Unsubscribes a callback from a specific score property.
|
|
1001
|
+
* @param {ScoreProperty} property - The property to unsubscribe from.
|
|
1002
|
+
* @param {function} callback - The callback function.
|
|
1003
|
+
* @returns {void} Returns nothing.
|
|
1004
|
+
*/
|
|
1005
|
+
unsubscribe(property: ScoreProperty, callback: (score: number) => void): void;
|
|
996
1006
|
}
|
|
997
1007
|
export interface Session extends StateSyncable, Debuggable {
|
|
998
1008
|
gameId: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|