melonjs 10.6.1 → 10.7.0
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/melonjs.js +37469 -36530
- package/dist/melonjs.min.js +21 -21
- package/dist/melonjs.module.d.ts +369 -164
- package/dist/melonjs.module.js +1746 -788
- package/package.json +10 -8
- package/src/game.js +5 -5
- package/src/geometries/rectangle.js +15 -0
- package/src/index.js +4 -4
- package/src/input/gamepad.js +12 -10
- package/src/input/keyboard.js +5 -3
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +2 -3
- package/src/level/tiled/TMXUtils.js +1 -1
- package/src/loader/loader.js +1 -1
- package/src/math/matrix3.js +66 -65
- package/src/particles/emitter.js +119 -428
- package/src/particles/particle.js +51 -52
- package/src/particles/settings.js +310 -0
- package/src/polyfill/console.js +7 -7
- package/src/polyfill/index.js +7 -0
- package/src/polyfill/performance.js +20 -0
- package/src/polyfill/requestAnimationFrame.js +10 -10
- package/src/renderable/imagelayer.js +2 -2
- package/src/state/state.js +7 -7
- package/src/system/device.js +141 -128
- package/src/system/event.js +10 -10
- package/src/system/timer.js +1 -1
- package/src/utils/agent.js +4 -4
- package/src/utils/function.js +2 -2
- package/src/utils/utils.js +10 -5
- package/src/video/canvas/canvas_renderer.js +16 -2
- package/src/video/renderer.js +2 -2
- package/src/video/video.js +11 -11
- package/src/video/webgl/glshader.js +1 -1
- package/src/video/webgl/webgl_renderer.js +6 -5
- package/src/particles/particlecontainer.js +0 -95
package/src/system/device.js
CHANGED
|
@@ -22,8 +22,8 @@ let swipeEnabled = true;
|
|
|
22
22
|
*/
|
|
23
23
|
function _disableSwipeFn(e) {
|
|
24
24
|
e.preventDefault();
|
|
25
|
-
if (typeof
|
|
26
|
-
|
|
25
|
+
if (typeof globalThis.scroll === "function") {
|
|
26
|
+
globalThis.scroll(0, 0);
|
|
27
27
|
}
|
|
28
28
|
return false;
|
|
29
29
|
};
|
|
@@ -39,24 +39,27 @@ function _domReady() {
|
|
|
39
39
|
// Make sure that the DOM is not already loaded
|
|
40
40
|
if (!isReady) {
|
|
41
41
|
// be sure document.body is there
|
|
42
|
-
if (!document.body) {
|
|
42
|
+
if (!device.nodeJS && !document.body) {
|
|
43
43
|
return setTimeout(_domReady, 13);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// clean up loading event
|
|
47
|
-
if (document.removeEventListener) {
|
|
48
|
-
document.removeEventListener(
|
|
47
|
+
if (typeof globalThis.document !== "undefined" && typeof globalThis.document.removeEventListener === "function") {
|
|
48
|
+
globalThis.document.removeEventListener(
|
|
49
49
|
"DOMContentLoaded",
|
|
50
50
|
this._domReady,
|
|
51
51
|
false
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
|
|
55
|
+
if (typeof globalThis.removeEventListener === "function") {
|
|
56
|
+
// remove the event on globalThis.onload (always added in `onReady`)
|
|
57
|
+
globalThis.removeEventListener("load", _domReady, false);
|
|
58
|
+
}
|
|
56
59
|
|
|
57
60
|
// execute all callbacks
|
|
58
61
|
while (readyList.length) {
|
|
59
|
-
readyList.shift().call(
|
|
62
|
+
readyList.shift().call(globalThis, []);
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
// Remember that the DOM is ready
|
|
@@ -95,7 +98,7 @@ function _detectDevice() {
|
|
|
95
98
|
device.BlackBerry ||
|
|
96
99
|
device.Kindle || false;
|
|
97
100
|
// ejecta
|
|
98
|
-
device.ejecta = (typeof
|
|
101
|
+
device.ejecta = (typeof globalThis.ejecta !== "undefined");
|
|
99
102
|
// Wechat
|
|
100
103
|
device.isWeixin = /MicroMessenger/i.test(device.ua);
|
|
101
104
|
};
|
|
@@ -116,46 +119,44 @@ function _checkCapabilities() {
|
|
|
116
119
|
}
|
|
117
120
|
|
|
118
121
|
// Touch/Gesture Event feature detection
|
|
119
|
-
device.TouchEvent = !!("ontouchstart" in
|
|
120
|
-
device.PointerEvent = !!
|
|
121
|
-
|
|
122
|
+
device.TouchEvent = !!("ontouchstart" in globalThis);
|
|
123
|
+
device.PointerEvent = !!globalThis.PointerEvent;
|
|
124
|
+
globalThis.gesture = prefixed("gesture");
|
|
122
125
|
|
|
123
126
|
// detect touch capabilities
|
|
124
127
|
device.touch = device.TouchEvent || device.PointerEvent;
|
|
125
128
|
|
|
126
129
|
// max amount of touch points ; always at least return 1 (e.g. headless chrome will return 0)
|
|
127
|
-
device.maxTouchPoints = device.touch ? (device.PointerEvent ? navigator.maxTouchPoints || 1 : 10) : 1;
|
|
130
|
+
device.maxTouchPoints = device.touch ? (device.PointerEvent ? globalThis.navigator.maxTouchPoints || 1 : 10) : 1;
|
|
128
131
|
|
|
129
132
|
// detect wheel event support
|
|
130
133
|
// Modern browsers support "wheel", Webkit and IE support at least "mousewheel
|
|
131
|
-
device.wheel =
|
|
134
|
+
device.wheel = typeof globalThis.document !== "undefined" && "onwheel" in globalThis.document.createElement("div");
|
|
132
135
|
|
|
133
136
|
// pointerlock detection (pointerLockElement can be null when the feature is supported)
|
|
134
|
-
device.hasPointerLockSupport = typeof document.pointerLockElement !== "undefined";
|
|
137
|
+
device.hasPointerLockSupport = typeof globalThis.document !== "undefined" && typeof globalThis.document.pointerLockElement !== "undefined";
|
|
135
138
|
|
|
136
139
|
// device orientation and motion detection
|
|
137
|
-
device.hasDeviceOrientation = !!
|
|
138
|
-
device.hasAccelerometer = !!
|
|
140
|
+
device.hasDeviceOrientation = !!globalThis.DeviceOrientationEvent;
|
|
141
|
+
device.hasAccelerometer = !!globalThis.DeviceMotionEvent;
|
|
139
142
|
|
|
140
143
|
// support the ScreenOrientation API
|
|
141
144
|
device.ScreenOrientation = (typeof screen !== "undefined") &&
|
|
142
145
|
(typeof screen.orientation !== "undefined");
|
|
143
146
|
|
|
144
147
|
// fullscreen api detection & polyfill when possible
|
|
145
|
-
device.hasFullscreenSupport = prefixed("fullscreenEnabled", document) ||
|
|
146
|
-
document.mozFullScreenEnabled;
|
|
148
|
+
device.hasFullscreenSupport = typeof globalThis.document !== "undefined" && (prefixed("fullscreenEnabled", globalThis.document) || globalThis.document.mozFullScreenEnabled);
|
|
147
149
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
if (device.hasFullscreenSupport === true) {
|
|
151
|
+
globalThis.document.exitFullscreen = typeof globalThis.document !== "undefined" && (prefixed("cancelFullScreen", globalThis.document) || prefixed("exitFullscreen", globalThis.document));
|
|
152
|
+
}
|
|
150
153
|
|
|
151
|
-
// vibration API poyfill
|
|
152
|
-
navigator.vibrate = prefixed("vibrate", navigator);
|
|
153
154
|
|
|
154
155
|
// web Audio detection
|
|
155
|
-
device.hasWebAudio = !!(
|
|
156
|
+
device.hasWebAudio = !!(globalThis.AudioContext || globalThis.webkitAudioContext);
|
|
156
157
|
|
|
157
158
|
try {
|
|
158
|
-
device.localStorage = !!
|
|
159
|
+
device.localStorage = !!globalThis.localStorage;
|
|
159
160
|
} catch (e) {
|
|
160
161
|
// the above generates an exception when cookies are blocked
|
|
161
162
|
device.localStorage = false;
|
|
@@ -165,75 +166,78 @@ function _checkCapabilities() {
|
|
|
165
166
|
// some browser (e.g. Safari) implements WebGL1 and WebGL2 contexts only
|
|
166
167
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=801176
|
|
167
168
|
device.OffscreenCanvas =
|
|
168
|
-
(typeof
|
|
169
|
+
(typeof globalThis.OffscreenCanvas !== "undefined") &&
|
|
169
170
|
((new OffscreenCanvas(0, 0).getContext( "2d" )) !== null);
|
|
170
171
|
} catch (e) {
|
|
171
172
|
device.OffscreenCanvas = false;
|
|
172
173
|
}
|
|
173
174
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
device.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
// Set the name of the hidden property and the change event for visibility
|
|
199
|
-
var hidden, visibilityChange;
|
|
200
|
-
if (typeof document.hidden !== "undefined") {
|
|
201
|
-
// Opera 12.10 and Firefox 18 and later support
|
|
202
|
-
hidden = "hidden";
|
|
203
|
-
visibilityChange = "visibilitychange";
|
|
204
|
-
} else if (typeof document.mozHidden !== "undefined") {
|
|
205
|
-
hidden = "mozHidden";
|
|
206
|
-
visibilityChange = "mozvisibilitychange";
|
|
207
|
-
} else if (typeof document.msHidden !== "undefined") {
|
|
208
|
-
hidden = "msHidden";
|
|
209
|
-
visibilityChange = "msvisibilitychange";
|
|
210
|
-
} else if (typeof document.webkitHidden !== "undefined") {
|
|
211
|
-
hidden = "webkitHidden";
|
|
212
|
-
visibilityChange = "webkitvisibilitychange";
|
|
175
|
+
if (typeof globalThis.addEventListener === "function") {
|
|
176
|
+
// set pause/stop action on losing focus
|
|
177
|
+
globalThis.addEventListener("blur", function () {
|
|
178
|
+
if (device.stopOnBlur) {
|
|
179
|
+
state.stop(true);
|
|
180
|
+
}
|
|
181
|
+
if (device.pauseOnBlur) {
|
|
182
|
+
state.pause(true);
|
|
183
|
+
}
|
|
184
|
+
}, false);
|
|
185
|
+
// set restart/resume action on gaining focus
|
|
186
|
+
globalThis.addEventListener("focus", function () {
|
|
187
|
+
if (device.stopOnBlur) {
|
|
188
|
+
state.restart(true);
|
|
189
|
+
}
|
|
190
|
+
if (device.resumeOnFocus) {
|
|
191
|
+
state.resume(true);
|
|
192
|
+
}
|
|
193
|
+
// force focus if autofocus is on
|
|
194
|
+
if (device.autoFocus) {
|
|
195
|
+
device.focus();
|
|
196
|
+
}
|
|
197
|
+
}, false);
|
|
213
198
|
}
|
|
214
199
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
document.
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
200
|
+
if (typeof globalThis.document !== "undefined") {
|
|
201
|
+
// Set the name of the hidden property and the change event for visibility
|
|
202
|
+
var hidden, visibilityChange;
|
|
203
|
+
if (typeof globalThis.document.hidden !== "undefined") {
|
|
204
|
+
// Opera 12.10 and Firefox 18 and later support
|
|
205
|
+
hidden = "hidden";
|
|
206
|
+
visibilityChange = "visibilitychange";
|
|
207
|
+
} else if (typeof globalThis.document.mozHidden !== "undefined") {
|
|
208
|
+
hidden = "mozHidden";
|
|
209
|
+
visibilityChange = "mozvisibilitychange";
|
|
210
|
+
} else if (typeof globalThis.document.msHidden !== "undefined") {
|
|
211
|
+
hidden = "msHidden";
|
|
212
|
+
visibilityChange = "msvisibilitychange";
|
|
213
|
+
} else if (typeof globalThis.document.webkitHidden !== "undefined") {
|
|
214
|
+
hidden = "webkitHidden";
|
|
215
|
+
visibilityChange = "webkitvisibilitychange";
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// register on the event if supported
|
|
219
|
+
if (typeof (visibilityChange) === "string") {
|
|
220
|
+
// add the corresponding event listener
|
|
221
|
+
globalThis.document.addEventListener(visibilityChange,
|
|
222
|
+
function () {
|
|
223
|
+
if (globalThis.document[hidden]) {
|
|
224
|
+
if (device.stopOnBlur) {
|
|
225
|
+
state.stop(true);
|
|
226
|
+
}
|
|
227
|
+
if (device.pauseOnBlur) {
|
|
228
|
+
state.pause(true);
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
if (device.stopOnBlur) {
|
|
232
|
+
state.restart(true);
|
|
233
|
+
}
|
|
234
|
+
if (device.resumeOnFocus) {
|
|
235
|
+
state.resume(true);
|
|
236
|
+
}
|
|
233
237
|
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
238
|
+
}, false
|
|
239
|
+
);
|
|
240
|
+
}
|
|
237
241
|
}
|
|
238
242
|
};
|
|
239
243
|
|
|
@@ -254,7 +258,7 @@ let device = {
|
|
|
254
258
|
* @name ua
|
|
255
259
|
* @memberof device
|
|
256
260
|
*/
|
|
257
|
-
ua : navigator.userAgent,
|
|
261
|
+
ua : typeof globalThis.navigator !== "undefined" ? globalThis.navigator.userAgent : "",
|
|
258
262
|
|
|
259
263
|
/**
|
|
260
264
|
* Browser Local Storage capabilities <br>
|
|
@@ -328,7 +332,7 @@ let device = {
|
|
|
328
332
|
* @name nativeBase64
|
|
329
333
|
* @memberof device
|
|
330
334
|
*/
|
|
331
|
-
nativeBase64 : (typeof(
|
|
335
|
+
nativeBase64 : (typeof(globalThis.atob) === "function"),
|
|
332
336
|
|
|
333
337
|
/**
|
|
334
338
|
* Return the maximum number of simultaneous touch contact points are supported by the current device.
|
|
@@ -407,24 +411,33 @@ let device = {
|
|
|
407
411
|
*/
|
|
408
412
|
linux : false,
|
|
409
413
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
414
|
+
/**
|
|
415
|
+
* equals to true if the game is running under Ejecta.
|
|
416
|
+
* @type {boolean}
|
|
417
|
+
* @readonly
|
|
418
|
+
* @see http://impactjs.com/ejecta
|
|
419
|
+
* @name ejecta
|
|
420
|
+
* @memberof device
|
|
421
|
+
*/
|
|
418
422
|
ejecta : false,
|
|
419
423
|
|
|
420
424
|
/**
|
|
421
|
-
* equals to true if the
|
|
425
|
+
* equals to true if the is running under Wechat.
|
|
422
426
|
* @type {boolean}
|
|
423
427
|
* @readonly
|
|
424
428
|
* @name isWeixin
|
|
425
429
|
* @memberof device
|
|
426
430
|
*/
|
|
427
|
-
|
|
431
|
+
isWeixin : false,
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* equals to true if running under node.js
|
|
435
|
+
* @type {boolean}
|
|
436
|
+
* @readonly
|
|
437
|
+
* @name nodeJS
|
|
438
|
+
* @memberof device
|
|
439
|
+
*/
|
|
440
|
+
nodeJS : (typeof process !== "undefined") && (process.release.name === "node"),
|
|
428
441
|
|
|
429
442
|
/**
|
|
430
443
|
* equals to true if the device is running on ChromeOS.
|
|
@@ -539,7 +552,7 @@ let device = {
|
|
|
539
552
|
* @name language
|
|
540
553
|
* @memberof device
|
|
541
554
|
*/
|
|
542
|
-
language : navigator.language || navigator.browserLanguage || navigator.userLanguage || "en",
|
|
555
|
+
language : typeof globalThis.navigator !== "undefined" ? globalThis.navigator.language || globalThis.navigator.browserLanguage || globalThis.navigator.userLanguage || "en" : "en",
|
|
543
556
|
|
|
544
557
|
/**
|
|
545
558
|
* Specify whether to pause the game when losing focus
|
|
@@ -631,7 +644,7 @@ let device = {
|
|
|
631
644
|
// If the DOM is already ready
|
|
632
645
|
if (isReady) {
|
|
633
646
|
// Execute the function immediately
|
|
634
|
-
fn.call(
|
|
647
|
+
fn.call(globalThis, []);
|
|
635
648
|
}
|
|
636
649
|
else {
|
|
637
650
|
// Add the function to the wait list
|
|
@@ -640,17 +653,17 @@ let device = {
|
|
|
640
653
|
// attach listeners if not yet done
|
|
641
654
|
if (!readyBound) {
|
|
642
655
|
// directly call domReady if document is already "ready"
|
|
643
|
-
if (document.readyState === "complete") {
|
|
656
|
+
if (device.nodeJS === true || (typeof globalThis.document !== "undefined" && globalThis.document.readyState === "complete")) {
|
|
644
657
|
// defer the fn call to ensure our script is fully loaded
|
|
645
|
-
|
|
658
|
+
globalThis.setTimeout(_domReady, 0);
|
|
646
659
|
}
|
|
647
660
|
else {
|
|
648
|
-
if (document.addEventListener) {
|
|
661
|
+
if (typeof globalThis.document !== "undefined" && typeof globalThis.document.addEventListener === "function") {
|
|
649
662
|
// Use the handy event callback
|
|
650
|
-
document.addEventListener("DOMContentLoaded", _domReady, false);
|
|
663
|
+
globalThis.document.addEventListener("DOMContentLoaded", _domReady, false);
|
|
651
664
|
}
|
|
652
|
-
// A fallback to
|
|
653
|
-
|
|
665
|
+
// A fallback to globalThis.onload, that will always work
|
|
666
|
+
globalThis.addEventListener("load", _domReady, false);
|
|
654
667
|
}
|
|
655
668
|
readyBound = true;
|
|
656
669
|
}
|
|
@@ -665,11 +678,11 @@ let device = {
|
|
|
665
678
|
enableSwipe(enable) {
|
|
666
679
|
if (enable !== false) {
|
|
667
680
|
if (swipeEnabled === false) {
|
|
668
|
-
|
|
681
|
+
globalThis.document.removeEventListener("touchmove", _disableSwipeFn, false);
|
|
669
682
|
swipeEnabled = true;
|
|
670
683
|
}
|
|
671
684
|
} else if (swipeEnabled === true) {
|
|
672
|
-
|
|
685
|
+
globalThis.document.addEventListener("touchmove", _disableSwipeFn, false);
|
|
673
686
|
swipeEnabled = false;
|
|
674
687
|
}
|
|
675
688
|
},
|
|
@@ -723,7 +736,7 @@ let device = {
|
|
|
723
736
|
var PORTRAIT = "portrait";
|
|
724
737
|
var LANDSCAPE = "landscape";
|
|
725
738
|
|
|
726
|
-
var screen =
|
|
739
|
+
var screen = globalThis.screen;
|
|
727
740
|
|
|
728
741
|
// first try using "standard" values
|
|
729
742
|
if (this.ScreenOrientation === true) {
|
|
@@ -738,12 +751,12 @@ let device = {
|
|
|
738
751
|
}
|
|
739
752
|
|
|
740
753
|
// check using the deprecated API
|
|
741
|
-
if (typeof
|
|
742
|
-
return (Math.abs(
|
|
754
|
+
if (typeof globalThis.orientation === "number") {
|
|
755
|
+
return (Math.abs(globalThis.orientation) === 90) ? LANDSCAPE : PORTRAIT;
|
|
743
756
|
}
|
|
744
757
|
|
|
745
758
|
// fallback to window size check
|
|
746
|
-
return (
|
|
759
|
+
return (globalThis.outerWidth > globalThis.outerHeight) ? LANDSCAPE : PORTRAIT;
|
|
747
760
|
},
|
|
748
761
|
|
|
749
762
|
/**
|
|
@@ -755,7 +768,7 @@ let device = {
|
|
|
755
768
|
* @returns {boolean} true if the orientation was unsuccessfully locked
|
|
756
769
|
*/
|
|
757
770
|
lockOrientation(orientation) {
|
|
758
|
-
var screen =
|
|
771
|
+
var screen = globalThis.screen;
|
|
759
772
|
if (typeof screen !== "undefined") {
|
|
760
773
|
var _lockOrientation = prefixed("lockOrientation", screen);
|
|
761
774
|
if (typeof _lockOrientation !== "undefined") {
|
|
@@ -773,7 +786,7 @@ let device = {
|
|
|
773
786
|
* @returns {boolean} true if the orientation was unsuccessfully unlocked
|
|
774
787
|
*/
|
|
775
788
|
unlockOrientation() {
|
|
776
|
-
var screen =
|
|
789
|
+
var screen = globalThis.screen;
|
|
777
790
|
if (typeof screen !== "undefined") {
|
|
778
791
|
var _unlockOrientation = prefixed("unlockOrientation", screen);
|
|
779
792
|
if (typeof _unlockOrientation !== "undefined") {
|
|
@@ -872,8 +885,8 @@ let device = {
|
|
|
872
885
|
if (typeof element === "object" && element !== document.body && typeof element.getBoundingClientRect !== "undefined") {
|
|
873
886
|
return element.getBoundingClientRect();
|
|
874
887
|
} else {
|
|
875
|
-
_domRect.width = _domRect.right =
|
|
876
|
-
_domRect.height = _domRect.bottom =
|
|
888
|
+
_domRect.width = _domRect.right = globalThis.innerWidth;
|
|
889
|
+
_domRect.height = _domRect.bottom = globalThis.innerHeight;
|
|
877
890
|
return _domRect;
|
|
878
891
|
};
|
|
879
892
|
},
|
|
@@ -905,7 +918,7 @@ let device = {
|
|
|
905
918
|
stencil: true,
|
|
906
919
|
failIfMajorPerformanceCaveat : options.failIfMajorPerformanceCaveat
|
|
907
920
|
};
|
|
908
|
-
_supported = !! (
|
|
921
|
+
_supported = !! (globalThis.WebGLRenderingContext && (canvas.getContext("webgl", ctxOptions) || canvas.getContext("experimental-webgl", ctxOptions)));
|
|
909
922
|
} catch (e) {
|
|
910
923
|
_supported = false;
|
|
911
924
|
}
|
|
@@ -940,8 +953,8 @@ let device = {
|
|
|
940
953
|
* }
|
|
941
954
|
*/
|
|
942
955
|
focus() {
|
|
943
|
-
if (typeof (
|
|
944
|
-
|
|
956
|
+
if (typeof (globalThis.focus) === "function") {
|
|
957
|
+
globalThis.focus();
|
|
945
958
|
}
|
|
946
959
|
},
|
|
947
960
|
|
|
@@ -995,13 +1008,13 @@ let device = {
|
|
|
995
1008
|
.then(response => {
|
|
996
1009
|
if (response === "granted") {
|
|
997
1010
|
// add a listener for the devicemotion event
|
|
998
|
-
|
|
1011
|
+
globalThis.addEventListener("devicemotion", this.onDeviceMotion, false);
|
|
999
1012
|
accelInitialized = true;
|
|
1000
1013
|
}
|
|
1001
1014
|
}).catch(console.error);
|
|
1002
1015
|
} else {
|
|
1003
1016
|
// add a listener for the devicemotion event
|
|
1004
|
-
|
|
1017
|
+
globalThis.addEventListener("devicemotion", this.onDeviceMotion, false);
|
|
1005
1018
|
accelInitialized = true;
|
|
1006
1019
|
}
|
|
1007
1020
|
}
|
|
@@ -1015,7 +1028,7 @@ let device = {
|
|
|
1015
1028
|
unwatchAccelerometer() {
|
|
1016
1029
|
if (accelInitialized) {
|
|
1017
1030
|
// remove the listener for the devicemotion event
|
|
1018
|
-
|
|
1031
|
+
globalThis.removeEventListener("devicemotion", this.onDeviceMotion, false);
|
|
1019
1032
|
accelInitialized = false;
|
|
1020
1033
|
}
|
|
1021
1034
|
},
|
|
@@ -1045,12 +1058,12 @@ let device = {
|
|
|
1045
1058
|
DeviceOrientationEvent.requestPermission()
|
|
1046
1059
|
.then(response => {
|
|
1047
1060
|
if (response === "granted") {
|
|
1048
|
-
|
|
1061
|
+
globalThis.addEventListener("deviceorientation", this.onDeviceRotate, false);
|
|
1049
1062
|
deviceOrientationInitialized = true;
|
|
1050
1063
|
}
|
|
1051
1064
|
}).catch(console.error);
|
|
1052
1065
|
} else {
|
|
1053
|
-
|
|
1066
|
+
globalThis.addEventListener("deviceorientation", this.onDeviceRotate, false);
|
|
1054
1067
|
deviceOrientationInitialized = true;
|
|
1055
1068
|
}
|
|
1056
1069
|
}
|
|
@@ -1063,7 +1076,7 @@ let device = {
|
|
|
1063
1076
|
*/
|
|
1064
1077
|
unwatchDeviceOrientation() {
|
|
1065
1078
|
if (deviceOrientationInitialized) {
|
|
1066
|
-
|
|
1079
|
+
globalThis.removeEventListener("deviceorientation", this.onDeviceRotate, false);
|
|
1067
1080
|
deviceOrientationInitialized = false;
|
|
1068
1081
|
}
|
|
1069
1082
|
},
|
|
@@ -1086,8 +1099,8 @@ let device = {
|
|
|
1086
1099
|
* me.device.vibrate(0);
|
|
1087
1100
|
*/
|
|
1088
1101
|
vibrate(pattern) {
|
|
1089
|
-
if (navigator.vibrate) {
|
|
1090
|
-
navigator.vibrate(pattern);
|
|
1102
|
+
if (typeof globalThis.navigator !== "undefined" && typeof globalThis.navigator.vibrate === "function") {
|
|
1103
|
+
globalThis.navigator.vibrate(pattern);
|
|
1091
1104
|
}
|
|
1092
1105
|
}
|
|
1093
1106
|
|
|
@@ -1107,7 +1120,7 @@ Object.defineProperty(device, "devicePixelRatio", {
|
|
|
1107
1120
|
* @ignore
|
|
1108
1121
|
*/
|
|
1109
1122
|
get: function () {
|
|
1110
|
-
return (
|
|
1123
|
+
return (globalThis.devicePixelRatio || 1);
|
|
1111
1124
|
}
|
|
1112
1125
|
});
|
|
1113
1126
|
|
package/src/system/event.js
CHANGED
|
@@ -357,7 +357,7 @@ export const DRAGEND = "me.game.dragend";
|
|
|
357
357
|
* @memberof event
|
|
358
358
|
* @see event.on
|
|
359
359
|
*/
|
|
360
|
-
export const WINDOW_ONRESIZE = "
|
|
360
|
+
export const WINDOW_ONRESIZE = "globalThis.onresize";
|
|
361
361
|
|
|
362
362
|
/**
|
|
363
363
|
* Event for when the canvas is resized <br>
|
|
@@ -397,7 +397,7 @@ export const VIEWPORT_ONRESIZE = "viewport.onresize";
|
|
|
397
397
|
* @memberof event
|
|
398
398
|
* @see event.on
|
|
399
399
|
*/
|
|
400
|
-
export const WINDOW_ONORIENTATION_CHANGE = "
|
|
400
|
+
export const WINDOW_ONORIENTATION_CHANGE = "globalThis.orientationchange";
|
|
401
401
|
|
|
402
402
|
/**
|
|
403
403
|
* Event for when the (browser) window is scrolled <br>
|
|
@@ -409,7 +409,7 @@ export const WINDOW_ONORIENTATION_CHANGE = "window.orientationchange";
|
|
|
409
409
|
* @memberof event
|
|
410
410
|
* @see event.on
|
|
411
411
|
*/
|
|
412
|
-
export const WINDOW_ONSCROLL = "
|
|
412
|
+
export const WINDOW_ONSCROLL = "globalThis.onscroll";
|
|
413
413
|
|
|
414
414
|
/**
|
|
415
415
|
* Event for when the viewport position is updated <br>
|
|
@@ -424,8 +424,8 @@ export const WINDOW_ONSCROLL = "window.onscroll";
|
|
|
424
424
|
export const VIEWPORT_ONCHANGE = "viewport.onchange";
|
|
425
425
|
|
|
426
426
|
/**
|
|
427
|
-
* Event for when
|
|
428
|
-
* Data passed : {me.
|
|
427
|
+
* Event for when the current context is lost <br>
|
|
428
|
+
* Data passed : {me.Renderer} the current renderer instance
|
|
429
429
|
* @public
|
|
430
430
|
* @constant
|
|
431
431
|
* @type {string}
|
|
@@ -433,19 +433,19 @@ export const VIEWPORT_ONCHANGE = "viewport.onchange";
|
|
|
433
433
|
* @memberof event
|
|
434
434
|
* @see event.on
|
|
435
435
|
*/
|
|
436
|
-
export const
|
|
436
|
+
export const ONCONTEXT_LOST = "renderer.contextlost";
|
|
437
437
|
|
|
438
438
|
/**
|
|
439
|
-
* Event for when
|
|
440
|
-
* Data passed : {me.
|
|
439
|
+
* Event for when the current context is restored <br>
|
|
440
|
+
* Data passed : {me.Renderer} the current renderer instance`
|
|
441
441
|
* @public
|
|
442
442
|
* @constant
|
|
443
443
|
* @type {string}
|
|
444
|
-
* @name
|
|
444
|
+
* @name ONCONTEXT_RESTORED
|
|
445
445
|
* @memberof event
|
|
446
446
|
* @see event.on
|
|
447
447
|
*/
|
|
448
|
-
export const
|
|
448
|
+
export const ONCONTEXT_RESTORED = "renderer.contextrestored";
|
|
449
449
|
|
|
450
450
|
/**
|
|
451
451
|
* calls each of the listeners registered for a given event.
|
package/src/system/timer.js
CHANGED
package/src/utils/agent.js
CHANGED
|
@@ -17,12 +17,12 @@ var vendors = [ "ms", "MS", "moz", "webkit", "o" ];
|
|
|
17
17
|
* @name prefixed
|
|
18
18
|
* @function
|
|
19
19
|
* @param {string} name Property name
|
|
20
|
-
* @param {object} [obj=
|
|
20
|
+
* @param {object} [obj=globalThis] Object or element reference to access
|
|
21
21
|
* @returns {string} Value of property
|
|
22
22
|
* @memberof utils.agent
|
|
23
23
|
*/
|
|
24
24
|
export function prefixed(name, obj) {
|
|
25
|
-
obj = obj ||
|
|
25
|
+
obj = obj || globalThis;
|
|
26
26
|
if (name in obj) {
|
|
27
27
|
return obj[name];
|
|
28
28
|
}
|
|
@@ -44,12 +44,12 @@ export function prefixed(name, obj) {
|
|
|
44
44
|
* @function
|
|
45
45
|
* @param {string} name Property name
|
|
46
46
|
* @param {string} value Property value
|
|
47
|
-
* @param {object} [obj=
|
|
47
|
+
* @param {object} [obj=globalThis] Object or element reference to access
|
|
48
48
|
* @returns {boolean} true if one of the vendor-prefixed property was found
|
|
49
49
|
* @memberof utils.agent
|
|
50
50
|
*/
|
|
51
51
|
export function setPrefixed(name, value, obj) {
|
|
52
|
-
obj = obj ||
|
|
52
|
+
obj = obj || globalThis;
|
|
53
53
|
if (name in obj) {
|
|
54
54
|
obj[name] = value;
|
|
55
55
|
return;
|
package/src/utils/function.js
CHANGED
|
@@ -36,13 +36,13 @@ export function defer(func, thisArg, ...args) {
|
|
|
36
36
|
* @returns {Function} the function that will be throttled
|
|
37
37
|
*/
|
|
38
38
|
export function throttle(fn, delay, no_trailing) {
|
|
39
|
-
var last =
|
|
39
|
+
var last = globalThis.performance.now(), deferTimer;
|
|
40
40
|
// `no_trailing` defaults to false.
|
|
41
41
|
if (typeof no_trailing !== "boolean") {
|
|
42
42
|
no_trailing = false;
|
|
43
43
|
}
|
|
44
44
|
return function () {
|
|
45
|
-
var now =
|
|
45
|
+
var now = globalThis.performance.now();
|
|
46
46
|
var elasped = now - last;
|
|
47
47
|
var args = arguments;
|
|
48
48
|
if (elasped < delay) {
|
package/src/utils/utils.js
CHANGED
|
@@ -103,12 +103,17 @@ var utils = {
|
|
|
103
103
|
var hash = {};
|
|
104
104
|
|
|
105
105
|
if (typeof url === "undefined") {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
if (typeof globalThis.document !== "undefined") {
|
|
107
|
+
var location = globalThis.document.location;
|
|
108
|
+
|
|
109
|
+
if (location && location.hash) {
|
|
110
|
+
url = location.hash;
|
|
111
|
+
} else {
|
|
112
|
+
// No "document.location" exist for Wechat mini game platform.
|
|
113
|
+
return hash;
|
|
114
|
+
}
|
|
110
115
|
} else {
|
|
111
|
-
//
|
|
116
|
+
// "document" undefined on node.js
|
|
112
117
|
return hash;
|
|
113
118
|
}
|
|
114
119
|
} else {
|