@react-shimeji/core 0.3.6 → 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,25 +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
- positionX: this.state.x,
1706
- x: visualLeft + (spriteWidth - width) / 2,
1707
- y: visualTop + spriteHeight - height,
1708
- width,
1709
- height
1710
- };
1711
- }
1712
1690
  /** Removes listeners, DOM nodes, and object URLs owned by this mascot. */
1713
1691
  destroy() {
1714
1692
  if (this.destroyed) return;
@@ -1737,13 +1715,12 @@ var Mascot = class {
1737
1715
  if (!this.startBehavior(this.createEnvironment(bounds, platforms), bounds, platforms)) return;
1738
1716
  }
1739
1717
  }
1740
- legacyTick(bounds, platforms, siblings) {
1718
+ legacyTick(bounds, platforms) {
1741
1719
  this.ensureBehavior(bounds, platforms, false);
1742
1720
  if (!this.currentBehavior) return;
1743
1721
  const previous = { x: this.state.x, y: this.state.y };
1744
1722
  const result = this.actions.step(this.createEnvironment(bounds, platforms), bounds, platforms);
1745
1723
  if (this.destroyed) return;
1746
- this.avoidSiblingCollision(previous, bounds, platforms, siblings);
1747
1724
  if (result === "lost-ground") {
1748
1725
  this.state.dragging = false;
1749
1726
  this.actions.cancel();
@@ -1761,48 +1738,6 @@ var Mascot = class {
1761
1738
  if (this.currentBehavior) this.startBehavior(this.createEnvironment(bounds, platforms), bounds, platforms);
1762
1739
  }
1763
1740
  }
1764
- avoidSiblingCollision(previous, bounds, platforms, siblings) {
1765
- const dx = this.state.x - previous.x;
1766
- if (this.state.dragging || dx === 0 || this.state.y !== previous.y) return;
1767
- const onHorizontalSurface = isOnFloor(previous, bounds, platforms) || isOnTop(previous, bounds) || platforms.some((platform) => isOnBottom(previous, platform));
1768
- if (!onHorizontalSurface) return;
1769
- const currentBox = this.collisionBox();
1770
- const offsetX = currentBox.x - this.state.x;
1771
- const previousBox = { ...currentBox, x: previous.x + offsetX };
1772
- const movingRight = dx > 0;
1773
- const sweptLeft = Math.min(previousBox.x, currentBox.x) - (movingRight ? 0 : MASCOT_COLLISION_LOOKAHEAD);
1774
- const sweptRight = Math.max(previousBox.x + previousBox.width, currentBox.x + currentBox.width) + (movingRight ? MASCOT_COLLISION_LOOKAHEAD : 0);
1775
- const overlappingSiblings = siblings.filter((sibling) => {
1776
- if (sibling.id === this.id) return false;
1777
- const overlapsVertically = currentBox.y < sibling.y + sibling.height && sibling.y < currentBox.y + currentBox.height;
1778
- const overlapsHorizontally = previousBox.x < sibling.x + sibling.width && sibling.x < previousBox.x + previousBox.width;
1779
- return overlapsVertically && (overlapsHorizontally || sibling.positionX === previous.x);
1780
- });
1781
- if (overlappingSiblings.length > 0) {
1782
- const coincidentIds = [
1783
- this.id,
1784
- ...overlappingSiblings.filter((sibling) => sibling.positionX === previous.x).map((sibling) => sibling.id)
1785
- ].sort();
1786
- const escapeRight = coincidentIds.length > 1 ? coincidentIds.indexOf(this.id) >= coincidentIds.length / 2 : overlappingSiblings.reduce((sum, sibling) => sum + sibling.positionX, 0) / overlappingSiblings.length < previous.x;
1787
- if (movingRight !== escapeRight) {
1788
- this.state.x = previous.x;
1789
- this.state.vx = 0;
1790
- this.state.lookRight = !this.state.lookRight;
1791
- }
1792
- return;
1793
- }
1794
- const collision = siblings.some((sibling) => {
1795
- if (sibling.id === this.id) return false;
1796
- const isAhead = movingRight ? sibling.positionX > previous.x : sibling.positionX < previous.x;
1797
- const overlapsVertically = currentBox.y < sibling.y + sibling.height && sibling.y < currentBox.y + currentBox.height;
1798
- const crossesHorizontally = sweptLeft <= sibling.x + sibling.width && sibling.x <= sweptRight;
1799
- return isAhead && overlapsVertically && crossesHorizontally;
1800
- });
1801
- if (!collision) return;
1802
- this.state.x = previous.x;
1803
- this.state.vx = 0;
1804
- this.state.lookRight = !this.state.lookRight;
1805
- }
1806
1741
  isOutsideVisibleBounds(bounds) {
1807
1742
  const sprite = this.spec.sprites[this.state.sprite];
1808
1743
  const width = typeof sprite === "object" && "width" in sprite && sprite.width !== void 0 ? sprite.width : 128;
@@ -2225,8 +2160,7 @@ var ShimejiEngine = class {
2225
2160
  const delta = Math.max(0, Math.min(rawDelta, this.options.maxDeltaTime));
2226
2161
  const { bounds, platforms } = this.readFrameGeometry();
2227
2162
  const mascots = [...this.mascots.values()];
2228
- const collisionBoxes = mascots.map((mascot) => mascot.collisionBox());
2229
- for (const mascot of mascots) mascot.tick(delta, bounds, platforms, collisionBoxes);
2163
+ for (const mascot of mascots) mascot.tick(delta, bounds, platforms);
2230
2164
  this.emitState();
2231
2165
  this.animationFrame = this.container.ownerDocument.defaultView?.requestAnimationFrame(this.onAnimationFrame);
2232
2166
  };