koishipro-core.js 1.0.8 → 1.0.10

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
@@ -55,6 +55,7 @@ __export(index_exports, {
55
55
  parseRegistryDump: () => parseRegistryDump,
56
56
  parseRegistryKeys: () => parseRegistryKeys,
57
57
  playYrp: () => playYrp,
58
+ playYrpStep: () => playYrpStep,
58
59
  testCard: () => testCard
59
60
  });
60
61
  module.exports = __toCommonJS(index_exports);
@@ -1256,50 +1257,38 @@ function normalizeOcgcoreFactory(mod) {
1256
1257
  throw new Error("Invalid ocgcore factory module");
1257
1258
  }
1258
1259
 
1259
- // src/utility/node-fs.ts
1260
- function getNodeFs(noThrow = false) {
1261
- const req = typeof require !== "undefined" && require || Function('return typeof require !== "undefined" && require')();
1260
+ // src/utility/load-node-module.ts
1261
+ function loadNodeModule(id, altId) {
1262
+ const req = typeof module.require !== "undefined" ? module.require : void 0;
1262
1263
  if (!req) {
1263
- if (noThrow) {
1264
- return null;
1265
- }
1266
- throw new Error("Node.js fs module is not available.");
1264
+ return null;
1267
1265
  }
1268
1266
  try {
1269
- return req("node:fs");
1267
+ return req(id);
1270
1268
  } catch {
1269
+ if (!altId) return null;
1271
1270
  try {
1272
- return req("fs");
1271
+ return req(altId);
1273
1272
  } catch {
1274
- if (noThrow) {
1275
- return null;
1276
- }
1277
- throw new Error("Node.js fs module is not available.");
1273
+ return null;
1278
1274
  }
1279
1275
  }
1280
1276
  }
1281
1277
 
1278
+ // src/utility/node-fs.ts
1279
+ function getNodeFs(noThrow = false) {
1280
+ const mod = loadNodeModule("node:fs", "fs");
1281
+ if (mod) return mod;
1282
+ if (noThrow) return null;
1283
+ throw new Error("Node.js fs module is not available.");
1284
+ }
1285
+
1282
1286
  // src/utility/node-path.ts
1283
1287
  function getNodePath(noThrow = false) {
1284
- const req = typeof require !== "undefined" && require || Function('return typeof require !== "undefined" && require')();
1285
- if (!req) {
1286
- if (noThrow) {
1287
- return null;
1288
- }
1289
- throw new Error("Node.js path module is not available.");
1290
- }
1291
- try {
1292
- return req("node:path");
1293
- } catch {
1294
- try {
1295
- return req("path");
1296
- } catch {
1297
- if (noThrow) {
1298
- return null;
1299
- }
1300
- throw new Error("Node.js path module is not available.");
1301
- }
1302
- }
1288
+ const mod = loadNodeModule("node:path", "path");
1289
+ if (mod) return mod;
1290
+ if (noThrow) return null;
1291
+ throw new Error("Node.js path module is not available.");
1303
1292
  }
1304
1293
 
1305
1294
  // src/load-ocgcore-factory.cjs.ts
@@ -2453,9 +2442,8 @@ function loadTagDeck(duel, deck, owner) {
2453
2442
  function setRegistryValue(duel, key, value) {
2454
2443
  duel.setRegistryValue(key, value);
2455
2444
  }
2456
- var playYrp = (ocgcoreWrapper, yrpInput) => {
2445
+ function* playYrpStep(ocgcoreWrapper, yrpInput) {
2457
2446
  const yrp = normalizeYrp(yrpInput);
2458
- const messages = [];
2459
2447
  const responses = yrp.responses.slice();
2460
2448
  const duel = createReplayDuel(ocgcoreWrapper, yrp);
2461
2449
  let ended = false;
@@ -2508,16 +2496,19 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
2508
2496
  }
2509
2497
  duel.startDuel(yrp.opt >>> 0);
2510
2498
  while (true) {
2511
- const { raw, status } = duel.process();
2512
- messages.push(raw);
2513
- if (raw.length > 0 && raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
2499
+ const result = duel.process();
2500
+ yield {
2501
+ duel,
2502
+ result
2503
+ };
2504
+ if (result.raw.length > 0 && result.raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
2514
2505
  throw new Error("Got MSG_RETRY");
2515
2506
  }
2516
- if (status === 0) {
2507
+ if (result.status === 0) {
2517
2508
  continue;
2518
2509
  }
2519
- if (status === 1) {
2520
- if (raw.length === 0) {
2510
+ if (result.status === 1) {
2511
+ if (result.raw.length === 0) {
2521
2512
  continue;
2522
2513
  }
2523
2514
  const response = responses.shift();
@@ -2532,7 +2523,13 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
2532
2523
  } finally {
2533
2524
  endDuel();
2534
2525
  }
2535
- return messages;
2526
+ }
2527
+ var playYrp = (ocgcoreWrapper, yrpInput) => {
2528
+ const results = [];
2529
+ for (const result of playYrpStep(ocgcoreWrapper, yrpInput)) {
2530
+ results.push(result.result.raw);
2531
+ }
2532
+ return results;
2536
2533
  };
2537
2534
 
2538
2535
  // src/test-card.ts
@@ -2610,6 +2607,7 @@ if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
2610
2607
  parseRegistryDump,
2611
2608
  parseRegistryKeys,
2612
2609
  playYrp,
2610
+ playYrpStep,
2613
2611
  testCard
2614
2612
  });
2615
2613
  //# sourceMappingURL=index.cjs.map