Skip to content

Commit 372ead4

Browse files
committed
[#1091] refactor Timer into an instantiable class
time (namespace) is now a default instance of the Timer class
1 parent 52e6759 commit 372ead4

File tree

4 files changed

+253
-216
lines changed

4 files changed

+253
-216
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [10.11.0] (melonJS 2) - _2022-XX-XX_
44

55
### Changed
6+
- Core: refactored Timer into an instantiable class with `time` (namespace) now being a default instance of the Timer class
67
- Doc: replaced JSDoc by Webdoc for documentation generation (huge thanks to @ShukantPal)
78

89
### Fixed

src/state/state.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { pauseTrack, resumeTrack } from "./../audio/audio.js";
22
import * as fctUtil from "./../utils/function.js";
33
import * as event from "./../system/event.js";
4-
import timer from "./../system/timer.js";
54
import * as game from "./../game.js";
65
import Stage from "./../state/stage.js";
76
import DefaultLoadingScreen from "./../loader/loadingscreen.js";
@@ -41,9 +40,6 @@ var _pauseTime = 0;
4140
function _startRunLoop() {
4241
// ensure nothing is running first and in valid state
4342
if ((_animFrameId === -1) && (_state !== -1)) {
44-
// reset the timer
45-
timer.reset();
46-
4743
// start the main loop
4844
_animFrameId = globalThis.requestAnimationFrame(_renderFrame);
4945
}
@@ -56,9 +52,6 @@ function _startRunLoop() {
5652
function _resumeRunLoop() {
5753
// ensure game is actually paused and in valid state
5854
if (_isPaused && (_state !== -1)) {
59-
// reset the timer
60-
timer.reset();
61-
6255
_isPaused = false;
6356
}
6457
}
@@ -124,6 +117,9 @@ function _switchState(state) {
124117
// new requested state
125118
_startRunLoop();
126119

120+
// publish the pause event
121+
event.emit(event.STATE_CHANGE);
122+
127123
// execute callback if defined
128124
if (_onSwitchComplete) {
129125
_onSwitchComplete();

src/system/event.js

+11
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ export const STATE_STOP = "me.state.onStop";
6767
*/
6868
export const STATE_RESTART = "me.state.onRestart";
6969

70+
/**
71+
* event for when the changing to a different stage
72+
* @public
73+
* @constant
74+
* @type {string}
75+
* @name STATE_CHANGE
76+
* @memberof event
77+
* @see event.on
78+
*/
79+
export const STATE_CHANGE = "me.state.onChange";
80+
7081
/**
7182
* event for when the video is initialized<br>
7283
* Data passed : none <br>

0 commit comments

Comments
 (0)