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.mjs CHANGED
@@ -1,12 +1,5 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
1
  // index.ts
9
- import { Buffer as Buffer2 } from "buffer";
2
+ import { Buffer } from "buffer";
10
3
 
11
4
  // src/vendor/ocgcore-constants.ts
12
5
  var OcgcoreCommonConstants = {
@@ -1231,50 +1224,38 @@ async function createOcgcoreWrapper(options = {}) {
1231
1224
  // src/adapters/script-readers.ts
1232
1225
  import JSZip from "jszip";
1233
1226
 
1234
- // src/utility/node-fs.ts
1235
- function getNodeFs(noThrow = false) {
1236
- const req = typeof __require !== "undefined" && __require || Function('return typeof require !== "undefined" && require')();
1227
+ // src/utility/load-node-module.ts
1228
+ function loadNodeModule(id, altId) {
1229
+ const req = typeof module.require !== "undefined" ? module.require : void 0;
1237
1230
  if (!req) {
1238
- if (noThrow) {
1239
- return null;
1240
- }
1241
- throw new Error("Node.js fs module is not available.");
1231
+ return null;
1242
1232
  }
1243
1233
  try {
1244
- return req("node:fs");
1234
+ return req(id);
1245
1235
  } catch {
1236
+ if (!altId) return null;
1246
1237
  try {
1247
- return req("fs");
1238
+ return req(altId);
1248
1239
  } catch {
1249
- if (noThrow) {
1250
- return null;
1251
- }
1252
- throw new Error("Node.js fs module is not available.");
1240
+ return null;
1253
1241
  }
1254
1242
  }
1255
1243
  }
1256
1244
 
1245
+ // src/utility/node-fs.ts
1246
+ function getNodeFs(noThrow = false) {
1247
+ const mod = loadNodeModule("node:fs", "fs");
1248
+ if (mod) return mod;
1249
+ if (noThrow) return null;
1250
+ throw new Error("Node.js fs module is not available.");
1251
+ }
1252
+
1257
1253
  // src/utility/node-path.ts
1258
1254
  function getNodePath(noThrow = false) {
1259
- const req = typeof __require !== "undefined" && __require || Function('return typeof require !== "undefined" && require')();
1260
- if (!req) {
1261
- if (noThrow) {
1262
- return null;
1263
- }
1264
- throw new Error("Node.js path module is not available.");
1265
- }
1266
- try {
1267
- return req("node:path");
1268
- } catch {
1269
- try {
1270
- return req("path");
1271
- } catch {
1272
- if (noThrow) {
1273
- return null;
1274
- }
1275
- throw new Error("Node.js path module is not available.");
1276
- }
1277
- }
1255
+ const mod = loadNodeModule("node:path", "path");
1256
+ if (mod) return mod;
1257
+ if (noThrow) return null;
1258
+ throw new Error("Node.js path module is not available.");
1278
1259
  }
1279
1260
 
1280
1261
  // src/adapters/script-readers.ts
@@ -2375,9 +2356,8 @@ function loadTagDeck(duel, deck, owner) {
2375
2356
  function setRegistryValue(duel, key, value) {
2376
2357
  duel.setRegistryValue(key, value);
2377
2358
  }
2378
- var playYrp = (ocgcoreWrapper, yrpInput) => {
2359
+ function* playYrpStep(ocgcoreWrapper, yrpInput) {
2379
2360
  const yrp = normalizeYrp(yrpInput);
2380
- const messages = [];
2381
2361
  const responses = yrp.responses.slice();
2382
2362
  const duel = createReplayDuel(ocgcoreWrapper, yrp);
2383
2363
  let ended = false;
@@ -2430,16 +2410,19 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
2430
2410
  }
2431
2411
  duel.startDuel(yrp.opt >>> 0);
2432
2412
  while (true) {
2433
- const { raw, status } = duel.process();
2434
- messages.push(raw);
2435
- if (raw.length > 0 && raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
2413
+ const result = duel.process();
2414
+ yield {
2415
+ duel,
2416
+ result
2417
+ };
2418
+ if (result.raw.length > 0 && result.raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
2436
2419
  throw new Error("Got MSG_RETRY");
2437
2420
  }
2438
- if (status === 0) {
2421
+ if (result.status === 0) {
2439
2422
  continue;
2440
2423
  }
2441
- if (status === 1) {
2442
- if (raw.length === 0) {
2424
+ if (result.status === 1) {
2425
+ if (result.raw.length === 0) {
2443
2426
  continue;
2444
2427
  }
2445
2428
  const response = responses.shift();
@@ -2454,7 +2437,13 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
2454
2437
  } finally {
2455
2438
  endDuel();
2456
2439
  }
2457
- return messages;
2440
+ }
2441
+ var playYrp = (ocgcoreWrapper, yrpInput) => {
2442
+ const results = [];
2443
+ for (const result of playYrpStep(ocgcoreWrapper, yrpInput)) {
2444
+ results.push(result.result.raw);
2445
+ }
2446
+ return results;
2458
2447
  };
2459
2448
 
2460
2449
  // src/test-card.ts
@@ -2502,7 +2491,7 @@ function testCard(ocgcoreWrapper, ...ids) {
2502
2491
 
2503
2492
  // index.ts
2504
2493
  if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
2505
- globalThis.Buffer = Buffer2;
2494
+ globalThis.Buffer = Buffer;
2506
2495
  }
2507
2496
  export {
2508
2497
  CardDataStruct,
@@ -2531,6 +2520,7 @@ export {
2531
2520
  parseRegistryDump,
2532
2521
  parseRegistryKeys,
2533
2522
  playYrp,
2523
+ playYrpStep,
2534
2524
  testCard
2535
2525
  };
2536
2526
  //# sourceMappingURL=index.mjs.map