@nonz250/ai-rotom 1.3.0 → 1.3.1

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.mjs CHANGED
@@ -538,12 +538,12 @@ var require_abilities = /* @__PURE__ */ __commonJSMin(((exports) => {
538
538
  },
539
539
  trys: [],
540
540
  ops: []
541
- }, f, y, t, g;
542
- return g = {
541
+ }, f, y, t, g = {
543
542
  next: verb(0),
544
543
  "throw": verb(1),
545
544
  "return": verb(2)
546
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
545
+ };
546
+ return typeof Symbol === "function" && (g[Symbol.iterator] = function() {
547
547
  return this;
548
548
  }), g;
549
549
  function verb(n) {
@@ -1282,12 +1282,12 @@ var require_items$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
1282
1282
  },
1283
1283
  trys: [],
1284
1284
  ops: []
1285
- }, f, y, t, g;
1286
- return g = {
1285
+ }, f, y, t, g = {
1287
1286
  next: verb(0),
1288
1287
  "throw": verb(1),
1289
1288
  "return": verb(2)
1290
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1289
+ };
1290
+ return typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1291
1291
  return this;
1292
1292
  }), g;
1293
1293
  function verb(n) {
@@ -2525,12 +2525,12 @@ var require_moves = /* @__PURE__ */ __commonJSMin(((exports) => {
2525
2525
  },
2526
2526
  trys: [],
2527
2527
  ops: []
2528
- }, f, y, t, g;
2529
- return g = {
2528
+ }, f, y, t, g = {
2530
2529
  next: verb(0),
2531
2530
  "throw": verb(1),
2532
2531
  "return": verb(2)
2533
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
2532
+ };
2533
+ return typeof Symbol === "function" && (g[Symbol.iterator] = function() {
2534
2534
  return this;
2535
2535
  }), g;
2536
2536
  function verb(n) {
@@ -10500,12 +10500,12 @@ var require_species = /* @__PURE__ */ __commonJSMin(((exports) => {
10500
10500
  },
10501
10501
  trys: [],
10502
10502
  ops: []
10503
- }, f, y, t, g;
10504
- return g = {
10503
+ }, f, y, t, g = {
10505
10504
  next: verb(0),
10506
10505
  "throw": verb(1),
10507
10506
  "return": verb(2)
10508
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
10507
+ };
10508
+ return typeof Symbol === "function" && (g[Symbol.iterator] = function() {
10509
10509
  return this;
10510
10510
  }), g;
10511
10511
  function verb(n) {
@@ -32078,12 +32078,12 @@ var require_types = /* @__PURE__ */ __commonJSMin(((exports) => {
32078
32078
  },
32079
32079
  trys: [],
32080
32080
  ops: []
32081
- }, f, y, t, g;
32082
- return g = {
32081
+ }, f, y, t, g = {
32083
32082
  next: verb(0),
32084
32083
  "throw": verb(1),
32085
32084
  "return": verb(2)
32086
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
32085
+ };
32086
+ return typeof Symbol === "function" && (g[Symbol.iterator] = function() {
32087
32087
  return this;
32088
32088
  }), g;
32089
32089
  function verb(n) {
@@ -32731,12 +32731,12 @@ var require_natures = /* @__PURE__ */ __commonJSMin(((exports) => {
32731
32731
  },
32732
32732
  trys: [],
32733
32733
  ops: []
32734
- }, f, y, t, g;
32735
- return g = {
32734
+ }, f, y, t, g = {
32736
32735
  next: verb(0),
32737
32736
  "throw": verb(1),
32738
32737
  "return": verb(2)
32739
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
32738
+ };
32739
+ return typeof Symbol === "function" && (g[Symbol.iterator] = function() {
32740
32740
  return this;
32741
32741
  }), g;
32742
32742
  function verb(n) {
@@ -77941,7 +77941,7 @@ var ASTKinds;
77941
77941
  ASTKinds["TERATYPE_LINE"] = "TERATYPE_LINE";
77942
77942
  ASTKinds["TERATYPE_VALUE"] = "TERATYPE_VALUE";
77943
77943
  ASTKinds["ABILITY_LINE"] = "ABILITY_LINE";
77944
- ASTKinds["ABILITY_LINE_$0"] = "ABILITY_LINE_$0";
77944
+ ASTKinds["PREVIOUS_ABILITY"] = "PREVIOUS_ABILITY";
77945
77945
  ASTKinds["ABILITY_VALUE"] = "ABILITY_VALUE";
77946
77946
  ASTKinds["NATURE_LINE"] = "NATURE_LINE";
77947
77947
  ASTKinds["NATURE_VALUE"] = "NATURE_VALUE";
@@ -78094,22 +78094,22 @@ var Parser = class {
78094
78094
  matchABILITY_LINE($$dpth, $$cr) {
78095
78095
  return this.run($$dpth, () => {
78096
78096
  let $scope$ability;
78097
- let $scope$preEvolution;
78097
+ let $scope$previousAbilities;
78098
78098
  let $$res = null;
78099
- if (this.regexAccept(String.raw`(?:特性)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?::)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && (($scope$ability = this.matchABILITY_VALUE($$dpth + 1, $$cr)) || true) && this.match_($$dpth + 1, $$cr) !== null && (($scope$preEvolution = this.matchABILITY_LINE_$0($$dpth + 1, $$cr)) || true)) $$res = {
78099
+ if (this.regexAccept(String.raw`(?:特性)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && this.regexAccept(String.raw`(?::)`, "", $$dpth + 1, $$cr) !== null && this.match_($$dpth + 1, $$cr) !== null && (($scope$ability = this.matchABILITY_VALUE($$dpth + 1, $$cr)) || true) && this.match_($$dpth + 1, $$cr) !== null && ($scope$previousAbilities = this.loop(() => this.matchPREVIOUS_ABILITY($$dpth + 1, $$cr), 0, -1)) !== null) $$res = {
78100
78100
  kind: ASTKinds.ABILITY_LINE,
78101
78101
  ability: $scope$ability,
78102
- preEvolution: $scope$preEvolution
78102
+ previousAbilities: $scope$previousAbilities
78103
78103
  };
78104
78104
  return $$res;
78105
78105
  });
78106
78106
  }
78107
- matchABILITY_LINE_$0($$dpth, $$cr) {
78107
+ matchPREVIOUS_ABILITY($$dpth, $$cr) {
78108
78108
  return this.run($$dpth, () => {
78109
78109
  let $scope$body;
78110
78110
  let $$res = null;
78111
- if (this.regexAccept(String.raw`(?:\()`, "", $$dpth + 1, $$cr) !== null && ($scope$body = this.matchABILITY_VALUE($$dpth + 1, $$cr)) !== null && this.regexAccept(String.raw`(?:\))`, "", $$dpth + 1, $$cr) !== null) $$res = {
78112
- kind: ASTKinds.ABILITY_LINE_$0,
78111
+ if (this.regexAccept(String.raw`(?:\()`, "", $$dpth + 1, $$cr) !== null && (($scope$body = this.matchABILITY_VALUE($$dpth + 1, $$cr)) || true) && this.regexAccept(String.raw`(?:\))`, "", $$dpth + 1, $$cr) !== null) $$res = {
78112
+ kind: ASTKinds.PREVIOUS_ABILITY,
78113
78113
  body: $scope$body
78114
78114
  };
78115
78115
  return $$res;
@@ -78449,7 +78449,9 @@ const parse = (pokesolText) => {
78449
78449
  const pokemonName = result.ast.line1.pokemon;
78450
78450
  const itemName = result.ast.line1.kind === ASTKinds.POKEMON_AND_ITEM_LINE ? result.ast.line1.item : null;
78451
78451
  const terastalName = result.ast.line2?.body.teratype || null;
78452
- const abilityNames = [result.ast.line3.ability, result.ast.line3.preEvolution?.body].filter((v) => v != null);
78452
+ const currentAbility = result.ast.line3.ability;
78453
+ const previousAbilities = result.ast.line3.previousAbilities.map(({ body }) => body);
78454
+ const abilityNames = previousAbilities.length > 0 ? [currentAbility, ...previousAbilities] : currentAbility !== null ? [currentAbility] : [];
78453
78455
  const natureName = result.ast.line4.nature || null;
78454
78456
  const evs = {
78455
78457
  hp: 0,
@@ -78525,8 +78527,8 @@ function splitPokesolTextBlocks(text) {
78525
78527
  }
78526
78528
  /**
78527
78529
  * パーサー出力 (`PokesolTextParseReult`) を `PartyMember` に変換する。
78528
- * - `abilityNames[1]` (メガ前特性) が存在すればそれを `ability` として保存
78529
- * (通常状態の特性が基本。メガ進化時の特性変化は計算側の責務)
78530
+ * - `abilityNames[1..]` (括弧内のメガ前特性) が存在すれば最も元の状態 (末尾) を
78531
+ * `ability` として保存 (通常状態の特性が基本。メガ進化時の特性変化は計算側の責務)
78530
78532
  * - `natureName` が null の場合は `DEFAULT_NATURE_NAME` で補完
78531
78533
  * - `terastalName` が存在する場合はポケチャン未対応のため無視
78532
78534
  * - `moveNames` が空配列の場合は `moves` フィールド自体を省く
@@ -78538,11 +78540,14 @@ function mapPokesolResultToPartyMember(result, blockNumber) {
78538
78540
  if (result.pokemonName === null || result.pokemonName === "") throw new Error(`ブロック ${blockNumber}: ポケモン名が読み取れませんでした。`);
78539
78541
  const member = { name: result.pokemonName };
78540
78542
  if (result.itemName !== null) member.item = result.itemName;
78541
- const [primaryAbility, preMegaAbility] = result.abilityNames;
78542
- if (preMegaAbility !== void 0) {
78543
- member.ability = preMegaAbility;
78544
- if (primaryAbility !== void 0 && primaryAbility !== preMegaAbility) warnings.push(`ブロック ${blockNumber}: メガ進化特性「${primaryAbility}」は無視し、メガ前特性「${preMegaAbility}」を ability として保存しました。`);
78545
- } else if (primaryAbility !== void 0) member.ability = primaryAbility;
78543
+ const { ability, ignoredAbilities } = selectAbility(result.abilityNames);
78544
+ if (ability !== void 0) {
78545
+ member.ability = ability;
78546
+ if (ignoredAbilities.length > 0) {
78547
+ const ignored = ignoredAbilities.map((name) => `「${name}」`).join("");
78548
+ warnings.push(`ブロック ${blockNumber}: メガ進化特性${ignored}は無視し、メガ前特性「${ability}」を ability として保存しました。`);
78549
+ }
78550
+ }
78546
78551
  if (result.natureName !== null) member.nature = result.natureName;
78547
78552
  else {
78548
78553
  member.nature = DEFAULT_NATURE_NAME;
@@ -78559,6 +78564,24 @@ function mapPokesolResultToPartyMember(result, blockNumber) {
78559
78564
  };
78560
78565
  }
78561
78566
  /**
78567
+ * パーサー出力の `abilityNames` から `PartyMember.ability` に保存する特性を選ぶ。
78568
+ * `abilityNames` は `[現在の特性, ...括弧内の以前の特性]` の順で、
78569
+ * 特性名が省略された位置 (`特性: (さめはだ)` の先頭など) は null になる。
78570
+ *
78571
+ * - 括弧内に特性があれば、最も元の状態である末尾の特性を採用する
78572
+ * - 括弧内が全て空なら現在の特性を採用する
78573
+ * - 採用しなかった特性 (重複を除く) は ignoredAbilities として返す
78574
+ */
78575
+ function selectAbility(abilityNames) {
78576
+ const names = abilityNames.filter((name) => name !== null);
78577
+ const [currentAbility, ...previousAbilities] = abilityNames;
78578
+ const ability = previousAbilities.filter((name) => name !== null).at(-1) ?? currentAbility ?? void 0;
78579
+ return {
78580
+ ability,
78581
+ ignoredAbilities: [...new Set(names)].filter((name) => name !== ability)
78582
+ };
78583
+ }
78584
+ /**
78562
78585
  * パーサー出力の SP (努力値フィールド) を `EvsInput` に変換する。
78563
78586
  * 全て 0 の場合は undefined を返し、`PartyMember.evs` を省く。
78564
78587
  */