koishipro-core.js 1.1.4 → 1.1.6
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 +41 -30
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +41 -30
- package/dist/index.mjs.map +2 -2
- package/dist/src/ocgcore-wrapper.d.ts +8 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -897,17 +897,7 @@ var OcgcoreWrapper = class {
|
|
|
897
897
|
this.logBufferSize = options?.logBufferSize ?? 1024;
|
|
898
898
|
this.scriptReaderFunc = this.createFunction((scriptPtr, lenPtr) => {
|
|
899
899
|
const scriptPath = this.getUTF8String(scriptPtr);
|
|
900
|
-
|
|
901
|
-
for (const reader of this.scriptReaders) {
|
|
902
|
-
try {
|
|
903
|
-
content = reader(scriptPath);
|
|
904
|
-
} catch {
|
|
905
|
-
content = null;
|
|
906
|
-
}
|
|
907
|
-
if (content != null) {
|
|
908
|
-
break;
|
|
909
|
-
}
|
|
910
|
-
}
|
|
900
|
+
const content = this.readScript(scriptPath);
|
|
911
901
|
if (content == null) {
|
|
912
902
|
return 0;
|
|
913
903
|
}
|
|
@@ -916,7 +906,7 @@ var OcgcoreWrapper = class {
|
|
|
916
906
|
this.scriptBufferSize
|
|
917
907
|
);
|
|
918
908
|
}
|
|
919
|
-
const bytes =
|
|
909
|
+
const bytes = content;
|
|
920
910
|
if (bytes.length > this.scriptBufferSize) {
|
|
921
911
|
this.ocgcoreModule._free(this.scriptBufferPtr);
|
|
922
912
|
this.scriptBufferPtr = this.ocgcoreModule._malloc(bytes.length);
|
|
@@ -928,17 +918,7 @@ var OcgcoreWrapper = class {
|
|
|
928
918
|
}, "iii");
|
|
929
919
|
this.ocgcoreModule._set_script_reader(this.scriptReaderFunc);
|
|
930
920
|
this.cardReaderFunc = this.createFunction((cardId, cardDataPtr) => {
|
|
931
|
-
|
|
932
|
-
for (const reader of this.cardReaders) {
|
|
933
|
-
try {
|
|
934
|
-
data = reader(cardId);
|
|
935
|
-
} catch {
|
|
936
|
-
data = null;
|
|
937
|
-
}
|
|
938
|
-
if (data) {
|
|
939
|
-
break;
|
|
940
|
-
}
|
|
941
|
-
}
|
|
921
|
+
const data = this.readCard(cardId);
|
|
942
922
|
if (!data) {
|
|
943
923
|
return 0;
|
|
944
924
|
}
|
|
@@ -982,15 +962,46 @@ var OcgcoreWrapper = class {
|
|
|
982
962
|
const message = this.getUTF8String(this.logBufferPtr);
|
|
983
963
|
const type = messageType === 2 ? "DebugMessage" /* DebugMessage */ : "ScriptError" /* ScriptError */;
|
|
984
964
|
const duel = this.getOrCreateDuel(duelPtr);
|
|
985
|
-
|
|
986
|
-
try {
|
|
987
|
-
handler(duel, message, type);
|
|
988
|
-
} catch {
|
|
989
|
-
}
|
|
990
|
-
}
|
|
965
|
+
this.handleMessage(duel, message, type);
|
|
991
966
|
}, "iii");
|
|
992
967
|
this.ocgcoreModule._set_message_handler(this.messageHandlerFunc);
|
|
993
968
|
}
|
|
969
|
+
readScript(scriptPath) {
|
|
970
|
+
let content;
|
|
971
|
+
for (const reader of this.scriptReaders) {
|
|
972
|
+
try {
|
|
973
|
+
content = reader(scriptPath);
|
|
974
|
+
} catch {
|
|
975
|
+
content = null;
|
|
976
|
+
}
|
|
977
|
+
if (content != null) {
|
|
978
|
+
break;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
return typeof content === "string" ? this.encoder.encode(content) : content ?? null;
|
|
982
|
+
}
|
|
983
|
+
readCard(cardId) {
|
|
984
|
+
let data;
|
|
985
|
+
for (const reader of this.cardReaders) {
|
|
986
|
+
try {
|
|
987
|
+
data = reader(cardId);
|
|
988
|
+
} catch {
|
|
989
|
+
data = null;
|
|
990
|
+
}
|
|
991
|
+
if (data) {
|
|
992
|
+
break;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
return data ?? null;
|
|
996
|
+
}
|
|
997
|
+
handleMessage(duel, message, type) {
|
|
998
|
+
for (const handler of this.messageHandlers) {
|
|
999
|
+
try {
|
|
1000
|
+
handler(duel, message, type);
|
|
1001
|
+
} catch {
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
994
1005
|
getUTF8String(ptr) {
|
|
995
1006
|
let length = 0;
|
|
996
1007
|
while (this.heapU8[ptr + length] !== 0) {
|
|
@@ -2406,9 +2417,9 @@ async function collectFsDbPaths(fs, pathMod, baseDir) {
|
|
|
2406
2417
|
return paths;
|
|
2407
2418
|
};
|
|
2408
2419
|
const results = [];
|
|
2409
|
-
results.push(...await collectCdbFiles(baseDir));
|
|
2410
2420
|
const expansionsDir = joinPath3(pathMod, baseDir, "expansions");
|
|
2411
2421
|
results.push(...await collectCdbFiles(expansionsDir));
|
|
2422
|
+
results.push(...await collectCdbFiles(baseDir));
|
|
2412
2423
|
return results;
|
|
2413
2424
|
}
|
|
2414
2425
|
function isRootCdbEntry(entryName) {
|