@caperjs/plugin-crunch 0.7.0 → 0.7.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/README.md CHANGED
@@ -122,6 +122,11 @@ gsap.to(platform, {
122
122
 
123
123
  Trigger zones for detecting overlaps (collectibles, checkpoints, damage zones).
124
124
 
125
+ A sensor is dynamic unless `isStatic` is set: it falls with gravity and rides solids, and like an
126
+ actor its velocity is clamped to the system's `maxVelocity`. Set `isStatic: true` for a sensor that
127
+ should simply stay where you put it. A dynamic sensor with no solid beneath it never lands: it keeps
128
+ falling (at `maxVelocity`) until you remove it.
129
+
125
130
  ```typescript
126
131
  class Coin extends Sensor {
127
132
  onActorEnter(actor: Actor) {
package/lib/Sensor.d.ts CHANGED
@@ -128,12 +128,21 @@ export declare class Sensor<D extends EntityData = EntityData> extends Entity<D>
128
128
  * @param deltaTime - Delta time in seconds
129
129
  */
130
130
  update(deltaTime: number): void;
131
+ /**
132
+ * The only actors a move of (dx, dy) pixels can start or stop overlapping: those
133
+ * touching the area swept by the move, plus the ones overlapping right now (they
134
+ * may be left behind). Built once per move so the per-pixel loop scans a handful
135
+ * of actors instead of rebuilding and walking the whole list for every pixel.
136
+ */
137
+ private getOverlapCandidates;
131
138
  /**
132
139
  * Checks for overlapping actors and triggers callbacks.
133
140
  *
141
+ * @param candidates - Restrict the scan to these actors (see getOverlapCandidates).
142
+ * Omit for a full scan of every actor of the collidable types.
134
143
  * @returns Set of current overlaps
135
144
  */
136
- checkActorOverlaps(): Set<SensorOverlap>;
145
+ checkActorOverlaps(candidates?: Iterable<Actor>): Set<SensorOverlap>;
137
146
  reset(): void;
138
147
  /**
139
148
  * Called when an actor starts overlapping with this sensor.
@@ -1 +1 @@
1
- {"version":3,"file":"Sensor.d.ts","sourceRoot":"","sources":["../src/Sensor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,MAAM,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E,KAAK,EAAE,CAAC,GAAG,IAAI;IAK5D;;;;;OAKG;IACI,WAAW,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAK3D;;;;;;OAMG;IACH,SAAS,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE;CAGrD"}
@@ -567,14 +567,14 @@ var v = class {
567
567
  let t = Math.round(this._xRemainder);
568
568
  if (t !== 0) {
569
569
  this._xRemainder -= t;
570
- let e = Math.sign(t), n = Math.abs(t);
570
+ let e = Math.sign(t), n = Math.abs(t), r = this.getOverlapCandidates(t, 0);
571
571
  for (; n > 0;) {
572
- let t = e, r = this.x + t, i = !1;
573
- for (let e of this.getSolidsAt(r, this.y)) if (e.canCollide) {
574
- i = !0;
572
+ let t = e, i = this.x + t, a = !1;
573
+ for (let e of this.getSolidsAt(i, this.y)) if (e.canCollide) {
574
+ a = !0;
575
575
  break;
576
576
  }
577
- if (!i) this._x = r, n--, this.updateView(), this.checkActorOverlaps();
577
+ if (!a) this._x = i, n--, this.updateView(), this.checkActorOverlaps(r);
578
578
  else {
579
579
  this.velocity.x = 0;
580
580
  break;
@@ -588,16 +588,16 @@ var v = class {
588
588
  let t = Math.round(this._yRemainder);
589
589
  if (t !== 0) {
590
590
  this._yRemainder -= t;
591
- let e = Math.sign(t), n = Math.abs(t);
591
+ let e = Math.sign(t), n = Math.abs(t), r = this.getOverlapCandidates(0, t);
592
592
  for (; n > 0;) {
593
- let t = e, r = this.y + t, i = !1;
593
+ let t = e, i = this.y + t, a = !1;
594
594
  if (Math.sign(this.system.gravity) === e) {
595
- for (let e of this.getSolidsAt(this.x, r)) if (e.canCollide) {
596
- i = !0;
595
+ for (let e of this.getSolidsAt(this.x, i)) if (e.canCollide) {
596
+ a = !0;
597
597
  break;
598
598
  }
599
599
  }
600
- if (!i) this._y = r, n--, this.updateView(), this.checkActorOverlaps();
600
+ if (!a) this._y = i, n--, this.updateView(), this.checkActorOverlaps(r);
601
601
  else {
602
602
  this.velocity.y = 0;
603
603
  break;
@@ -606,20 +606,28 @@ var v = class {
606
606
  }
607
607
  }
608
608
  update(e) {
609
- this._isRidingSolidCache = null, this.active && (!this.isStatic && !this.isRidingSolid() && (this.velocity.y += this.system.gravity * e), this.velocity.x !== 0 && this.moveX(this.velocity.x * e), this.velocity.y !== 0 && this.moveY(this.velocity.y * e));
609
+ if (this._isRidingSolidCache = null, !this.active) return;
610
+ !this.isStatic && !this.isRidingSolid() && (this.velocity.y += this.system.gravity * e);
611
+ let t = this.system.maxVelocity;
612
+ this.velocity.x = Math.min(Math.max(this.velocity.x, -t), t), this.velocity.y = Math.min(Math.max(this.velocity.y, -t), t), this.velocity.x !== 0 && this.moveX(this.velocity.x * e), this.velocity.y !== 0 && this.moveY(this.velocity.y * e);
610
613
  }
611
- checkActorOverlaps() {
614
+ getOverlapCandidates(e, t) {
615
+ let n = new Set(this.overlappingActors), r = Math.min(this.x, this.x + e), i = Math.min(this.y, this.y + t), a = Math.max(this.x, this.x + e) + this.width, o = Math.max(this.y, this.y + t) + this.height;
616
+ for (let e of this.system.getActorsByType(this.collidableTypes)) e.x < a && e.x + e.width > r && e.y < o && e.y + e.height > i && n.add(e);
617
+ return n;
618
+ }
619
+ checkActorOverlaps(e) {
612
620
  if (this.collisionMask === 0 || !this.active) return /* @__PURE__ */ new Set();
613
621
  this._currentSensorOverlaps.clear(), this._currentOverlaps.clear();
614
- let e = this.collisionLayer, t = this.collisionMask, n = this.system.getActorsByType(this.collidableTypes);
615
- for (let r of n) r.active && ((e & r.collisionMask) === 0 || (r.collisionLayer & t) === 0 || this.system.aabbOverlap(this, r) && (this._currentOverlaps.add(r), this.overlappingActors.has(r) || (this._currentSensorOverlaps.add({
616
- actor: r,
622
+ let t = this.collisionLayer, n = this.collisionMask, r = e ?? this.system.getActorsByType(this.collidableTypes);
623
+ for (let e of r) e.active && ((t & e.collisionMask) === 0 || (e.collisionLayer & n) === 0 || this.system.aabbOverlap(this, e) && (this._currentOverlaps.add(e), this.overlappingActors.has(e) || (this._currentSensorOverlaps.add({
624
+ actor: e,
617
625
  sensor: this,
618
- type: `${r.type}|${this.type}`
619
- }), this.onActorEnter(r))));
626
+ type: `${e.type}|${this.type}`
627
+ }), this.onActorEnter(e))));
620
628
  for (let e of this.overlappingActors) this._currentOverlaps.has(e) || this.onActorExit(e);
621
- let r = this.overlappingActors;
622
- return this.overlappingActors = this._currentOverlaps, this._currentOverlaps = r, this._currentOverlaps.clear(), this._currentSensorOverlaps;
629
+ let i = this.overlappingActors;
630
+ return this.overlappingActors = this._currentOverlaps, this._currentOverlaps = i, this._currentOverlaps.clear(), this._currentSensorOverlaps;
623
631
  }
624
632
  reset() {
625
633
  super.reset(), this._currentSensorOverlaps.clear(), this._currentOverlaps.clear(), this._isRidingSolidCache = null, this.velocity = {