koishipro-core.js 1.0.7 → 1.0.9

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
@@ -54,7 +54,8 @@ __export(index_exports, {
54
54
  parseFieldInfo: () => parseFieldInfo,
55
55
  parseRegistryDump: () => parseRegistryDump,
56
56
  parseRegistryKeys: () => parseRegistryKeys,
57
- playYrp: () => playYrp
57
+ playYrp: () => playYrp,
58
+ testCard: () => testCard
58
59
  });
59
60
  module.exports = __toCommonJS(index_exports);
60
61
  var import_buffer = require("buffer");
@@ -1093,7 +1094,7 @@ var OcgcoreWrapper = class {
1093
1094
  }
1094
1095
  this.ocgcoreModule._get_log_message(duelPtr, this.logBufferPtr);
1095
1096
  const message = this.getUTF8String(this.logBufferPtr);
1096
- const type = messageType === 1 ? "ScriptError" /* ScriptError */ : messageType === 2 ? "DebugMessage" /* DebugMessage */ : messageType;
1097
+ const type = messageType === 2 ? "DebugMessage" /* DebugMessage */ : "ScriptError" /* ScriptError */;
1097
1098
  const duel = this.getOrCreateDuel(duelPtr);
1098
1099
  for (const handler of this.messageHandlers) {
1099
1100
  try {
@@ -1255,50 +1256,40 @@ function normalizeOcgcoreFactory(mod) {
1255
1256
  throw new Error("Invalid ocgcore factory module");
1256
1257
  }
1257
1258
 
1258
- // src/utility/node-fs.ts
1259
- function getNodeFs(noThrow = false) {
1260
- const req = typeof require !== "undefined" && require || Function('return typeof require !== "undefined" && require')();
1259
+ // src/utility/load-node-module.ts
1260
+ function loadNodeModule(id, altId) {
1261
+ const req = new Function(
1262
+ 'return typeof require !== "undefined" ? require : undefined'
1263
+ )();
1261
1264
  if (!req) {
1262
- if (noThrow) {
1263
- return null;
1264
- }
1265
- throw new Error("Node.js fs module is not available.");
1265
+ return null;
1266
1266
  }
1267
1267
  try {
1268
- return req("node:fs");
1268
+ return req(id);
1269
1269
  } catch {
1270
+ if (!altId) return null;
1270
1271
  try {
1271
- return req("fs");
1272
+ return req(altId);
1272
1273
  } catch {
1273
- if (noThrow) {
1274
- return null;
1275
- }
1276
- throw new Error("Node.js fs module is not available.");
1274
+ return null;
1277
1275
  }
1278
1276
  }
1279
1277
  }
1280
1278
 
1279
+ // src/utility/node-fs.ts
1280
+ function getNodeFs(noThrow = false) {
1281
+ const mod = loadNodeModule("node:fs", "fs");
1282
+ if (mod) return mod;
1283
+ if (noThrow) return null;
1284
+ throw new Error("Node.js fs module is not available.");
1285
+ }
1286
+
1281
1287
  // src/utility/node-path.ts
1282
1288
  function getNodePath(noThrow = false) {
1283
- const req = typeof require !== "undefined" && require || Function('return typeof require !== "undefined" && require')();
1284
- if (!req) {
1285
- if (noThrow) {
1286
- return null;
1287
- }
1288
- throw new Error("Node.js path module is not available.");
1289
- }
1290
- try {
1291
- return req("node:path");
1292
- } catch {
1293
- try {
1294
- return req("path");
1295
- } catch {
1296
- if (noThrow) {
1297
- return null;
1298
- }
1299
- throw new Error("Node.js path module is not available.");
1300
- }
1301
- }
1289
+ const mod = loadNodeModule("node:path", "path");
1290
+ if (mod) return mod;
1291
+ if (noThrow) return null;
1292
+ throw new Error("Node.js path module is not available.");
1302
1293
  }
1303
1294
 
1304
1295
  // src/load-ocgcore-factory.cjs.ts
@@ -2534,6 +2525,49 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
2534
2525
  return messages;
2535
2526
  };
2536
2527
 
2528
+ // src/test-card.ts
2529
+ var { LOCATION_DECK: LOCATION_DECK2, POS_FACEUP_ATTACK } = OcgcoreScriptConstants;
2530
+ function testCard(ocgcoreWrapper, ...ids) {
2531
+ const logs = [];
2532
+ const duel = ocgcoreWrapper.createDuelV2(
2533
+ Array.from(
2534
+ { length: 8 },
2535
+ () => Math.floor(Math.random() * 4294967295) >>> 0
2536
+ )
2537
+ );
2538
+ ocgcoreWrapper.setMessageHandler((_duel, message, type) => {
2539
+ if (duel.duelPtr !== _duel.duelPtr) return;
2540
+ logs.push({ type, message });
2541
+ });
2542
+ duel.preloadScript("./script/special.lua");
2543
+ duel.preloadScript("./script/init.lua");
2544
+ duel.setPlayerInfo({ playerId: 0, lp: 8e3, startCount: 5, drawCount: 1 });
2545
+ duel.setPlayerInfo({ playerId: 1, lp: 8e3, startCount: 5, drawCount: 1 });
2546
+ for (const code of ids) {
2547
+ duel.newCard({
2548
+ code,
2549
+ owner: 0,
2550
+ playerId: 0,
2551
+ location: LOCATION_DECK2,
2552
+ sequence: 0,
2553
+ position: POS_FACEUP_ATTACK
2554
+ });
2555
+ }
2556
+ duel.startDuel(0);
2557
+ while (true) {
2558
+ const { status, raw } = duel.process();
2559
+ if (raw.length > 0 && raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
2560
+ break;
2561
+ }
2562
+ if (status === 0) {
2563
+ continue;
2564
+ }
2565
+ break;
2566
+ }
2567
+ duel.endDuel();
2568
+ return logs;
2569
+ }
2570
+
2537
2571
  // index.ts
2538
2572
  if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
2539
2573
  globalThis.Buffer = import_buffer.Buffer;
@@ -2565,6 +2599,7 @@ if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
2565
2599
  parseFieldInfo,
2566
2600
  parseRegistryDump,
2567
2601
  parseRegistryKeys,
2568
- playYrp
2602
+ playYrp,
2603
+ testCard
2569
2604
  });
2570
2605
  //# sourceMappingURL=index.cjs.map