q5play 4.0.1 → 4.0.2

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/LICENSE.md CHANGED
@@ -1,3 +1,5 @@
1
+ SPDX-License-Identifier: LicenseRef-q5play-Creator-License
2
+
1
3
  # q5play Creator License
2
4
 
3
5
  This License Agreement ("Agreement") is made between Quinton Ashley, the sole copyright owner of q5play ("Licensor") and an individual, organization, or company ("Licensee") that is using q5play.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q5play",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "author": "quinton-ashley",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "description": "A web-based game engine that uses q5.js WebGPU for graphics and Box2D v3 WASM for physics.",
package/q5play.d.ts CHANGED
@@ -2600,6 +2600,18 @@ declare global {
2600
2600
  * @returns true on the first frame that the user releases the input after dragging the mouse
2601
2601
  */
2602
2602
  dragged(inp?: string): boolean;
2603
+ /**
2604
+ * @returns true on the first frame that the user scrolls the mouse wheel
2605
+ */
2606
+ scrolls(): boolean;
2607
+ /**
2608
+ * @returns the amount of frames the user has been scrolling the mouse wheel
2609
+ */
2610
+ scrolling(): number;
2611
+ /**
2612
+ * @returns true on the first frame that the user stops scrolling the mouse wheel
2613
+ */
2614
+ scrolled(): boolean;
2603
2615
  }
2604
2616
 
2605
2617
  class _Pointer extends InputDevice {
package/q5play.js CHANGED
@@ -584,11 +584,18 @@ async function q5playPreSetup($, q) {
584
584
  this.x += this.vx * timeScale;
585
585
  this.y += this.vy * timeScale;
586
586
 
587
+ if (this.tint) $.tint(this.tint);
588
+ if (this.opacity) $.opacity(this.opacity);
589
+
587
590
  if (this.ani) {
588
591
  $.animation(this.ani, this.x, this.y);
589
592
  } else if (this._img) {
590
593
  $.image(this._img, this.x, this.y);
591
594
  }
595
+
596
+ if (this.tint) $.noTint();
597
+ if (this.opacity) $.opacity(1);
598
+
592
599
  this.life -= timeScale;
593
600
  }
594
601
 
@@ -698,24 +705,26 @@ async function q5playPreSetup($, q) {
698
705
  }
699
706
 
700
707
  changeAni(name) {
701
- let ani = this._anis?.[name];
708
+ let ani = this.anis[name];
702
709
  if (!ani) {
703
- for (let g of this.groups || []) {
704
- ani = g._anis?.[name] || g._anis?.[name];
705
- if (ani) {
706
- ani = ani.clone();
707
- break;
710
+ const groups = this.groups;
711
+ if (groups) {
712
+ for (let g of groups) {
713
+ ani = g._anis?.[name];
714
+ if (ani) break;
708
715
  }
716
+ } else {
717
+ let v = this._visuals;
718
+ ani = v._anis?.[name];
709
719
  }
710
- if (!ani) {
711
- console.error('Ani not found: ' + name);
712
- return;
713
- }
720
+ if (ani) ani = ani.clone();
721
+ else return console.error('Ani not found: ' + name);
714
722
  }
715
723
  // reset to frame 0 of that animation
716
724
  if (this.resetAniOnChange) ani._frame = 0;
717
725
  ani.name = name;
718
726
  this.ani = ani;
727
+ this.anis[name] = ani;
719
728
  }
720
729
 
721
730
  playAni(name) {
@@ -3700,6 +3709,7 @@ async function q5playPreSetup($, q) {
3700
3709
  else this.img = _this._img;
3701
3710
  _this.push(this);
3702
3711
  _this.amount++;
3712
+ this._visuals = _this;
3703
3713
  }
3704
3714
  };
3705
3715
  }
@@ -3953,6 +3963,10 @@ async function q5playPreSetup($, q) {
3953
3963
  constructor() {
3954
3964
  super(_this, ...arguments);
3955
3965
  }
3966
+
3967
+ static withSensor() {
3968
+ return new $.Sprite(null, _this, ...arguments);
3969
+ }
3956
3970
  };
3957
3971
 
3958
3972
  this.Group = class extends $.Group {
@@ -5214,6 +5228,26 @@ async function q5playPreSetup($, q) {
5214
5228
  this._calcBoundsY(val);
5215
5229
  }
5216
5230
 
5231
+ get zoom() {
5232
+ return this._zoom;
5233
+ }
5234
+ set zoom(val) {
5235
+ if (val === undefined || isNaN(val)) return;
5236
+ this._zoom = val;
5237
+ let x = -this._pos.x;
5238
+ if ($._c2d) x += $.canvas.hw / val;
5239
+ let y = -this._pos.y;
5240
+ if ($._c2d) y += $.canvas.hh / val;
5241
+ this.__pos.x = x;
5242
+ this.__pos.y = y;
5243
+ if ($.allSprites.pixelPerfect) {
5244
+ this.__pos.rounded.x = Math.round(x);
5245
+ this.__pos.rounded.y = Math.round(y);
5246
+ }
5247
+ this._calcBoundsX(this._pos.x);
5248
+ this._calcBoundsY(this._pos.y);
5249
+ }
5250
+
5217
5251
  moveTo(x, y, speed) {
5218
5252
  if (x === undefined) return;
5219
5253
  if (isNaN(x)) {
@@ -5243,7 +5277,7 @@ async function q5playPreSetup($, q) {
5243
5277
  this.x += velX;
5244
5278
  this.y += velY;
5245
5279
 
5246
- await $.delay(16);
5280
+ await $.delay();
5247
5281
  if (destIdx != this._destIdx) return false;
5248
5282
  }
5249
5283
  this.x = x;
@@ -5252,26 +5286,6 @@ async function q5playPreSetup($, q) {
5252
5286
  })();
5253
5287
  }
5254
5288
 
5255
- get zoom() {
5256
- return this._zoom;
5257
- }
5258
- set zoom(val) {
5259
- if (val === undefined || isNaN(val)) return;
5260
- this._zoom = val;
5261
- let x = -this._pos.x;
5262
- if ($._c2d) x += $.canvas.hw / val;
5263
- let y = -this._pos.y;
5264
- if ($._c2d) y += $.canvas.hh / val;
5265
- this.__pos.x = x;
5266
- this.__pos.y = y;
5267
- if ($.allSprites.pixelPerfect) {
5268
- this.__pos.rounded.x = Math.round(x);
5269
- this.__pos.rounded.y = Math.round(y);
5270
- }
5271
- this._calcBoundsX(this._pos.x);
5272
- this._calcBoundsY(this._pos.y);
5273
- }
5274
-
5275
5289
  zoomTo(target, speed) {
5276
5290
  if (target == this._zoom) return Promise.resolve(true);
5277
5291
  speed ??= 0.1;
@@ -5287,7 +5301,7 @@ async function q5playPreSetup($, q) {
5287
5301
  for (let i = 0; i < frames; i++) {
5288
5302
  if (zoomIdx != this._zoomIdx) return false;
5289
5303
  this.zoom += speed;
5290
- await $.delay(16);
5304
+ await $.delay();
5291
5305
  }
5292
5306
  this.zoom = target;
5293
5307
  return true;
@@ -6505,6 +6519,9 @@ async function q5playPreSetup($, q) {
6505
6519
  let sd = $.mouse.scrollDelta;
6506
6520
  sd.x = e.deltaX;
6507
6521
  sd.y = e.deltaY;
6522
+ if (Math.abs(sd.x) > 1 || Math.abs(sd.y) > 1) {
6523
+ $.mouse.scroll++;
6524
+ }
6508
6525
  });
6509
6526
  c.addEventListener('touchstart', (e) => e.preventDefault());
6510
6527
  // this stops the right click menu from appearing
@@ -6794,8 +6811,14 @@ async function q5playPreSetup($, q) {
6794
6811
 
6795
6812
  _update() {
6796
6813
  let cam = $.camera;
6797
- this.x = $.mouseX / cam.zoom + cam.x;
6798
- this.y = $.mouseY / cam.zoom + cam.y;
6814
+ let m = this;
6815
+ m.x = $.mouseX / cam.zoom + cam.x;
6816
+ m.y = $.mouseY / cam.zoom + cam.y;
6817
+
6818
+ if (m.scroll < 0) m.scroll = 0;
6819
+ if (m.scrollDelta.x == 0 && m.scrollDelta.y == 0) {
6820
+ m.scroll = m.scroll == 1 ? -3 : m.scroll > 0 ? -1 : 0;
6821
+ }
6799
6822
  }
6800
6823
 
6801
6824
  get pos() {
@@ -6837,6 +6860,16 @@ async function q5playPreSetup($, q) {
6837
6860
  inp ??= this._default;
6838
6861
  return this.drag[inp] <= -1;
6839
6862
  }
6863
+
6864
+ scrolls() {
6865
+ return this.scroll == 1;
6866
+ }
6867
+ scrolling() {
6868
+ return this.scroll > 0 ? this.scroll : 0;
6869
+ }
6870
+ scrolled() {
6871
+ return this.scroll <= -1;
6872
+ }
6840
6873
  };
6841
6874
 
6842
6875
  $.mouse = new $._Mouse();
@@ -8131,7 +8164,7 @@ function q5playPostDraw() {
8131
8164
  }
8132
8165
 
8133
8166
  function q5playRemove() {
8134
- this.world.delete();
8167
+ this.world?.delete();
8135
8168
  }
8136
8169
 
8137
8170
  Q5.addHook('presetup', q5playPreSetup);