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 +70 -35
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +70 -43
- package/dist/index.mjs.map +4 -4
- package/dist/src/adapters/script-readers.d.ts +1 -1
- package/dist/src/ocgcore-wrapper.d.ts +3 -5
- package/dist/src/sqljs-card-reader.d.ts +1 -1
- package/dist/src/test-card.d.ts +7 -0
- package/dist/src/types/callback.d.ts +6 -0
- package/dist/src/types/card-data.d.ts +0 -1
- package/dist/src/types/index.d.ts +1 -1
- package/dist/src/utility/load-node-module.d.ts +2 -0
- package/index.ts +1 -0
- package/package.json +1 -1
- package/dist/src/types/ocgcore-readers.d.ts +0 -1
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 ===
|
|
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-
|
|
1259
|
-
function
|
|
1260
|
-
const req =
|
|
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
|
-
|
|
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(
|
|
1268
|
+
return req(id);
|
|
1269
1269
|
} catch {
|
|
1270
|
+
if (!altId) return null;
|
|
1270
1271
|
try {
|
|
1271
|
-
return req(
|
|
1272
|
+
return req(altId);
|
|
1272
1273
|
} catch {
|
|
1273
|
-
|
|
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
|
|
1284
|
-
if (
|
|
1285
|
-
|
|
1286
|
-
|
|
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
|