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.d.ts
CHANGED
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
|
|
2
|
+
import { Buffer } from "buffer";
|
|
10
3
|
|
|
11
4
|
// src/vendor/ocgcore-constants.ts
|
|
12
5
|
var OcgcoreCommonConstants = {
|
|
@@ -1042,7 +1035,7 @@ var OcgcoreWrapper = class {
|
|
|
1042
1035
|
}
|
|
1043
1036
|
this.ocgcoreModule._get_log_message(duelPtr, this.logBufferPtr);
|
|
1044
1037
|
const message = this.getUTF8String(this.logBufferPtr);
|
|
1045
|
-
const type = messageType ===
|
|
1038
|
+
const type = messageType === 2 ? "DebugMessage" /* DebugMessage */ : "ScriptError" /* ScriptError */;
|
|
1046
1039
|
const duel = this.getOrCreateDuel(duelPtr);
|
|
1047
1040
|
for (const handler of this.messageHandlers) {
|
|
1048
1041
|
try {
|
|
@@ -1231,50 +1224,40 @@ async function createOcgcoreWrapper(options = {}) {
|
|
|
1231
1224
|
// src/adapters/script-readers.ts
|
|
1232
1225
|
import JSZip from "jszip";
|
|
1233
1226
|
|
|
1234
|
-
// src/utility/node-
|
|
1235
|
-
function
|
|
1236
|
-
const req =
|
|
1227
|
+
// src/utility/load-node-module.ts
|
|
1228
|
+
function loadNodeModule(id, altId) {
|
|
1229
|
+
const req = new Function(
|
|
1230
|
+
'return typeof require !== "undefined" ? require : undefined'
|
|
1231
|
+
)();
|
|
1237
1232
|
if (!req) {
|
|
1238
|
-
|
|
1239
|
-
return null;
|
|
1240
|
-
}
|
|
1241
|
-
throw new Error("Node.js fs module is not available.");
|
|
1233
|
+
return null;
|
|
1242
1234
|
}
|
|
1243
1235
|
try {
|
|
1244
|
-
return req(
|
|
1236
|
+
return req(id);
|
|
1245
1237
|
} catch {
|
|
1238
|
+
if (!altId) return null;
|
|
1246
1239
|
try {
|
|
1247
|
-
return req(
|
|
1240
|
+
return req(altId);
|
|
1248
1241
|
} catch {
|
|
1249
|
-
|
|
1250
|
-
return null;
|
|
1251
|
-
}
|
|
1252
|
-
throw new Error("Node.js fs module is not available.");
|
|
1242
|
+
return null;
|
|
1253
1243
|
}
|
|
1254
1244
|
}
|
|
1255
1245
|
}
|
|
1256
1246
|
|
|
1247
|
+
// src/utility/node-fs.ts
|
|
1248
|
+
function getNodeFs(noThrow = false) {
|
|
1249
|
+
const mod = loadNodeModule("node:fs", "fs");
|
|
1250
|
+
if (mod) return mod;
|
|
1251
|
+
if (noThrow) return null;
|
|
1252
|
+
throw new Error("Node.js fs module is not available.");
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1257
1255
|
// src/utility/node-path.ts
|
|
1258
1256
|
function getNodePath(noThrow = false) {
|
|
1259
|
-
const
|
|
1260
|
-
if (
|
|
1261
|
-
|
|
1262
|
-
|
|
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
|
-
}
|
|
1257
|
+
const mod = loadNodeModule("node:path", "path");
|
|
1258
|
+
if (mod) return mod;
|
|
1259
|
+
if (noThrow) return null;
|
|
1260
|
+
throw new Error("Node.js path module is not available.");
|
|
1278
1261
|
}
|
|
1279
1262
|
|
|
1280
1263
|
// src/adapters/script-readers.ts
|
|
@@ -2457,9 +2440,52 @@ var playYrp = (ocgcoreWrapper, yrpInput) => {
|
|
|
2457
2440
|
return messages;
|
|
2458
2441
|
};
|
|
2459
2442
|
|
|
2443
|
+
// src/test-card.ts
|
|
2444
|
+
var { LOCATION_DECK: LOCATION_DECK2, POS_FACEUP_ATTACK } = OcgcoreScriptConstants;
|
|
2445
|
+
function testCard(ocgcoreWrapper, ...ids) {
|
|
2446
|
+
const logs = [];
|
|
2447
|
+
const duel = ocgcoreWrapper.createDuelV2(
|
|
2448
|
+
Array.from(
|
|
2449
|
+
{ length: 8 },
|
|
2450
|
+
() => Math.floor(Math.random() * 4294967295) >>> 0
|
|
2451
|
+
)
|
|
2452
|
+
);
|
|
2453
|
+
ocgcoreWrapper.setMessageHandler((_duel, message, type) => {
|
|
2454
|
+
if (duel.duelPtr !== _duel.duelPtr) return;
|
|
2455
|
+
logs.push({ type, message });
|
|
2456
|
+
});
|
|
2457
|
+
duel.preloadScript("./script/special.lua");
|
|
2458
|
+
duel.preloadScript("./script/init.lua");
|
|
2459
|
+
duel.setPlayerInfo({ playerId: 0, lp: 8e3, startCount: 5, drawCount: 1 });
|
|
2460
|
+
duel.setPlayerInfo({ playerId: 1, lp: 8e3, startCount: 5, drawCount: 1 });
|
|
2461
|
+
for (const code of ids) {
|
|
2462
|
+
duel.newCard({
|
|
2463
|
+
code,
|
|
2464
|
+
owner: 0,
|
|
2465
|
+
playerId: 0,
|
|
2466
|
+
location: LOCATION_DECK2,
|
|
2467
|
+
sequence: 0,
|
|
2468
|
+
position: POS_FACEUP_ATTACK
|
|
2469
|
+
});
|
|
2470
|
+
}
|
|
2471
|
+
duel.startDuel(0);
|
|
2472
|
+
while (true) {
|
|
2473
|
+
const { status, raw } = duel.process();
|
|
2474
|
+
if (raw.length > 0 && raw[0] === OcgcoreCommonConstants.MSG_RETRY) {
|
|
2475
|
+
break;
|
|
2476
|
+
}
|
|
2477
|
+
if (status === 0) {
|
|
2478
|
+
continue;
|
|
2479
|
+
}
|
|
2480
|
+
break;
|
|
2481
|
+
}
|
|
2482
|
+
duel.endDuel();
|
|
2483
|
+
return logs;
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2460
2486
|
// index.ts
|
|
2461
2487
|
if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
2462
|
-
globalThis.Buffer =
|
|
2488
|
+
globalThis.Buffer = Buffer;
|
|
2463
2489
|
}
|
|
2464
2490
|
export {
|
|
2465
2491
|
CardDataStruct,
|
|
@@ -2487,6 +2513,7 @@ export {
|
|
|
2487
2513
|
parseFieldInfo,
|
|
2488
2514
|
parseRegistryDump,
|
|
2489
2515
|
parseRegistryKeys,
|
|
2490
|
-
playYrp
|
|
2516
|
+
playYrp,
|
|
2517
|
+
testCard
|
|
2491
2518
|
};
|
|
2492
2519
|
//# sourceMappingURL=index.mjs.map
|