@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.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,25 +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
- positionX: this.state.x,
1753
- x: visualLeft + (spriteWidth - width) / 2,
1754
- y: visualTop + spriteHeight - height,
1755
- width,
1756
- height
1757
- };
1758
- }
1759
1737
  /** Removes listeners, DOM nodes, and object URLs owned by this mascot. */
1760
1738
  destroy() {
1761
1739
  if (this.destroyed) return;
@@ -1784,13 +1762,12 @@ var Mascot = class {
1784
1762
  if (!this.startBehavior(this.createEnvironment(bounds, platforms), bounds, platforms)) return;
1785
1763
  }
1786
1764
  }
1787
- legacyTick(bounds, platforms, siblings) {
1765
+ legacyTick(bounds, platforms) {
1788
1766
  this.ensureBehavior(bounds, platforms, false);
1789
1767
  if (!this.currentBehavior) return;
1790
1768
  const previous = { x: this.state.x, y: this.state.y };
1791
1769
  const result = this.actions.step(this.createEnvironment(bounds, platforms), bounds, platforms);
1792
1770
  if (this.destroyed) return;
1793
- this.avoidSiblingCollision(previous, bounds, platforms, siblings);
1794
1771
  if (result === "lost-ground") {
1795
1772
  this.state.dragging = false;
1796
1773
  this.actions.cancel();
@@ -1808,48 +1785,6 @@ var Mascot = class {
1808
1785
  if (this.currentBehavior) this.startBehavior(this.createEnvironment(bounds, platforms), bounds, platforms);
1809
1786
  }
1810
1787
  }
1811
- avoidSiblingCollision(previous, bounds, platforms, siblings) {
1812
- const dx = this.state.x - previous.x;
1813
- if (this.state.dragging || dx === 0 || this.state.y !== previous.y) return;
1814
- const onHorizontalSurface = isOnFloor(previous, bounds, platforms) || isOnTop(previous, bounds) || platforms.some((platform) => isOnBottom(previous, platform));
1815
- if (!onHorizontalSurface) return;
1816
- const currentBox = this.collisionBox();
1817
- const offsetX = currentBox.x - this.state.x;
1818
- const previousBox = { ...currentBox, x: previous.x + offsetX };
1819
- const movingRight = dx > 0;
1820
- const sweptLeft = Math.min(previousBox.x, currentBox.x) - (movingRight ? 0 : MASCOT_COLLISION_LOOKAHEAD);
1821
- const sweptRight = Math.max(previousBox.x + previousBox.width, currentBox.x + currentBox.width) + (movingRight ? MASCOT_COLLISION_LOOKAHEAD : 0);
1822
- const overlappingSiblings = siblings.filter((sibling) => {
1823
- if (sibling.id === this.id) return false;
1824
- const overlapsVertically = currentBox.y < sibling.y + sibling.height && sibling.y < currentBox.y + currentBox.height;
1825
- const overlapsHorizontally = previousBox.x < sibling.x + sibling.width && sibling.x < previousBox.x + previousBox.width;
1826
- return overlapsVertically && (overlapsHorizontally || sibling.positionX === previous.x);
1827
- });
1828
- if (overlappingSiblings.length > 0) {
1829
- const coincidentIds = [
1830
- this.id,
1831
- ...overlappingSiblings.filter((sibling) => sibling.positionX === previous.x).map((sibling) => sibling.id)
1832
- ].sort();
1833
- const escapeRight = coincidentIds.length > 1 ? coincidentIds.indexOf(this.id) >= coincidentIds.length / 2 : overlappingSiblings.reduce((sum, sibling) => sum + sibling.positionX, 0) / overlappingSiblings.length < previous.x;
1834
- if (movingRight !== escapeRight) {
1835
- this.state.x = previous.x;
1836
- this.state.vx = 0;
1837
- this.state.lookRight = !this.state.lookRight;
1838
- }
1839
- return;
1840
- }
1841
- const collision = siblings.some((sibling) => {
1842
- if (sibling.id === this.id) return false;
1843
- const isAhead = movingRight ? sibling.positionX > previous.x : sibling.positionX < previous.x;
1844
- const overlapsVertically = currentBox.y < sibling.y + sibling.height && sibling.y < currentBox.y + currentBox.height;
1845
- const crossesHorizontally = sweptLeft <= sibling.x + sibling.width && sibling.x <= sweptRight;
1846
- return isAhead && overlapsVertically && crossesHorizontally;
1847
- });
1848
- if (!collision) return;
1849
- this.state.x = previous.x;
1850
- this.state.vx = 0;
1851
- this.state.lookRight = !this.state.lookRight;
1852
- }
1853
1788
  isOutsideVisibleBounds(bounds) {
1854
1789
  const sprite = this.spec.sprites[this.state.sprite];
1855
1790
  const width = typeof sprite === "object" && "width" in sprite && sprite.width !== void 0 ? sprite.width : 128;
@@ -2272,8 +2207,7 @@ var ShimejiEngine = class {
2272
2207
  const delta = Math.max(0, Math.min(rawDelta, this.options.maxDeltaTime));
2273
2208
  const { bounds, platforms } = this.readFrameGeometry();
2274
2209
  const mascots = [...this.mascots.values()];
2275
- const collisionBoxes = mascots.map((mascot) => mascot.collisionBox());
2276
- for (const mascot of mascots) mascot.tick(delta, bounds, platforms, collisionBoxes);
2210
+ for (const mascot of mascots) mascot.tick(delta, bounds, platforms);
2277
2211
  this.emitState();
2278
2212
  this.animationFrame = this.container.ownerDocument.defaultView?.requestAnimationFrame(this.onAnimationFrame);
2279
2213
  };