@react-shimeji/core 0.3.1 → 0.3.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/dist/index.cjs +28 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +28 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1637,6 +1637,7 @@ function environmentRectangle(bounds) {
|
|
|
1637
1637
|
};
|
|
1638
1638
|
}
|
|
1639
1639
|
var PLATFORM_NEARBY_DISTANCE = 400;
|
|
1640
|
+
var PLATFORM_EDGE_TOLERANCE = 2;
|
|
1640
1641
|
function distanceToRectangle(point, rectangle) {
|
|
1641
1642
|
const dx = Math.max(rectangle.x - point.x, 0, point.x - rectangle.x - rectangle.width);
|
|
1642
1643
|
const dy = Math.max(rectangle.y - point.y, 0, point.y - rectangle.y - rectangle.height);
|
|
@@ -1756,7 +1757,7 @@ var Mascot = class {
|
|
|
1756
1757
|
if (result === "lost-ground") {
|
|
1757
1758
|
this.state.dragging = false;
|
|
1758
1759
|
this.actions.cancel();
|
|
1759
|
-
this.currentBehavior = this.
|
|
1760
|
+
this.currentBehavior = this.selectEdgeBehavior(bounds, platforms);
|
|
1760
1761
|
if (this.currentBehavior) this.startBehavior(this.createEnvironment(bounds, platforms), bounds, platforms);
|
|
1761
1762
|
} else if (result === "complete") {
|
|
1762
1763
|
this.currentBehavior = this.selectNextBehavior(this.createEnvironment(bounds, platforms), bounds);
|
|
@@ -1782,14 +1783,37 @@ var Mascot = class {
|
|
|
1782
1783
|
findFallBehavior() {
|
|
1783
1784
|
return this.behavior.force("Fall") ?? this.behavior.force("\u843D\u4E0B\u3059\u308B");
|
|
1784
1785
|
}
|
|
1785
|
-
selectNextBehavior(environment, bounds) {
|
|
1786
|
+
selectNextBehavior(environment, bounds, relocateOnFallback = true) {
|
|
1786
1787
|
const selected = this.behavior.selectNext(environment);
|
|
1787
|
-
if (this.behavior.usedFallback()) {
|
|
1788
|
+
if (relocateOnFallback && this.behavior.usedFallback()) {
|
|
1788
1789
|
this.state.x = Math.trunc(bounds.x + this.random() * bounds.width);
|
|
1789
1790
|
this.state.y = bounds.y - 256;
|
|
1790
1791
|
}
|
|
1791
1792
|
return selected;
|
|
1792
1793
|
}
|
|
1794
|
+
selectEdgeBehavior(bounds, platforms) {
|
|
1795
|
+
const original = { x: this.state.x, y: this.state.y };
|
|
1796
|
+
const platform = platforms.find((candidate) => candidate.element === this.activePlatformElement);
|
|
1797
|
+
if (platform) {
|
|
1798
|
+
const left = platform.x;
|
|
1799
|
+
const right = platform.x + platform.width;
|
|
1800
|
+
const top = platform.y;
|
|
1801
|
+
const bottom = platform.y + platform.height;
|
|
1802
|
+
if (Math.abs(this.state.y - top) <= PLATFORM_EDGE_TOLERANCE || Math.abs(this.state.y - bottom) <= PLATFORM_EDGE_TOLERANCE) {
|
|
1803
|
+
if (this.state.x < left) this.state.x = left;
|
|
1804
|
+
else if (this.state.x > right) this.state.x = right;
|
|
1805
|
+
} else if (Math.abs(this.state.x - left) <= PLATFORM_EDGE_TOLERANCE || Math.abs(this.state.x - right) <= PLATFORM_EDGE_TOLERANCE) {
|
|
1806
|
+
if (this.state.y < top) this.state.y = top;
|
|
1807
|
+
else if (this.state.y > bottom) this.state.y = bottom;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
const selected = this.selectNextBehavior(this.createEnvironment(bounds, platforms), bounds, false);
|
|
1811
|
+
if (this.behavior.usedFallback() || selected?.name === "Fall" || selected?.name === "\u843D\u4E0B\u3059\u308B") {
|
|
1812
|
+
this.state.x = original.x;
|
|
1813
|
+
this.state.y = original.y;
|
|
1814
|
+
}
|
|
1815
|
+
return selected ?? this.findFallBehavior();
|
|
1816
|
+
}
|
|
1793
1817
|
createEnvironment(bounds, platforms = this.platforms) {
|
|
1794
1818
|
const workArea = environmentRectangle(bounds);
|
|
1795
1819
|
const inactive = environmentRectangle({ x: -100, y: -100, width: 0, height: 0 });
|
|
@@ -1820,7 +1844,7 @@ var Mascot = class {
|
|
|
1820
1844
|
}
|
|
1821
1845
|
const anchor = this.state;
|
|
1822
1846
|
const current = platforms.find((platform) => platform.element === this.activePlatformElement);
|
|
1823
|
-
if (current && (isOnTop(anchor, current,
|
|
1847
|
+
if (current && (isOnTop(anchor, current, PLATFORM_EDGE_TOLERANCE) || isOnBottom(anchor, current, PLATFORM_EDGE_TOLERANCE) || isOnLeft(anchor, current, PLATFORM_EDGE_TOLERANCE) || isOnRight(anchor, current, PLATFORM_EDGE_TOLERANCE))) return current;
|
|
1824
1848
|
if (this.state.vy >= 0) {
|
|
1825
1849
|
const landingPlatform = platforms.filter((platform) => anchor.x >= platform.x && anchor.x <= platform.x + platform.width && platform.y >= anchor.y - 1).sort((left, right) => left.y - right.y)[0];
|
|
1826
1850
|
if (landingPlatform) {
|