koishipro-core.js 1.2.1 → 1.2.3
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 +34 -133
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.mjs +39 -137
- package/dist/index.mjs.map +4 -4
- package/dist/src/ocgcore-duel.d.ts +1 -0
- package/dist/src/ocgcore-wrapper.d.ts +2 -2
- package/dist/src/play-yrp.d.ts +0 -6
- package/dist/src/types/callback.d.ts +2 -2
- package/dist/src/types/index.d.ts +0 -1
- package/index.ts +0 -1
- package/package.json +2 -2
- package/dist/src/structs/card-data.d.ts +0 -16
- package/dist/src/structs/index.d.ts +0 -1
- package/dist/src/types/card-data.d.ts +0 -15
package/dist/index.cjs
CHANGED
|
@@ -25,19 +25,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
mod
|
|
26
26
|
));
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var __decorateClass = (decorators, target, key, kind) => {
|
|
29
|
-
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
30
|
-
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
31
|
-
if (decorator = decorators[i])
|
|
32
|
-
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
33
|
-
if (kind && result) __defProp(target, key, result);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
28
|
|
|
37
29
|
// index.ts
|
|
38
30
|
var index_exports = {};
|
|
39
31
|
__export(index_exports, {
|
|
40
|
-
CardDataStruct: () => CardDataStruct,
|
|
41
32
|
DirCardReader: () => DirCardReader,
|
|
42
33
|
DirReader: () => DirReader,
|
|
43
34
|
DirScriptReader: () => DirScriptReader,
|
|
@@ -59,7 +50,6 @@ __export(index_exports, {
|
|
|
59
50
|
ZipReader: () => ZipReader,
|
|
60
51
|
ZipScriptReader: () => ZipScriptReader,
|
|
61
52
|
_OcgcoreConstants: () => vendor_exports,
|
|
62
|
-
consumeResponseFromOcgcoreProcess: () => consumeResponseFromOcgcoreProcess,
|
|
63
53
|
createDuelFromYrp: () => createDuelFromYrp,
|
|
64
54
|
createOcgcoreWrapper: () => createOcgcoreWrapper,
|
|
65
55
|
createSqljsCardReader: () => createSqljsCardReader,
|
|
@@ -71,7 +61,6 @@ __export(index_exports, {
|
|
|
71
61
|
parseRegistryKeys: () => parseRegistryKeys,
|
|
72
62
|
playYrp: () => playYrp,
|
|
73
63
|
playYrpStep: () => playYrpStep,
|
|
74
|
-
processYrpDuelStep: () => processYrpDuelStep,
|
|
75
64
|
testCard: () => testCard
|
|
76
65
|
});
|
|
77
66
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -270,6 +259,22 @@ var OcgcoreDuel = class {
|
|
|
270
259
|
message: parsedMessage
|
|
271
260
|
};
|
|
272
261
|
}
|
|
262
|
+
*advance(advancor) {
|
|
263
|
+
while (true) {
|
|
264
|
+
const res = this.process();
|
|
265
|
+
yield res;
|
|
266
|
+
if (res.status === 2 || res.message instanceof import_ygopro_msg_encode3.YGOProMsgRetry) {
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
if (res.status === 1 && res.raw.length > 0) {
|
|
270
|
+
const response = advancor?.();
|
|
271
|
+
if (!response) {
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
this.setResponse(response);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
273
278
|
newCard(card) {
|
|
274
279
|
this.ocgcoreWrapper.ocgcoreModule._new_card(
|
|
275
280
|
this.duelPtr,
|
|
@@ -441,55 +446,8 @@ var OcgcoreDuel = class {
|
|
|
441
446
|
}
|
|
442
447
|
};
|
|
443
448
|
|
|
444
|
-
// src/
|
|
449
|
+
// src/ocgcore-wrapper.ts
|
|
445
450
|
var import_ygopro_msg_encode4 = require("ygopro-msg-encode");
|
|
446
|
-
var _CardDataStruct = class _CardDataStruct {
|
|
447
|
-
static fromBytes(data) {
|
|
448
|
-
const obj = new _CardDataStruct();
|
|
449
|
-
(0, import_ygopro_msg_encode4.fillBinaryFields)(obj, data, _CardDataStruct);
|
|
450
|
-
return obj;
|
|
451
|
-
}
|
|
452
|
-
toBytes() {
|
|
453
|
-
return (0, import_ygopro_msg_encode4.toBinaryFields)(this, _CardDataStruct);
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
__decorateClass([
|
|
457
|
-
(0, import_ygopro_msg_encode4.BinaryField)("u32", 0)
|
|
458
|
-
], _CardDataStruct.prototype, "code", 2);
|
|
459
|
-
__decorateClass([
|
|
460
|
-
(0, import_ygopro_msg_encode4.BinaryField)("u32", 4)
|
|
461
|
-
], _CardDataStruct.prototype, "alias", 2);
|
|
462
|
-
__decorateClass([
|
|
463
|
-
(0, import_ygopro_msg_encode4.BinaryField)("u16", 8, 16)
|
|
464
|
-
], _CardDataStruct.prototype, "setcode", 2);
|
|
465
|
-
__decorateClass([
|
|
466
|
-
(0, import_ygopro_msg_encode4.BinaryField)("u32", 40)
|
|
467
|
-
], _CardDataStruct.prototype, "type", 2);
|
|
468
|
-
__decorateClass([
|
|
469
|
-
(0, import_ygopro_msg_encode4.BinaryField)("u32", 44)
|
|
470
|
-
], _CardDataStruct.prototype, "level", 2);
|
|
471
|
-
__decorateClass([
|
|
472
|
-
(0, import_ygopro_msg_encode4.BinaryField)("u32", 48)
|
|
473
|
-
], _CardDataStruct.prototype, "attribute", 2);
|
|
474
|
-
__decorateClass([
|
|
475
|
-
(0, import_ygopro_msg_encode4.BinaryField)("u32", 52)
|
|
476
|
-
], _CardDataStruct.prototype, "race", 2);
|
|
477
|
-
__decorateClass([
|
|
478
|
-
(0, import_ygopro_msg_encode4.BinaryField)("i32", 56)
|
|
479
|
-
], _CardDataStruct.prototype, "attack", 2);
|
|
480
|
-
__decorateClass([
|
|
481
|
-
(0, import_ygopro_msg_encode4.BinaryField)("i32", 60)
|
|
482
|
-
], _CardDataStruct.prototype, "defense", 2);
|
|
483
|
-
__decorateClass([
|
|
484
|
-
(0, import_ygopro_msg_encode4.BinaryField)("u32", 64)
|
|
485
|
-
], _CardDataStruct.prototype, "lscale", 2);
|
|
486
|
-
__decorateClass([
|
|
487
|
-
(0, import_ygopro_msg_encode4.BinaryField)("u32", 68)
|
|
488
|
-
], _CardDataStruct.prototype, "rscale", 2);
|
|
489
|
-
__decorateClass([
|
|
490
|
-
(0, import_ygopro_msg_encode4.BinaryField)("u32", 72)
|
|
491
|
-
], _CardDataStruct.prototype, "linkMarker", 2);
|
|
492
|
-
var CardDataStruct = _CardDataStruct;
|
|
493
451
|
|
|
494
452
|
// src/types/ocgcore-enums.ts
|
|
495
453
|
var OcgcoreMessageType = /* @__PURE__ */ ((OcgcoreMessageType2) => {
|
|
@@ -567,34 +525,7 @@ var OcgcoreWrapper = class {
|
|
|
567
525
|
if (!data) {
|
|
568
526
|
return 0;
|
|
569
527
|
}
|
|
570
|
-
|
|
571
|
-
if (data instanceof CardDataStruct) {
|
|
572
|
-
buf = data.toBytes();
|
|
573
|
-
} else {
|
|
574
|
-
const cardData = new CardDataStruct();
|
|
575
|
-
cardData.code = data.code;
|
|
576
|
-
cardData.alias = data.alias;
|
|
577
|
-
const targetSetcode = new Uint16Array(16);
|
|
578
|
-
targetSetcode.fill(0);
|
|
579
|
-
if (data.setcode instanceof Uint16Array && data.setcode.length === 16) {
|
|
580
|
-
targetSetcode.set(data.setcode);
|
|
581
|
-
} else {
|
|
582
|
-
for (let i = 0; i < 16 && i < data.setcode.length; i++) {
|
|
583
|
-
targetSetcode[i] = data.setcode[i];
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
cardData.setcode = targetSetcode;
|
|
587
|
-
cardData.type = data.type;
|
|
588
|
-
cardData.level = data.level;
|
|
589
|
-
cardData.attribute = data.attribute;
|
|
590
|
-
cardData.race = data.race;
|
|
591
|
-
cardData.attack = data.attack;
|
|
592
|
-
cardData.defense = data.defense;
|
|
593
|
-
cardData.lscale = data.lscale;
|
|
594
|
-
cardData.rscale = data.rscale;
|
|
595
|
-
cardData.linkMarker = data.linkMarker;
|
|
596
|
-
buf = cardData.toBytes();
|
|
597
|
-
}
|
|
528
|
+
const buf = new import_ygopro_msg_encode4.CardData().fromPartial(data).toPayload();
|
|
598
529
|
this.heapU8.set(buf, cardDataPtr);
|
|
599
530
|
return 0;
|
|
600
531
|
}, "iii");
|
|
@@ -1085,15 +1016,13 @@ async function DirScriptReaderEx(...baseDirs) {
|
|
|
1085
1016
|
}
|
|
1086
1017
|
|
|
1087
1018
|
// src/card-reader/sqljs-card-reader.ts
|
|
1088
|
-
function
|
|
1019
|
+
function toNumberArrayFromSetcode(value) {
|
|
1089
1020
|
let raw = typeof value === "bigint" ? value : BigInt(value >>> 0);
|
|
1090
|
-
const list =
|
|
1091
|
-
|
|
1092
|
-
while (raw !== 0n && idx < 16) {
|
|
1021
|
+
const list = [];
|
|
1022
|
+
while (raw !== 0n && list.length < 16) {
|
|
1093
1023
|
const chunk = raw & 0xffffn;
|
|
1094
1024
|
if (chunk !== 0n) {
|
|
1095
|
-
list
|
|
1096
|
-
idx++;
|
|
1025
|
+
list.push(Number(chunk));
|
|
1097
1026
|
}
|
|
1098
1027
|
raw >>= 16n;
|
|
1099
1028
|
}
|
|
@@ -1115,7 +1044,7 @@ function mapRowToCardData(row) {
|
|
|
1115
1044
|
return {
|
|
1116
1045
|
code: row.id,
|
|
1117
1046
|
alias: row.alias ?? 0,
|
|
1118
|
-
setcode:
|
|
1047
|
+
setcode: toNumberArrayFromSetcode(row.setcode ?? 0),
|
|
1119
1048
|
type,
|
|
1120
1049
|
level,
|
|
1121
1050
|
attribute: (row.attribute ?? 0) >>> 0,
|
|
@@ -1276,6 +1205,7 @@ async function DirCardReader(sqljs, ...baseDirs) {
|
|
|
1276
1205
|
|
|
1277
1206
|
// src/play-yrp.ts
|
|
1278
1207
|
var import_ygopro_yrp_encode = require("ygopro-yrp-encode");
|
|
1208
|
+
var import_ygopro_msg_encode5 = require("ygopro-msg-encode");
|
|
1279
1209
|
var { LOCATION_DECK, LOCATION_EXTRA, POS_FACEDOWN_DEFENSE } = import_ygopro_msg_encode.OcgcoreScriptConstants;
|
|
1280
1210
|
function normalizeYrp(input) {
|
|
1281
1211
|
if (input instanceof import_ygopro_yrp_encode.YGOProYrp) {
|
|
@@ -1375,45 +1305,19 @@ function createDuelFromYrp(wrapper, yrpInput) {
|
|
|
1375
1305
|
duel.startDuel(yrp.opt >>> 0);
|
|
1376
1306
|
return { yrp, duel };
|
|
1377
1307
|
}
|
|
1378
|
-
function consumeResponseFromOcgcoreProcess(duel, result, responses) {
|
|
1379
|
-
if (result.raw.length > 0 && result.raw[0] === import_ygopro_msg_encode.OcgcoreCommonConstants.MSG_RETRY) {
|
|
1380
|
-
throw new Error("Got MSG_RETRY");
|
|
1381
|
-
}
|
|
1382
|
-
if (result.status === 0) {
|
|
1383
|
-
return false;
|
|
1384
|
-
}
|
|
1385
|
-
if (result.status === 1) {
|
|
1386
|
-
if (result.raw.length === 0) {
|
|
1387
|
-
return false;
|
|
1388
|
-
}
|
|
1389
|
-
const response = responses.shift();
|
|
1390
|
-
if (!response) {
|
|
1391
|
-
return true;
|
|
1392
|
-
}
|
|
1393
|
-
duel.setResponse(response);
|
|
1394
|
-
return false;
|
|
1395
|
-
}
|
|
1396
|
-
return true;
|
|
1397
|
-
}
|
|
1398
|
-
function* processYrpDuelStep(duel, yrp) {
|
|
1399
|
-
const responses = yrp.responses.slice();
|
|
1400
|
-
while (true) {
|
|
1401
|
-
const result = duel.process();
|
|
1402
|
-
yield {
|
|
1403
|
-
duel,
|
|
1404
|
-
result,
|
|
1405
|
-
responses
|
|
1406
|
-
};
|
|
1407
|
-
if (consumeResponseFromOcgcoreProcess(duel, result, responses)) {
|
|
1408
|
-
break;
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
1308
|
function* playYrpStep(ocgcoreWrapper, yrpInput) {
|
|
1413
1309
|
const { yrp, duel } = createDuelFromYrp(ocgcoreWrapper, yrpInput);
|
|
1310
|
+
const responses = yrp.responses.slice();
|
|
1414
1311
|
try {
|
|
1415
|
-
for (const
|
|
1416
|
-
yield
|
|
1312
|
+
for (const result of duel.advance(() => responses.shift())) {
|
|
1313
|
+
yield {
|
|
1314
|
+
duel,
|
|
1315
|
+
result,
|
|
1316
|
+
responses
|
|
1317
|
+
};
|
|
1318
|
+
if (result.message instanceof import_ygopro_msg_encode5.YGOProMsgRetry) {
|
|
1319
|
+
throw new Error("Got MSG_RETRY");
|
|
1320
|
+
}
|
|
1417
1321
|
}
|
|
1418
1322
|
} finally {
|
|
1419
1323
|
duel.endDuel();
|
|
@@ -1476,7 +1380,6 @@ if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
|
1476
1380
|
}
|
|
1477
1381
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1478
1382
|
0 && (module.exports = {
|
|
1479
|
-
CardDataStruct,
|
|
1480
1383
|
DirCardReader,
|
|
1481
1384
|
DirReader,
|
|
1482
1385
|
DirScriptReader,
|
|
@@ -1498,7 +1401,6 @@ if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
|
1498
1401
|
ZipReader,
|
|
1499
1402
|
ZipScriptReader,
|
|
1500
1403
|
_OcgcoreConstants,
|
|
1501
|
-
consumeResponseFromOcgcoreProcess,
|
|
1502
1404
|
createDuelFromYrp,
|
|
1503
1405
|
createOcgcoreWrapper,
|
|
1504
1406
|
createSqljsCardReader,
|
|
@@ -1510,7 +1412,6 @@ if (typeof globalThis !== "undefined" && !globalThis.Buffer) {
|
|
|
1510
1412
|
parseRegistryKeys,
|
|
1511
1413
|
playYrp,
|
|
1512
1414
|
playYrpStep,
|
|
1513
|
-
processYrpDuelStep,
|
|
1514
1415
|
testCard
|
|
1515
1416
|
});
|
|
1516
1417
|
//# sourceMappingURL=index.cjs.map
|