@react-shimeji/core 0.3.5 → 0.3.7

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/index.cjs CHANGED
@@ -1647,9 +1647,6 @@ function environmentRectangle(bounds) {
1647
1647
  }
1648
1648
  var PLATFORM_NEARBY_DISTANCE = 400;
1649
1649
  var PLATFORM_EDGE_TOLERANCE = 2;
1650
- var MASCOT_HITBOX_MAX_WIDTH = 32;
1651
- var MASCOT_HITBOX_MAX_HEIGHT = 64;
1652
- var MASCOT_COLLISION_LOOKAHEAD = 4;
1653
1650
  var IE_BEHAVIOR_NAME_PATTERN = /wall|climb|crawl|壁|登|よじ/i;
1654
1651
  function isIEBehavior(behavior) {
1655
1652
  return behavior.conditions.some((condition) => /activeIE/i.test(condition)) || behavior.name.includes("IE") || behavior.name.includes("\uFF29\uFF25") || IE_BEHAVIOR_NAME_PATTERN.test(behavior.name) || behavior.actionName !== void 0 && (behavior.actionName.includes("IE") || behavior.actionName.includes("\uFF29\uFF25") || IE_BEHAVIOR_NAME_PATTERN.test(behavior.actionName));
@@ -1716,7 +1713,7 @@ var Mascot = class {
1716
1713
  random;
1717
1714
  forceInitialFall;
1718
1715
  /** Advances behavior, animation, physics, and rendering by one clock tick. */
1719
- tick(deltaMs, bounds, platforms = [], siblings = []) {
1716
+ tick(deltaMs, bounds, platforms = []) {
1720
1717
  if (this.destroyed) return;
1721
1718
  this.platforms = platforms;
1722
1719
  try {
@@ -1724,7 +1721,7 @@ var Mascot = class {
1724
1721
  this.accumulatedMs += Math.max(0, deltaMs);
1725
1722
  while (this.accumulatedMs >= this.frameDuration && !this.destroyed) {
1726
1723
  this.accumulatedMs -= this.frameDuration;
1727
- this.legacyTick(bounds, platforms, siblings);
1724
+ this.legacyTick(bounds, platforms);
1728
1725
  }
1729
1726
  } catch (error) {
1730
1727
  this.callbacks.error(error instanceof Error ? error : new Error(String(error)));
@@ -1737,24 +1734,6 @@ var Mascot = class {
1737
1734
  snapshot() {
1738
1735
  return { ...this.state };
1739
1736
  }
1740
- /** Returns the mascot's compact, feet-aligned behavioral collision box. */
1741
- collisionBox() {
1742
- const sprite = this.spec.sprites[this.state.sprite];
1743
- const spriteWidth = typeof sprite === "object" && sprite.width !== void 0 ? sprite.width : 128;
1744
- const spriteHeight = typeof sprite === "object" && sprite.height !== void 0 ? sprite.height : 128;
1745
- const width = Math.min(spriteWidth, MASCOT_HITBOX_MAX_WIDTH);
1746
- const height = Math.min(spriteHeight, MASCOT_HITBOX_MAX_HEIGHT);
1747
- const anchorX = this.state.lookRight ? spriteWidth - this.state.anchorX : this.state.anchorX;
1748
- const visualLeft = this.state.x - anchorX;
1749
- const visualTop = this.state.y - this.state.anchorY;
1750
- return {
1751
- id: this.id,
1752
- x: visualLeft + (spriteWidth - width) / 2,
1753
- y: visualTop + spriteHeight - height,
1754
- width,
1755
- height
1756
- };
1757
- }
1758
1737
  /** Removes listeners, DOM nodes, and object URLs owned by this mascot. */
1759
1738
  destroy() {
1760
1739
  if (this.destroyed) return;
@@ -1783,13 +1762,12 @@ var Mascot = class {
1783
1762
  if (!this.startBehavior(this.createEnvironment(bounds, platforms), bounds, platforms)) return;
1784
1763
  }
1785
1764
  }
1786
- legacyTick(bounds, platforms, siblings) {
1765
+ legacyTick(bounds, platforms) {
1787
1766
  this.ensureBehavior(bounds, platforms, false);
1788
1767
  if (!this.currentBehavior) return;
1789
1768
  const previous = { x: this.state.x, y: this.state.y };
1790
1769
  const result = this.actions.step(this.createEnvironment(bounds, platforms), bounds, platforms);
1791
1770
  if (this.destroyed) return;
1792
- this.avoidSiblingCollision(previous, bounds, platforms, siblings);
1793
1771
  if (result === "lost-ground") {
1794
1772
  this.state.dragging = false;
1795
1773
  this.actions.cancel();
@@ -1807,32 +1785,6 @@ var Mascot = class {
1807
1785
  if (this.currentBehavior) this.startBehavior(this.createEnvironment(bounds, platforms), bounds, platforms);
1808
1786
  }
1809
1787
  }
1810
- avoidSiblingCollision(previous, bounds, platforms, siblings) {
1811
- const dx = this.state.x - previous.x;
1812
- if (this.state.dragging || dx === 0 || this.state.y !== previous.y) return;
1813
- const onHorizontalSurface = isOnFloor(previous, bounds, platforms) || isOnTop(previous, bounds) || platforms.some((platform) => isOnBottom(previous, platform));
1814
- if (!onHorizontalSurface) return;
1815
- const currentBox = this.collisionBox();
1816
- const offsetX = currentBox.x - this.state.x;
1817
- const previousBox = { ...currentBox, x: previous.x + offsetX };
1818
- const movingRight = dx > 0;
1819
- const sweptLeft = Math.min(previousBox.x, currentBox.x) - (movingRight ? 0 : MASCOT_COLLISION_LOOKAHEAD);
1820
- const sweptRight = Math.max(previousBox.x + previousBox.width, currentBox.x + currentBox.width) + (movingRight ? MASCOT_COLLISION_LOOKAHEAD : 0);
1821
- const previousCenterX = previousBox.x + previousBox.width / 2;
1822
- const collision = siblings.some((sibling) => {
1823
- if (sibling.id === this.id) return false;
1824
- const siblingCenterX = sibling.x + sibling.width / 2;
1825
- const isAhead = movingRight ? siblingCenterX >= previousCenterX : siblingCenterX <= previousCenterX;
1826
- const overlapsVertically = currentBox.y < sibling.y + sibling.height && sibling.y < currentBox.y + currentBox.height;
1827
- const crossesHorizontally = sweptLeft <= sibling.x + sibling.width && sibling.x <= sweptRight;
1828
- const wasAlreadyOverlapping = overlapsVertically && previousBox.x < sibling.x + sibling.width && sibling.x < previousBox.x + previousBox.width;
1829
- return isAhead && overlapsVertically && crossesHorizontally && !wasAlreadyOverlapping;
1830
- });
1831
- if (!collision) return;
1832
- this.state.x = previous.x;
1833
- this.state.vx = 0;
1834
- this.state.lookRight = !this.state.lookRight;
1835
- }
1836
1788
  isOutsideVisibleBounds(bounds) {
1837
1789
  const sprite = this.spec.sprites[this.state.sprite];
1838
1790
  const width = typeof sprite === "object" && "width" in sprite && sprite.width !== void 0 ? sprite.width : 128;
@@ -2255,8 +2207,7 @@ var ShimejiEngine = class {
2255
2207
  const delta = Math.max(0, Math.min(rawDelta, this.options.maxDeltaTime));
2256
2208
  const { bounds, platforms } = this.readFrameGeometry();
2257
2209
  const mascots = [...this.mascots.values()];
2258
- const collisionBoxes = mascots.map((mascot) => mascot.collisionBox());
2259
- for (const mascot of mascots) mascot.tick(delta, bounds, platforms, collisionBoxes);
2210
+ for (const mascot of mascots) mascot.tick(delta, bounds, platforms);
2260
2211
  this.emitState();
2261
2212
  this.animationFrame = this.container.ownerDocument.defaultView?.requestAnimationFrame(this.onAnimationFrame);
2262
2213
  };