@react-shimeji/core 0.3.2 → 0.3.3

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
@@ -662,12 +662,17 @@ var BehaviorController = class {
662
662
  }
663
663
  /** Selects the weighted transition following the current behavior. */
664
664
  selectNext(environment) {
665
- const next = this.previous?.nextBehaviors ?? [];
666
- const pool = this.previous && this.previous.nextAdditive === false ? next : [...this.spec.behaviors, ...next];
667
- const selected = this.choose(pool, environment);
665
+ const selected = this.choose(this.nextPool(), environment);
668
666
  this.fallbackSelected = selected === void 0;
669
667
  return this.previous = selected ?? this.findFallBehavior();
670
668
  }
669
+ /** Tries a weighted transition from a subset without changing history when none applies. */
670
+ trySelectNext(environment, predicate) {
671
+ const selected = this.choose(this.nextPool().filter(predicate), environment);
672
+ if (!selected) return void 0;
673
+ this.fallbackSelected = false;
674
+ return this.previous = selected;
675
+ }
671
676
  /** Whether the most recent transition had no effective weighted candidate. */
672
677
  usedFallback() {
673
678
  return this.fallbackSelected;
@@ -683,6 +688,10 @@ var BehaviorController = class {
683
688
  const chosen = selectWeighted(applicable, (behavior) => behavior.frequency, this.random);
684
689
  return chosen ? this.resolve(chosen) : void 0;
685
690
  }
691
+ nextPool() {
692
+ const next = this.previous?.nextBehaviors ?? [];
693
+ return this.previous && this.previous.nextAdditive === false ? next : [...this.spec.behaviors, ...next];
694
+ }
686
695
  resolve(behavior) {
687
696
  if (behavior.type !== "Reference") return behavior;
688
697
  const target = this.spec.behaviors.find((candidate) => candidate.type === "Behavior" && candidate.name === behavior.name);
@@ -1638,6 +1647,10 @@ function environmentRectangle(bounds) {
1638
1647
  }
1639
1648
  var PLATFORM_NEARBY_DISTANCE = 400;
1640
1649
  var PLATFORM_EDGE_TOLERANCE = 2;
1650
+ var IE_BEHAVIOR_NAME_PATTERN = /wall|climb|crawl|壁|登|よじ/i;
1651
+ function isIEBehavior(behavior) {
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));
1653
+ }
1641
1654
  function distanceToRectangle(point, rectangle) {
1642
1655
  const dx = Math.max(rectangle.x - point.x, 0, point.x - rectangle.x - rectangle.width);
1643
1656
  const dy = Math.max(rectangle.y - point.y, 0, point.y - rectangle.y - rectangle.height);
@@ -1807,7 +1820,9 @@ var Mascot = class {
1807
1820
  else if (this.state.y > bottom) this.state.y = bottom;
1808
1821
  }
1809
1822
  }
1810
- const selected = this.selectNextBehavior(this.createEnvironment(bounds, platforms), bounds, false);
1823
+ const environment = this.createEnvironment(bounds, platforms);
1824
+ const interruptedBehavior = this.currentBehavior;
1825
+ const selected = this.behavior.trySelectNext(environment, (candidate) => candidate.name !== interruptedBehavior?.name && isIEBehavior(candidate)) ?? this.selectNextBehavior(environment, bounds, false);
1811
1826
  if (this.behavior.usedFallback() || selected?.name === "Fall" || selected?.name === "\u843D\u4E0B\u3059\u308B") {
1812
1827
  this.state.x = original.x;
1813
1828
  this.state.y = original.y;