@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.d.cts CHANGED
@@ -422,11 +422,14 @@ declare class BehaviorController {
422
422
  selectInitial(environment: MascotEnvironment, requestedName?: string): BehaviorDefinition | undefined;
423
423
  /** Selects the weighted transition following the current behavior. */
424
424
  selectNext(environment: MascotEnvironment): BehaviorDefinition | undefined;
425
+ /** Tries a weighted transition from a subset without changing history when none applies. */
426
+ trySelectNext(environment: MascotEnvironment, predicate: (behavior: BehaviorDefinition) => boolean): BehaviorDefinition | undefined;
425
427
  /** Whether the most recent transition had no effective weighted candidate. */
426
428
  usedFallback(): boolean;
427
429
  /** Replaces selection history so an external interaction can force a behavior. */
428
430
  force(name: string): BehaviorDefinition | undefined;
429
431
  private choose;
432
+ private nextPool;
430
433
  private resolve;
431
434
  private findFallBehavior;
432
435
  }
package/dist/index.d.ts CHANGED
@@ -422,11 +422,14 @@ declare class BehaviorController {
422
422
  selectInitial(environment: MascotEnvironment, requestedName?: string): BehaviorDefinition | undefined;
423
423
  /** Selects the weighted transition following the current behavior. */
424
424
  selectNext(environment: MascotEnvironment): BehaviorDefinition | undefined;
425
+ /** Tries a weighted transition from a subset without changing history when none applies. */
426
+ trySelectNext(environment: MascotEnvironment, predicate: (behavior: BehaviorDefinition) => boolean): BehaviorDefinition | undefined;
425
427
  /** Whether the most recent transition had no effective weighted candidate. */
426
428
  usedFallback(): boolean;
427
429
  /** Replaces selection history so an external interaction can force a behavior. */
428
430
  force(name: string): BehaviorDefinition | undefined;
429
431
  private choose;
432
+ private nextPool;
430
433
  private resolve;
431
434
  private findFallBehavior;
432
435
  }
package/dist/index.js CHANGED
@@ -615,12 +615,17 @@ var BehaviorController = class {
615
615
  }
616
616
  /** Selects the weighted transition following the current behavior. */
617
617
  selectNext(environment) {
618
- const next = this.previous?.nextBehaviors ?? [];
619
- const pool = this.previous && this.previous.nextAdditive === false ? next : [...this.spec.behaviors, ...next];
620
- const selected = this.choose(pool, environment);
618
+ const selected = this.choose(this.nextPool(), environment);
621
619
  this.fallbackSelected = selected === void 0;
622
620
  return this.previous = selected ?? this.findFallBehavior();
623
621
  }
622
+ /** Tries a weighted transition from a subset without changing history when none applies. */
623
+ trySelectNext(environment, predicate) {
624
+ const selected = this.choose(this.nextPool().filter(predicate), environment);
625
+ if (!selected) return void 0;
626
+ this.fallbackSelected = false;
627
+ return this.previous = selected;
628
+ }
624
629
  /** Whether the most recent transition had no effective weighted candidate. */
625
630
  usedFallback() {
626
631
  return this.fallbackSelected;
@@ -636,6 +641,10 @@ var BehaviorController = class {
636
641
  const chosen = selectWeighted(applicable, (behavior) => behavior.frequency, this.random);
637
642
  return chosen ? this.resolve(chosen) : void 0;
638
643
  }
644
+ nextPool() {
645
+ const next = this.previous?.nextBehaviors ?? [];
646
+ return this.previous && this.previous.nextAdditive === false ? next : [...this.spec.behaviors, ...next];
647
+ }
639
648
  resolve(behavior) {
640
649
  if (behavior.type !== "Reference") return behavior;
641
650
  const target = this.spec.behaviors.find((candidate) => candidate.type === "Behavior" && candidate.name === behavior.name);
@@ -1591,6 +1600,10 @@ function environmentRectangle(bounds) {
1591
1600
  }
1592
1601
  var PLATFORM_NEARBY_DISTANCE = 400;
1593
1602
  var PLATFORM_EDGE_TOLERANCE = 2;
1603
+ var IE_BEHAVIOR_NAME_PATTERN = /wall|climb|crawl|壁|登|よじ/i;
1604
+ function isIEBehavior(behavior) {
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));
1606
+ }
1594
1607
  function distanceToRectangle(point, rectangle) {
1595
1608
  const dx = Math.max(rectangle.x - point.x, 0, point.x - rectangle.x - rectangle.width);
1596
1609
  const dy = Math.max(rectangle.y - point.y, 0, point.y - rectangle.y - rectangle.height);
@@ -1760,7 +1773,9 @@ var Mascot = class {
1760
1773
  else if (this.state.y > bottom) this.state.y = bottom;
1761
1774
  }
1762
1775
  }
1763
- const selected = this.selectNextBehavior(this.createEnvironment(bounds, platforms), bounds, false);
1776
+ const environment = this.createEnvironment(bounds, platforms);
1777
+ const interruptedBehavior = this.currentBehavior;
1778
+ const selected = this.behavior.trySelectNext(environment, (candidate) => candidate.name !== interruptedBehavior?.name && isIEBehavior(candidate)) ?? this.selectNextBehavior(environment, bounds, false);
1764
1779
  if (this.behavior.usedFallback() || selected?.name === "Fall" || selected?.name === "\u843D\u4E0B\u3059\u308B") {
1765
1780
  this.state.x = original.x;
1766
1781
  this.state.y = original.y;