@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.js CHANGED
@@ -1600,9 +1600,6 @@ function environmentRectangle(bounds) {
1600
1600
  }
1601
1601
  var PLATFORM_NEARBY_DISTANCE = 400;
1602
1602
  var PLATFORM_EDGE_TOLERANCE = 2;
1603
- var MASCOT_HITBOX_MAX_WIDTH = 32;
1604
- var MASCOT_HITBOX_MAX_HEIGHT = 64;
1605
- var MASCOT_COLLISION_LOOKAHEAD = 4;
1606
1603
  var IE_BEHAVIOR_NAME_PATTERN = /wall|climb|crawl|壁|登|よじ/i;
1607
1604
  function isIEBehavior(behavior) {
1608
1605
  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));
@@ -1669,7 +1666,7 @@ var Mascot = class {
1669
1666
  random;
1670
1667
  forceInitialFall;
1671
1668
  /** Advances behavior, animation, physics, and rendering by one clock tick. */
1672
- tick(deltaMs, bounds, platforms = [], siblings = []) {
1669
+ tick(deltaMs, bounds, platforms = []) {
1673
1670
  if (this.destroyed) return;
1674
1671
  this.platforms = platforms;
1675
1672
  try {
@@ -1677,7 +1674,7 @@ var Mascot = class {
1677
1674
  this.accumulatedMs += Math.max(0, deltaMs);
1678
1675
  while (this.accumulatedMs >= this.frameDuration && !this.destroyed) {
1679
1676
  this.accumulatedMs -= this.frameDuration;
1680
- this.legacyTick(bounds, platforms, siblings);
1677
+ this.legacyTick(bounds, platforms);
1681
1678
  }
1682
1679
  } catch (error) {
1683
1680
  this.callbacks.error(error instanceof Error ? error : new Error(String(error)));
@@ -1690,24 +1687,6 @@ var Mascot = class {
1690
1687
  snapshot() {
1691
1688
  return { ...this.state };
1692
1689
  }
1693
- /** Returns the mascot's compact, feet-aligned behavioral collision box. */
1694
- collisionBox() {
1695
- const sprite = this.spec.sprites[this.state.sprite];
1696
- const spriteWidth = typeof sprite === "object" && sprite.width !== void 0 ? sprite.width : 128;
1697
- const spriteHeight = typeof sprite === "object" && sprite.height !== void 0 ? sprite.height : 128;
1698
- const width = Math.min(spriteWidth, MASCOT_HITBOX_MAX_WIDTH);
1699
- const height = Math.min(spriteHeight, MASCOT_HITBOX_MAX_HEIGHT);
1700
- const anchorX = this.state.lookRight ? spriteWidth - this.state.anchorX : this.state.anchorX;
1701
- const visualLeft = this.state.x - anchorX;
1702
- const visualTop = this.state.y - this.state.anchorY;
1703
- return {
1704
- id: this.id,
1705
- x: visualLeft + (spriteWidth - width) / 2,
1706
- y: visualTop + spriteHeight - height,
1707
- width,
1708
- height
1709
- };
1710
- }
1711
1690
  /** Removes listeners, DOM nodes, and object URLs owned by this mascot. */
1712
1691
  destroy() {
1713
1692
  if (this.destroyed) return;
@@ -1736,13 +1715,12 @@ var Mascot = class {
1736
1715
  if (!this.startBehavior(this.createEnvironment(bounds, platforms), bounds, platforms)) return;
1737
1716
  }
1738
1717
  }
1739
- legacyTick(bounds, platforms, siblings) {
1718
+ legacyTick(bounds, platforms) {
1740
1719
  this.ensureBehavior(bounds, platforms, false);
1741
1720
  if (!this.currentBehavior) return;
1742
1721
  const previous = { x: this.state.x, y: this.state.y };
1743
1722
  const result = this.actions.step(this.createEnvironment(bounds, platforms), bounds, platforms);
1744
1723
  if (this.destroyed) return;
1745
- this.avoidSiblingCollision(previous, bounds, platforms, siblings);
1746
1724
  if (result === "lost-ground") {
1747
1725
  this.state.dragging = false;
1748
1726
  this.actions.cancel();
@@ -1760,32 +1738,6 @@ var Mascot = class {
1760
1738
  if (this.currentBehavior) this.startBehavior(this.createEnvironment(bounds, platforms), bounds, platforms);
1761
1739
  }
1762
1740
  }
1763
- avoidSiblingCollision(previous, bounds, platforms, siblings) {
1764
- const dx = this.state.x - previous.x;
1765
- if (this.state.dragging || dx === 0 || this.state.y !== previous.y) return;
1766
- const onHorizontalSurface = isOnFloor(previous, bounds, platforms) || isOnTop(previous, bounds) || platforms.some((platform) => isOnBottom(previous, platform));
1767
- if (!onHorizontalSurface) return;
1768
- const currentBox = this.collisionBox();
1769
- const offsetX = currentBox.x - this.state.x;
1770
- const previousBox = { ...currentBox, x: previous.x + offsetX };
1771
- const movingRight = dx > 0;
1772
- const sweptLeft = Math.min(previousBox.x, currentBox.x) - (movingRight ? 0 : MASCOT_COLLISION_LOOKAHEAD);
1773
- const sweptRight = Math.max(previousBox.x + previousBox.width, currentBox.x + currentBox.width) + (movingRight ? MASCOT_COLLISION_LOOKAHEAD : 0);
1774
- const previousCenterX = previousBox.x + previousBox.width / 2;
1775
- const collision = siblings.some((sibling) => {
1776
- if (sibling.id === this.id) return false;
1777
- const siblingCenterX = sibling.x + sibling.width / 2;
1778
- const isAhead = movingRight ? siblingCenterX >= previousCenterX : siblingCenterX <= previousCenterX;
1779
- const overlapsVertically = currentBox.y < sibling.y + sibling.height && sibling.y < currentBox.y + currentBox.height;
1780
- const crossesHorizontally = sweptLeft <= sibling.x + sibling.width && sibling.x <= sweptRight;
1781
- const wasAlreadyOverlapping = overlapsVertically && previousBox.x < sibling.x + sibling.width && sibling.x < previousBox.x + previousBox.width;
1782
- return isAhead && overlapsVertically && crossesHorizontally && !wasAlreadyOverlapping;
1783
- });
1784
- if (!collision) return;
1785
- this.state.x = previous.x;
1786
- this.state.vx = 0;
1787
- this.state.lookRight = !this.state.lookRight;
1788
- }
1789
1741
  isOutsideVisibleBounds(bounds) {
1790
1742
  const sprite = this.spec.sprites[this.state.sprite];
1791
1743
  const width = typeof sprite === "object" && "width" in sprite && sprite.width !== void 0 ? sprite.width : 128;
@@ -2208,8 +2160,7 @@ var ShimejiEngine = class {
2208
2160
  const delta = Math.max(0, Math.min(rawDelta, this.options.maxDeltaTime));
2209
2161
  const { bounds, platforms } = this.readFrameGeometry();
2210
2162
  const mascots = [...this.mascots.values()];
2211
- const collisionBoxes = mascots.map((mascot) => mascot.collisionBox());
2212
- for (const mascot of mascots) mascot.tick(delta, bounds, platforms, collisionBoxes);
2163
+ for (const mascot of mascots) mascot.tick(delta, bounds, platforms);
2213
2164
  this.emitState();
2214
2165
  this.animationFrame = this.container.ownerDocument.defaultView?.requestAnimationFrame(this.onAnimationFrame);
2215
2166
  };