q5 2.27.2 → 2.27.4
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/deno.json +1 -1
- package/package.json +1 -1
- package/q5.d.ts +190 -71
- package/q5.js +43 -41
- package/q5.min.js +1 -1
package/q5.js
CHANGED
|
@@ -74,7 +74,8 @@ function Q5(scope, parent, renderer) {
|
|
|
74
74
|
|
|
75
75
|
$._preloadPromises = [];
|
|
76
76
|
$._usePreload = true;
|
|
77
|
-
$.
|
|
77
|
+
$.usePromiseLoading = (v = true) => ($._usePreload = !v);
|
|
78
|
+
$.usePreloadSystem = (v = true) => ($._usePreload = v);
|
|
78
79
|
$.isPreloadSupported = () => $._usePreload;
|
|
79
80
|
|
|
80
81
|
const resolvers = [];
|
|
@@ -299,6 +300,8 @@ function Q5(scope, parent, renderer) {
|
|
|
299
300
|
await Promise.all($._preloadPromises);
|
|
300
301
|
if ($._g) await Promise.all($._g._preloadPromises);
|
|
301
302
|
|
|
303
|
+
if (t.setup?.constructor.name == 'AsyncFunction') $.usePromiseLoading();
|
|
304
|
+
|
|
302
305
|
for (let name of userFns) wrapWithFES(name);
|
|
303
306
|
|
|
304
307
|
$.draw = t.draw || (() => {});
|
|
@@ -312,6 +315,8 @@ function Q5(scope, parent, renderer) {
|
|
|
312
315
|
raf($._draw);
|
|
313
316
|
}
|
|
314
317
|
|
|
318
|
+
Q5.instances.push($);
|
|
319
|
+
|
|
315
320
|
if (autoLoaded) _start();
|
|
316
321
|
else setTimeout(_start, 32);
|
|
317
322
|
}
|
|
@@ -325,6 +330,7 @@ Q5._server = typeof process == 'object';
|
|
|
325
330
|
Q5._esm = this === undefined;
|
|
326
331
|
|
|
327
332
|
Q5._instanceCount = 0;
|
|
333
|
+
Q5.instances = [];
|
|
328
334
|
Q5._friendlyError = (msg, func) => {
|
|
329
335
|
if (!Q5.disableFriendlyErrors) console.error(func + ': ' + msg);
|
|
330
336
|
};
|
|
@@ -458,7 +464,7 @@ Q5.modules.canvas = ($, q) => {
|
|
|
458
464
|
}
|
|
459
465
|
}).observe(c);
|
|
460
466
|
}
|
|
461
|
-
}
|
|
467
|
+
} else c.visible = true;
|
|
462
468
|
}
|
|
463
469
|
|
|
464
470
|
$._setCanvasSize(w, h);
|
|
@@ -3138,7 +3144,7 @@ Q5.modules.fes = ($) => {
|
|
|
3138
3144
|
|
|
3139
3145
|
let bug = ['🐛', '🐞', '🐜', '🦗', '🦋', '🪲'][Math.floor(Math.random() * 6)];
|
|
3140
3146
|
|
|
3141
|
-
|
|
3147
|
+
$.log(
|
|
3142
3148
|
'%cq5.js ' + bug + '%c Error in ' + fileBase + ' on line ' + lineNum + ':\n\n' + errLine,
|
|
3143
3149
|
'background: #b7ebff; color: #000;',
|
|
3144
3150
|
''
|
|
@@ -3213,8 +3219,10 @@ Q5.modules.input = ($, q) => {
|
|
|
3213
3219
|
q.moveY = e.movementY;
|
|
3214
3220
|
};
|
|
3215
3221
|
|
|
3222
|
+
let pressAmt = 0;
|
|
3223
|
+
|
|
3216
3224
|
$._onmousedown = (e) => {
|
|
3217
|
-
|
|
3225
|
+
pressAmt++;
|
|
3218
3226
|
$._startAudio();
|
|
3219
3227
|
$._updateMouse(e);
|
|
3220
3228
|
q.mouseIsPressed = true;
|
|
@@ -3223,20 +3231,21 @@ Q5.modules.input = ($, q) => {
|
|
|
3223
3231
|
};
|
|
3224
3232
|
|
|
3225
3233
|
$._onmousemove = (e) => {
|
|
3234
|
+
if (c && !c.visible) return;
|
|
3226
3235
|
$._updateMouse(e);
|
|
3227
3236
|
if ($.mouseIsPressed) $.mouseDragged(e);
|
|
3228
3237
|
else $.mouseMoved(e);
|
|
3229
3238
|
};
|
|
3230
3239
|
|
|
3231
3240
|
$._onmouseup = (e) => {
|
|
3232
|
-
if (
|
|
3241
|
+
if (pressAmt > 0) pressAmt--;
|
|
3242
|
+
else return;
|
|
3233
3243
|
$._updateMouse(e);
|
|
3234
3244
|
q.mouseIsPressed = false;
|
|
3235
3245
|
$.mouseReleased(e);
|
|
3236
3246
|
};
|
|
3237
3247
|
|
|
3238
3248
|
$._onclick = (e) => {
|
|
3239
|
-
if (!c?.visible) return;
|
|
3240
3249
|
$._updateMouse(e);
|
|
3241
3250
|
q.mouseIsPressed = true;
|
|
3242
3251
|
$.mouseClicked(e);
|
|
@@ -3244,7 +3253,6 @@ Q5.modules.input = ($, q) => {
|
|
|
3244
3253
|
};
|
|
3245
3254
|
|
|
3246
3255
|
$._ondblclick = (e) => {
|
|
3247
|
-
if (!c?.visible) return;
|
|
3248
3256
|
$._updateMouse(e);
|
|
3249
3257
|
q.mouseIsPressed = true;
|
|
3250
3258
|
$.doubleClicked(e);
|
|
@@ -3252,7 +3260,6 @@ Q5.modules.input = ($, q) => {
|
|
|
3252
3260
|
};
|
|
3253
3261
|
|
|
3254
3262
|
$._onwheel = (e) => {
|
|
3255
|
-
if (!c?.visible) return;
|
|
3256
3263
|
$._updateMouse(e);
|
|
3257
3264
|
e.delta = e.deltaY;
|
|
3258
3265
|
if ($.mouseWheel(e) == false || $._noScroll) e.preventDefault();
|
|
@@ -3317,37 +3324,19 @@ Q5.modules.input = ($, q) => {
|
|
|
3317
3324
|
}
|
|
3318
3325
|
|
|
3319
3326
|
$._ontouchstart = (e) => {
|
|
3320
|
-
if (!c?.visible) return;
|
|
3321
3327
|
$._startAudio();
|
|
3322
3328
|
q.touches = [...e.touches].map(getTouchInfo);
|
|
3323
|
-
if (!$.
|
|
3324
|
-
q.mouseX = $.touches[0].x;
|
|
3325
|
-
q.mouseY = $.touches[0].y;
|
|
3326
|
-
q.mouseIsPressed = true;
|
|
3327
|
-
q.mouseButton = $.LEFT;
|
|
3328
|
-
$.mousePressed(e);
|
|
3329
|
-
}
|
|
3330
|
-
$.touchStarted(e);
|
|
3329
|
+
if (!$.touchStarted(e)) e.preventDefault();
|
|
3331
3330
|
};
|
|
3332
3331
|
|
|
3333
3332
|
$._ontouchmove = (e) => {
|
|
3334
|
-
if (!c
|
|
3333
|
+
if (c && !c.visible) return;
|
|
3335
3334
|
q.touches = [...e.touches].map(getTouchInfo);
|
|
3336
|
-
if (!$._isTouchAware) {
|
|
3337
|
-
q.mouseX = $.touches[0].x;
|
|
3338
|
-
q.mouseY = $.touches[0].y;
|
|
3339
|
-
if (!$.mouseDragged(e)) e.preventDefault();
|
|
3340
|
-
}
|
|
3341
3335
|
if (!$.touchMoved(e)) e.preventDefault();
|
|
3342
3336
|
};
|
|
3343
3337
|
|
|
3344
3338
|
$._ontouchend = (e) => {
|
|
3345
|
-
if (!c?.visible) return;
|
|
3346
3339
|
q.touches = [...e.touches].map(getTouchInfo);
|
|
3347
|
-
if (!$._isTouchAware && !$.touches.length) {
|
|
3348
|
-
q.mouseIsPressed = false;
|
|
3349
|
-
if (!$.mouseReleased(e)) e.preventDefault();
|
|
3350
|
-
}
|
|
3351
3340
|
if (!$.touchEnded(e)) e.preventDefault();
|
|
3352
3341
|
};
|
|
3353
3342
|
|
|
@@ -3356,24 +3345,30 @@ Q5.modules.input = ($, q) => {
|
|
|
3356
3345
|
l('keydown', (e) => $._onkeydown(e), false);
|
|
3357
3346
|
l('keyup', (e) => $._onkeyup(e), false);
|
|
3358
3347
|
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
l('
|
|
3362
|
-
|
|
3363
|
-
l('
|
|
3348
|
+
let pointer = window.PointerEvent ? 'pointer' : 'mouse';
|
|
3349
|
+
|
|
3350
|
+
l(pointer + 'move', (e) => $._onmousemove(e), false);
|
|
3351
|
+
|
|
3352
|
+
l('touchmove', (e) => $._ontouchmove(e));
|
|
3364
3353
|
|
|
3365
3354
|
if (!c) l('wheel', (e) => $._onwheel(e));
|
|
3355
|
+
// making the window level event listener for wheel events
|
|
3356
|
+
// not passive would be necessary to be able to use `e.preventDefault`
|
|
3357
|
+
// but browsers warn that it's bad for performance
|
|
3358
|
+
else c.addEventListener('wheel', (e) => $._onwheel(e));
|
|
3359
|
+
|
|
3360
|
+
if (!$._isGlobal && c) l = c.addEventListener.bind(c);
|
|
3361
|
+
|
|
3362
|
+
l(pointer + 'down', (e) => $._onmousedown(e));
|
|
3363
|
+
l(pointer + 'up', (e) => $._onmouseup(e));
|
|
3364
|
+
|
|
3365
|
+
l('click', (e) => $._onclick(e));
|
|
3366
|
+
l('dblclick', (e) => $._ondblclick(e));
|
|
3366
3367
|
|
|
3367
3368
|
l('touchstart', (e) => $._ontouchstart(e));
|
|
3368
|
-
l('touchmove', (e) => $._ontouchmove(e));
|
|
3369
3369
|
l('touchend', (e) => $._ontouchend(e));
|
|
3370
3370
|
l('touchcancel', (e) => $._ontouchend(e));
|
|
3371
3371
|
}
|
|
3372
|
-
|
|
3373
|
-
// making the window level event listener for wheel events
|
|
3374
|
-
// not passive would be necessary to be able to use `e.preventDefault`
|
|
3375
|
-
// but browsers warn that it's bad for performance
|
|
3376
|
-
if (c) c.addEventListener('wheel', (e) => $._onwheel(e));
|
|
3377
3372
|
};
|
|
3378
3373
|
Q5.modules.math = ($, q) => {
|
|
3379
3374
|
$.RADIANS = 0;
|
|
@@ -4237,12 +4232,18 @@ Q5.modules.sound = ($, q) => {
|
|
|
4237
4232
|
Q5.soundOut = Q5.aud.createGain();
|
|
4238
4233
|
Q5.soundOut.connect(Q5.aud.destination);
|
|
4239
4234
|
|
|
4240
|
-
for (let
|
|
4235
|
+
for (let inst of Q5.instances) {
|
|
4236
|
+
inst._userAudioStarted();
|
|
4237
|
+
}
|
|
4241
4238
|
}
|
|
4242
4239
|
return Q5.aud.resume();
|
|
4243
4240
|
}
|
|
4244
4241
|
};
|
|
4245
4242
|
|
|
4243
|
+
$._userAudioStarted = () => {
|
|
4244
|
+
for (let s of sounds) s.init();
|
|
4245
|
+
};
|
|
4246
|
+
|
|
4246
4247
|
$.outputVolume = (level) => {
|
|
4247
4248
|
if (Q5.soundOut) Q5.soundOut.gain.value = level;
|
|
4248
4249
|
};
|
|
@@ -4266,6 +4267,7 @@ Q5.Sound = class {
|
|
|
4266
4267
|
let res = await fetch(url);
|
|
4267
4268
|
this.buffer = await res.arrayBuffer();
|
|
4268
4269
|
this.buffer = await Q5.aud.decodeAudioData(this.buffer);
|
|
4270
|
+
if (Q5.aud) this.init();
|
|
4269
4271
|
}
|
|
4270
4272
|
|
|
4271
4273
|
init() {
|
|
@@ -4451,7 +4453,7 @@ Q5.modules.util = ($, q) => {
|
|
|
4451
4453
|
} else {
|
|
4452
4454
|
obj = $.loadText(url);
|
|
4453
4455
|
}
|
|
4454
|
-
promises.push(obj.promise);
|
|
4456
|
+
promises.push($._usePreload ? obj.promise : obj);
|
|
4455
4457
|
}
|
|
4456
4458
|
|
|
4457
4459
|
if (urls.length == 1) return promises[0];
|