melonjs 10.6.1 → 10.8.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 +37947 -36530
- package/dist/melonjs.min.js +22 -22
- package/dist/melonjs.module.d.ts +1352 -307
- package/dist/melonjs.module.js +2929 -1501
- package/package.json +14 -12
- package/src/camera/camera2d.js +1 -1
- package/src/entity/entity.js +6 -7
- package/src/game.js +5 -5
- package/src/geometries/ellipse.js +10 -11
- package/src/geometries/line.js +3 -3
- package/src/geometries/path2d.js +319 -0
- package/src/geometries/poly.js +11 -11
- package/src/geometries/rectangle.js +30 -15
- package/src/geometries/roundrect.js +67 -0
- package/src/index.js +9 -5
- 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 +3 -4
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXObject.js +9 -12
- package/src/level/tiled/TMXTileMap.js +23 -4
- package/src/level/tiled/TMXUtils.js +1 -1
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/loader.js +5 -5
- package/src/loader/loadingscreen.js +1 -1
- package/src/math/color.js +1 -1
- package/src/math/matrix2.js +1 -1
- package/src/math/matrix3.js +67 -66
- package/src/math/observable_vector2.js +1 -1
- package/src/math/observable_vector3.js +1 -1
- package/src/math/vector2.js +1 -1
- package/src/math/vector3.js +1 -1
- package/src/particles/emitter.js +130 -430
- package/src/particles/particle.js +53 -53
- package/src/particles/settings.js +310 -0
- package/src/physics/body.js +67 -51
- package/src/physics/bounds.js +8 -9
- package/src/physics/world.js +1 -1
- 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/collectable.js +9 -2
- package/src/renderable/colorlayer.js +1 -1
- package/src/renderable/container.js +1 -1
- package/src/renderable/imagelayer.js +3 -3
- package/src/renderable/renderable.js +1 -1
- package/src/renderable/sprite.js +2 -3
- package/src/renderable/trigger.js +10 -4
- package/src/state/stage.js +1 -1
- package/src/state/state.js +8 -8
- package/src/system/device.js +148 -133
- package/src/system/event.js +10 -10
- package/src/system/pooling.js +156 -149
- package/src/system/timer.js +1 -1
- package/src/text/bitmaptext.js +1 -1
- package/src/text/text.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 +104 -36
- package/src/video/renderer.js +28 -16
- package/src/video/texture.js +1 -1
- package/src/video/video.js +11 -11
- package/src/video/webgl/glshader.js +30 -194
- package/src/video/webgl/utils/attributes.js +16 -0
- package/src/video/webgl/utils/precision.js +11 -0
- package/src/video/webgl/utils/program.js +58 -0
- package/src/video/webgl/utils/string.js +16 -0
- package/src/video/webgl/utils/uniforms.js +87 -0
- package/src/video/webgl/webgl_compositor.js +1 -14
- package/src/video/webgl/webgl_renderer.js +129 -186
- 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
|
};
|
|
@@ -109,53 +112,45 @@ function _checkCapabilities() {
|
|
|
109
112
|
// detect device type/platform
|
|
110
113
|
_detectDevice();
|
|
111
114
|
|
|
112
|
-
// Mobile browser hacks
|
|
113
|
-
if (device.isMobile) {
|
|
114
|
-
// Prevent the webview from moving on a swipe
|
|
115
|
-
device.enableSwipe(false);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
115
|
// Touch/Gesture Event feature detection
|
|
119
|
-
device.TouchEvent = !!("ontouchstart" in
|
|
120
|
-
device.PointerEvent = !!
|
|
121
|
-
|
|
116
|
+
device.TouchEvent = !!("ontouchstart" in globalThis);
|
|
117
|
+
device.PointerEvent = !!globalThis.PointerEvent;
|
|
118
|
+
globalThis.gesture = prefixed("gesture");
|
|
122
119
|
|
|
123
120
|
// detect touch capabilities
|
|
124
121
|
device.touch = device.TouchEvent || device.PointerEvent;
|
|
125
122
|
|
|
126
123
|
// 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;
|
|
124
|
+
device.maxTouchPoints = device.touch ? (device.PointerEvent ? globalThis.navigator.maxTouchPoints || 1 : 10) : 1;
|
|
128
125
|
|
|
129
126
|
// detect wheel event support
|
|
130
127
|
// Modern browsers support "wheel", Webkit and IE support at least "mousewheel
|
|
131
|
-
device.wheel =
|
|
128
|
+
device.wheel = typeof globalThis.document !== "undefined" && "onwheel" in globalThis.document.createElement("div");
|
|
132
129
|
|
|
133
130
|
// pointerlock detection (pointerLockElement can be null when the feature is supported)
|
|
134
|
-
device.hasPointerLockSupport = typeof document.pointerLockElement !== "undefined";
|
|
131
|
+
device.hasPointerLockSupport = typeof globalThis.document !== "undefined" && typeof globalThis.document.pointerLockElement !== "undefined";
|
|
135
132
|
|
|
136
133
|
// device orientation and motion detection
|
|
137
|
-
device.hasDeviceOrientation = !!
|
|
138
|
-
device.hasAccelerometer = !!
|
|
134
|
+
device.hasDeviceOrientation = !!globalThis.DeviceOrientationEvent;
|
|
135
|
+
device.hasAccelerometer = !!globalThis.DeviceMotionEvent;
|
|
139
136
|
|
|
140
137
|
// support the ScreenOrientation API
|
|
141
138
|
device.ScreenOrientation = (typeof screen !== "undefined") &&
|
|
142
139
|
(typeof screen.orientation !== "undefined");
|
|
143
140
|
|
|
144
141
|
// fullscreen api detection & polyfill when possible
|
|
145
|
-
device.hasFullscreenSupport = prefixed("fullscreenEnabled", document) ||
|
|
146
|
-
document.mozFullScreenEnabled;
|
|
142
|
+
device.hasFullscreenSupport = typeof globalThis.document !== "undefined" && (prefixed("fullscreenEnabled", globalThis.document) || globalThis.document.mozFullScreenEnabled);
|
|
147
143
|
|
|
148
|
-
|
|
149
|
-
|
|
144
|
+
if (device.hasFullscreenSupport === true) {
|
|
145
|
+
globalThis.document.exitFullscreen = typeof globalThis.document !== "undefined" && (prefixed("cancelFullScreen", globalThis.document) || prefixed("exitFullscreen", globalThis.document));
|
|
146
|
+
}
|
|
150
147
|
|
|
151
|
-
// vibration API poyfill
|
|
152
|
-
navigator.vibrate = prefixed("vibrate", navigator);
|
|
153
148
|
|
|
154
149
|
// web Audio detection
|
|
155
|
-
device.hasWebAudio = !!(
|
|
150
|
+
device.hasWebAudio = !!(globalThis.AudioContext || globalThis.webkitAudioContext);
|
|
156
151
|
|
|
157
152
|
try {
|
|
158
|
-
device.localStorage = !!
|
|
153
|
+
device.localStorage = !!globalThis.localStorage;
|
|
159
154
|
} catch (e) {
|
|
160
155
|
// the above generates an exception when cookies are blocked
|
|
161
156
|
device.localStorage = false;
|
|
@@ -165,76 +160,86 @@ function _checkCapabilities() {
|
|
|
165
160
|
// some browser (e.g. Safari) implements WebGL1 and WebGL2 contexts only
|
|
166
161
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=801176
|
|
167
162
|
device.OffscreenCanvas =
|
|
168
|
-
(typeof
|
|
163
|
+
(typeof globalThis.OffscreenCanvas !== "undefined") &&
|
|
169
164
|
((new OffscreenCanvas(0, 0).getContext( "2d" )) !== null);
|
|
170
165
|
} catch (e) {
|
|
171
166
|
device.OffscreenCanvas = false;
|
|
172
167
|
}
|
|
173
168
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
169
|
+
if (typeof globalThis.addEventListener === "function") {
|
|
170
|
+
// set pause/stop action on losing focus
|
|
171
|
+
globalThis.addEventListener("blur", function () {
|
|
172
|
+
if (device.stopOnBlur) {
|
|
173
|
+
state.stop(true);
|
|
174
|
+
}
|
|
175
|
+
if (device.pauseOnBlur) {
|
|
176
|
+
state.pause(true);
|
|
177
|
+
}
|
|
178
|
+
}, false);
|
|
179
|
+
// set restart/resume action on gaining focus
|
|
180
|
+
globalThis.addEventListener("focus", function () {
|
|
181
|
+
if (device.stopOnBlur) {
|
|
182
|
+
state.restart(true);
|
|
183
|
+
}
|
|
184
|
+
if (device.resumeOnFocus) {
|
|
185
|
+
state.resume(true);
|
|
186
|
+
}
|
|
187
|
+
// force focus if autofocus is on
|
|
188
|
+
if (device.autoFocus) {
|
|
189
|
+
device.focus();
|
|
190
|
+
}
|
|
191
|
+
}, false);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (typeof globalThis.document !== "undefined") {
|
|
195
|
+
// Set the name of the hidden property and the change event for visibility
|
|
196
|
+
var hidden, visibilityChange;
|
|
197
|
+
if (typeof globalThis.document.hidden !== "undefined") {
|
|
198
|
+
// Opera 12.10 and Firefox 18 and later support
|
|
199
|
+
hidden = "hidden";
|
|
200
|
+
visibilityChange = "visibilitychange";
|
|
201
|
+
} else if (typeof globalThis.document.mozHidden !== "undefined") {
|
|
202
|
+
hidden = "mozHidden";
|
|
203
|
+
visibilityChange = "mozvisibilitychange";
|
|
204
|
+
} else if (typeof globalThis.document.msHidden !== "undefined") {
|
|
205
|
+
hidden = "msHidden";
|
|
206
|
+
visibilityChange = "msvisibilitychange";
|
|
207
|
+
} else if (typeof globalThis.document.webkitHidden !== "undefined") {
|
|
208
|
+
hidden = "webkitHidden";
|
|
209
|
+
visibilityChange = "webkitvisibilitychange";
|
|
190
210
|
}
|
|
191
|
-
|
|
192
|
-
if
|
|
193
|
-
|
|
211
|
+
|
|
212
|
+
// register on the event if supported
|
|
213
|
+
if (typeof (visibilityChange) === "string") {
|
|
214
|
+
// add the corresponding event listener
|
|
215
|
+
globalThis.document.addEventListener(visibilityChange,
|
|
216
|
+
function () {
|
|
217
|
+
if (globalThis.document[hidden]) {
|
|
218
|
+
if (device.stopOnBlur) {
|
|
219
|
+
state.stop(true);
|
|
220
|
+
}
|
|
221
|
+
if (device.pauseOnBlur) {
|
|
222
|
+
state.pause(true);
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
if (device.stopOnBlur) {
|
|
226
|
+
state.restart(true);
|
|
227
|
+
}
|
|
228
|
+
if (device.resumeOnFocus) {
|
|
229
|
+
state.resume(true);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}, false
|
|
233
|
+
);
|
|
194
234
|
}
|
|
195
|
-
}, false);
|
|
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";
|
|
213
235
|
}
|
|
214
236
|
|
|
215
|
-
//
|
|
216
|
-
if (
|
|
217
|
-
//
|
|
218
|
-
|
|
219
|
-
function () {
|
|
220
|
-
if (document[hidden]) {
|
|
221
|
-
if (device.stopOnBlur) {
|
|
222
|
-
state.stop(true);
|
|
223
|
-
}
|
|
224
|
-
if (device.pauseOnBlur) {
|
|
225
|
-
state.pause(true);
|
|
226
|
-
}
|
|
227
|
-
} else {
|
|
228
|
-
if (device.stopOnBlur) {
|
|
229
|
-
state.restart(true);
|
|
230
|
-
}
|
|
231
|
-
if (device.resumeOnFocus) {
|
|
232
|
-
state.resume(true);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}, false
|
|
236
|
-
);
|
|
237
|
+
// Mobile browser hacks
|
|
238
|
+
if (device.isMobile) {
|
|
239
|
+
// Prevent the webview from moving on a swipe
|
|
240
|
+
device.enableSwipe(false);
|
|
237
241
|
}
|
|
242
|
+
|
|
238
243
|
};
|
|
239
244
|
|
|
240
245
|
|
|
@@ -254,7 +259,7 @@ let device = {
|
|
|
254
259
|
* @name ua
|
|
255
260
|
* @memberof device
|
|
256
261
|
*/
|
|
257
|
-
ua : navigator.userAgent,
|
|
262
|
+
ua : typeof globalThis.navigator !== "undefined" ? globalThis.navigator.userAgent : "",
|
|
258
263
|
|
|
259
264
|
/**
|
|
260
265
|
* Browser Local Storage capabilities <br>
|
|
@@ -328,7 +333,7 @@ let device = {
|
|
|
328
333
|
* @name nativeBase64
|
|
329
334
|
* @memberof device
|
|
330
335
|
*/
|
|
331
|
-
nativeBase64 : (typeof(
|
|
336
|
+
nativeBase64 : (typeof(globalThis.atob) === "function"),
|
|
332
337
|
|
|
333
338
|
/**
|
|
334
339
|
* Return the maximum number of simultaneous touch contact points are supported by the current device.
|
|
@@ -407,24 +412,33 @@ let device = {
|
|
|
407
412
|
*/
|
|
408
413
|
linux : false,
|
|
409
414
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
415
|
+
/**
|
|
416
|
+
* equals to true if the game is running under Ejecta.
|
|
417
|
+
* @type {boolean}
|
|
418
|
+
* @readonly
|
|
419
|
+
* @see http://impactjs.com/ejecta
|
|
420
|
+
* @name ejecta
|
|
421
|
+
* @memberof device
|
|
422
|
+
*/
|
|
418
423
|
ejecta : false,
|
|
419
424
|
|
|
420
425
|
/**
|
|
421
|
-
* equals to true if the
|
|
426
|
+
* equals to true if the is running under Wechat.
|
|
422
427
|
* @type {boolean}
|
|
423
428
|
* @readonly
|
|
424
429
|
* @name isWeixin
|
|
425
430
|
* @memberof device
|
|
426
431
|
*/
|
|
427
|
-
|
|
432
|
+
isWeixin : false,
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* equals to true if running under node.js
|
|
436
|
+
* @type {boolean}
|
|
437
|
+
* @readonly
|
|
438
|
+
* @name nodeJS
|
|
439
|
+
* @memberof device
|
|
440
|
+
*/
|
|
441
|
+
nodeJS : (typeof process !== "undefined") && (process.release.name === "node"),
|
|
428
442
|
|
|
429
443
|
/**
|
|
430
444
|
* equals to true if the device is running on ChromeOS.
|
|
@@ -539,7 +553,7 @@ let device = {
|
|
|
539
553
|
* @name language
|
|
540
554
|
* @memberof device
|
|
541
555
|
*/
|
|
542
|
-
language : navigator.language || navigator.browserLanguage || navigator.userLanguage || "en",
|
|
556
|
+
language : typeof globalThis.navigator !== "undefined" ? globalThis.navigator.language || globalThis.navigator.browserLanguage || globalThis.navigator.userLanguage || "en" : "en",
|
|
543
557
|
|
|
544
558
|
/**
|
|
545
559
|
* Specify whether to pause the game when losing focus
|
|
@@ -631,7 +645,7 @@ let device = {
|
|
|
631
645
|
// If the DOM is already ready
|
|
632
646
|
if (isReady) {
|
|
633
647
|
// Execute the function immediately
|
|
634
|
-
fn.call(
|
|
648
|
+
fn.call(globalThis, []);
|
|
635
649
|
}
|
|
636
650
|
else {
|
|
637
651
|
// Add the function to the wait list
|
|
@@ -640,17 +654,17 @@ let device = {
|
|
|
640
654
|
// attach listeners if not yet done
|
|
641
655
|
if (!readyBound) {
|
|
642
656
|
// directly call domReady if document is already "ready"
|
|
643
|
-
if (document.readyState === "complete") {
|
|
657
|
+
if (device.nodeJS === true || (typeof globalThis.document !== "undefined" && globalThis.document.readyState === "complete")) {
|
|
644
658
|
// defer the fn call to ensure our script is fully loaded
|
|
645
|
-
|
|
659
|
+
globalThis.setTimeout(_domReady, 0);
|
|
646
660
|
}
|
|
647
661
|
else {
|
|
648
|
-
if (document.addEventListener) {
|
|
662
|
+
if (typeof globalThis.document !== "undefined" && typeof globalThis.document.addEventListener === "function") {
|
|
649
663
|
// Use the handy event callback
|
|
650
|
-
document.addEventListener("DOMContentLoaded", _domReady, false);
|
|
664
|
+
globalThis.document.addEventListener("DOMContentLoaded", _domReady, false);
|
|
651
665
|
}
|
|
652
|
-
// A fallback to
|
|
653
|
-
|
|
666
|
+
// A fallback to globalThis.onload, that will always work
|
|
667
|
+
globalThis.addEventListener("load", _domReady, false);
|
|
654
668
|
}
|
|
655
669
|
readyBound = true;
|
|
656
670
|
}
|
|
@@ -663,13 +677,14 @@ let device = {
|
|
|
663
677
|
* @param {boolean} [enable=true] enable or disable swipe.
|
|
664
678
|
*/
|
|
665
679
|
enableSwipe(enable) {
|
|
680
|
+
var moveEvent = device.PointerEvent ? "pointermove" : (device.TouchEvent ? "touchmove" : "mousemove");
|
|
666
681
|
if (enable !== false) {
|
|
667
682
|
if (swipeEnabled === false) {
|
|
668
|
-
|
|
683
|
+
globalThis.document.removeEventListener(moveEvent, _disableSwipeFn);
|
|
669
684
|
swipeEnabled = true;
|
|
670
685
|
}
|
|
671
686
|
} else if (swipeEnabled === true) {
|
|
672
|
-
|
|
687
|
+
globalThis.document.addEventListener(moveEvent, _disableSwipeFn, { passive: false });
|
|
673
688
|
swipeEnabled = false;
|
|
674
689
|
}
|
|
675
690
|
},
|
|
@@ -723,7 +738,7 @@ let device = {
|
|
|
723
738
|
var PORTRAIT = "portrait";
|
|
724
739
|
var LANDSCAPE = "landscape";
|
|
725
740
|
|
|
726
|
-
var screen =
|
|
741
|
+
var screen = globalThis.screen;
|
|
727
742
|
|
|
728
743
|
// first try using "standard" values
|
|
729
744
|
if (this.ScreenOrientation === true) {
|
|
@@ -738,12 +753,12 @@ let device = {
|
|
|
738
753
|
}
|
|
739
754
|
|
|
740
755
|
// check using the deprecated API
|
|
741
|
-
if (typeof
|
|
742
|
-
return (Math.abs(
|
|
756
|
+
if (typeof globalThis.orientation === "number") {
|
|
757
|
+
return (Math.abs(globalThis.orientation) === 90) ? LANDSCAPE : PORTRAIT;
|
|
743
758
|
}
|
|
744
759
|
|
|
745
760
|
// fallback to window size check
|
|
746
|
-
return (
|
|
761
|
+
return (globalThis.outerWidth > globalThis.outerHeight) ? LANDSCAPE : PORTRAIT;
|
|
747
762
|
},
|
|
748
763
|
|
|
749
764
|
/**
|
|
@@ -755,7 +770,7 @@ let device = {
|
|
|
755
770
|
* @returns {boolean} true if the orientation was unsuccessfully locked
|
|
756
771
|
*/
|
|
757
772
|
lockOrientation(orientation) {
|
|
758
|
-
var screen =
|
|
773
|
+
var screen = globalThis.screen;
|
|
759
774
|
if (typeof screen !== "undefined") {
|
|
760
775
|
var _lockOrientation = prefixed("lockOrientation", screen);
|
|
761
776
|
if (typeof _lockOrientation !== "undefined") {
|
|
@@ -773,7 +788,7 @@ let device = {
|
|
|
773
788
|
* @returns {boolean} true if the orientation was unsuccessfully unlocked
|
|
774
789
|
*/
|
|
775
790
|
unlockOrientation() {
|
|
776
|
-
var screen =
|
|
791
|
+
var screen = globalThis.screen;
|
|
777
792
|
if (typeof screen !== "undefined") {
|
|
778
793
|
var _unlockOrientation = prefixed("unlockOrientation", screen);
|
|
779
794
|
if (typeof _unlockOrientation !== "undefined") {
|
|
@@ -872,8 +887,8 @@ let device = {
|
|
|
872
887
|
if (typeof element === "object" && element !== document.body && typeof element.getBoundingClientRect !== "undefined") {
|
|
873
888
|
return element.getBoundingClientRect();
|
|
874
889
|
} else {
|
|
875
|
-
_domRect.width = _domRect.right =
|
|
876
|
-
_domRect.height = _domRect.bottom =
|
|
890
|
+
_domRect.width = _domRect.right = globalThis.innerWidth;
|
|
891
|
+
_domRect.height = _domRect.bottom = globalThis.innerHeight;
|
|
877
892
|
return _domRect;
|
|
878
893
|
};
|
|
879
894
|
},
|
|
@@ -905,7 +920,7 @@ let device = {
|
|
|
905
920
|
stencil: true,
|
|
906
921
|
failIfMajorPerformanceCaveat : options.failIfMajorPerformanceCaveat
|
|
907
922
|
};
|
|
908
|
-
_supported = !! (
|
|
923
|
+
_supported = !! (globalThis.WebGLRenderingContext && (canvas.getContext("webgl", ctxOptions) || canvas.getContext("experimental-webgl", ctxOptions)));
|
|
909
924
|
} catch (e) {
|
|
910
925
|
_supported = false;
|
|
911
926
|
}
|
|
@@ -940,8 +955,8 @@ let device = {
|
|
|
940
955
|
* }
|
|
941
956
|
*/
|
|
942
957
|
focus() {
|
|
943
|
-
if (typeof (
|
|
944
|
-
|
|
958
|
+
if (typeof (globalThis.focus) === "function") {
|
|
959
|
+
globalThis.focus();
|
|
945
960
|
}
|
|
946
961
|
},
|
|
947
962
|
|
|
@@ -995,13 +1010,13 @@ let device = {
|
|
|
995
1010
|
.then(response => {
|
|
996
1011
|
if (response === "granted") {
|
|
997
1012
|
// add a listener for the devicemotion event
|
|
998
|
-
|
|
1013
|
+
globalThis.addEventListener("devicemotion", this.onDeviceMotion, false);
|
|
999
1014
|
accelInitialized = true;
|
|
1000
1015
|
}
|
|
1001
1016
|
}).catch(console.error);
|
|
1002
1017
|
} else {
|
|
1003
1018
|
// add a listener for the devicemotion event
|
|
1004
|
-
|
|
1019
|
+
globalThis.addEventListener("devicemotion", this.onDeviceMotion, false);
|
|
1005
1020
|
accelInitialized = true;
|
|
1006
1021
|
}
|
|
1007
1022
|
}
|
|
@@ -1015,7 +1030,7 @@ let device = {
|
|
|
1015
1030
|
unwatchAccelerometer() {
|
|
1016
1031
|
if (accelInitialized) {
|
|
1017
1032
|
// remove the listener for the devicemotion event
|
|
1018
|
-
|
|
1033
|
+
globalThis.removeEventListener("devicemotion", this.onDeviceMotion, false);
|
|
1019
1034
|
accelInitialized = false;
|
|
1020
1035
|
}
|
|
1021
1036
|
},
|
|
@@ -1045,12 +1060,12 @@ let device = {
|
|
|
1045
1060
|
DeviceOrientationEvent.requestPermission()
|
|
1046
1061
|
.then(response => {
|
|
1047
1062
|
if (response === "granted") {
|
|
1048
|
-
|
|
1063
|
+
globalThis.addEventListener("deviceorientation", this.onDeviceRotate, false);
|
|
1049
1064
|
deviceOrientationInitialized = true;
|
|
1050
1065
|
}
|
|
1051
1066
|
}).catch(console.error);
|
|
1052
1067
|
} else {
|
|
1053
|
-
|
|
1068
|
+
globalThis.addEventListener("deviceorientation", this.onDeviceRotate, false);
|
|
1054
1069
|
deviceOrientationInitialized = true;
|
|
1055
1070
|
}
|
|
1056
1071
|
}
|
|
@@ -1063,7 +1078,7 @@ let device = {
|
|
|
1063
1078
|
*/
|
|
1064
1079
|
unwatchDeviceOrientation() {
|
|
1065
1080
|
if (deviceOrientationInitialized) {
|
|
1066
|
-
|
|
1081
|
+
globalThis.removeEventListener("deviceorientation", this.onDeviceRotate, false);
|
|
1067
1082
|
deviceOrientationInitialized = false;
|
|
1068
1083
|
}
|
|
1069
1084
|
},
|
|
@@ -1086,8 +1101,8 @@ let device = {
|
|
|
1086
1101
|
* me.device.vibrate(0);
|
|
1087
1102
|
*/
|
|
1088
1103
|
vibrate(pattern) {
|
|
1089
|
-
if (navigator.vibrate) {
|
|
1090
|
-
navigator.vibrate(pattern);
|
|
1104
|
+
if (typeof globalThis.navigator !== "undefined" && typeof globalThis.navigator.vibrate === "function") {
|
|
1105
|
+
globalThis.navigator.vibrate(pattern);
|
|
1091
1106
|
}
|
|
1092
1107
|
}
|
|
1093
1108
|
|
|
@@ -1107,7 +1122,7 @@ Object.defineProperty(device, "devicePixelRatio", {
|
|
|
1107
1122
|
* @ignore
|
|
1108
1123
|
*/
|
|
1109
1124
|
get: function () {
|
|
1110
|
-
return (
|
|
1125
|
+
return (globalThis.devicePixelRatio || 1);
|
|
1111
1126
|
}
|
|
1112
1127
|
});
|
|
1113
1128
|
|
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.
|