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.mjs
CHANGED
|
@@ -835,17 +835,7 @@ var OcgcoreWrapper = class {
|
|
|
835
835
|
this.logBufferSize = options?.logBufferSize ?? 1024;
|
|
836
836
|
this.scriptReaderFunc = this.createFunction((scriptPtr, lenPtr) => {
|
|
837
837
|
const scriptPath = this.getUTF8String(scriptPtr);
|
|
838
|
-
|
|
839
|
-
for (const reader of this.scriptReaders) {
|
|
840
|
-
try {
|
|
841
|
-
content = reader(scriptPath);
|
|
842
|
-
} catch {
|
|
843
|
-
content = null;
|
|
844
|
-
}
|
|
845
|
-
if (content != null) {
|
|
846
|
-
break;
|
|
847
|
-
}
|
|
848
|
-
}
|
|
838
|
+
const content = this.readScript(scriptPath);
|
|
849
839
|
if (content == null) {
|
|
850
840
|
return 0;
|
|
851
841
|
}
|
|
@@ -854,7 +844,7 @@ var OcgcoreWrapper = class {
|
|
|
854
844
|
this.scriptBufferSize
|
|
855
845
|
);
|
|
856
846
|
}
|
|
857
|
-
const bytes =
|
|
847
|
+
const bytes = content;
|
|
858
848
|
if (bytes.length > this.scriptBufferSize) {
|
|
859
849
|
this.ocgcoreModule._free(this.scriptBufferPtr);
|
|
860
850
|
this.scriptBufferPtr = this.ocgcoreModule._malloc(bytes.length);
|
|
@@ -866,17 +856,7 @@ var OcgcoreWrapper = class {
|
|
|
866
856
|
}, "iii");
|
|
867
857
|
this.ocgcoreModule._set_script_reader(this.scriptReaderFunc);
|
|
868
858
|
this.cardReaderFunc = this.createFunction((cardId, cardDataPtr) => {
|
|
869
|
-
|
|
870
|
-
for (const reader of this.cardReaders) {
|
|
871
|
-
try {
|
|
872
|
-
data = reader(cardId);
|
|
873
|
-
} catch {
|
|
874
|
-
data = null;
|
|
875
|
-
}
|
|
876
|
-
if (data) {
|
|
877
|
-
break;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
859
|
+
const data = this.readCard(cardId);
|
|
880
860
|
if (!data) {
|
|
881
861
|
return 0;
|
|
882
862
|
}
|
|
@@ -920,15 +900,46 @@ var OcgcoreWrapper = class {
|
|
|
920
900
|
const message = this.getUTF8String(this.logBufferPtr);
|
|
921
901
|
const type = messageType === 2 ? "DebugMessage" /* DebugMessage */ : "ScriptError" /* ScriptError */;
|
|
922
902
|
const duel = this.getOrCreateDuel(duelPtr);
|
|
923
|
-
|
|
924
|
-
try {
|
|
925
|
-
handler(duel, message, type);
|
|
926
|
-
} catch {
|
|
927
|
-
}
|
|
928
|
-
}
|
|
903
|
+
this.handleMessage(duel, message, type);
|
|
929
904
|
}, "iii");
|
|
930
905
|
this.ocgcoreModule._set_message_handler(this.messageHandlerFunc);
|
|
931
906
|
}
|
|
907
|
+
readScript(scriptPath) {
|
|
908
|
+
let content;
|
|
909
|
+
for (const reader of this.scriptReaders) {
|
|
910
|
+
try {
|
|
911
|
+
content = reader(scriptPath);
|
|
912
|
+
} catch {
|
|
913
|
+
content = null;
|
|
914
|
+
}
|
|
915
|
+
if (content != null) {
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return typeof content === "string" ? this.encoder.encode(content) : content ?? null;
|
|
920
|
+
}
|
|
921
|
+
readCard(cardId) {
|
|
922
|
+
let data;
|
|
923
|
+
for (const reader of this.cardReaders) {
|
|
924
|
+
try {
|
|
925
|
+
data = reader(cardId);
|
|
926
|
+
} catch {
|
|
927
|
+
data = null;
|
|
928
|
+
}
|
|
929
|
+
if (data) {
|
|
930
|
+
break;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
return data ?? null;
|
|
934
|
+
}
|
|
935
|
+
handleMessage(duel, message, type) {
|
|
936
|
+
for (const handler of this.messageHandlers) {
|
|
937
|
+
try {
|
|
938
|
+
handler(duel, message, type);
|
|
939
|
+
} catch {
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
932
943
|
getUTF8String(ptr) {
|
|
933
944
|
let length = 0;
|
|
934
945
|
while (this.heapU8[ptr + length] !== 0) {
|
|
@@ -2318,9 +2329,9 @@ async function collectFsDbPaths(fs, pathMod, baseDir) {
|
|
|
2318
2329
|
return paths;
|
|
2319
2330
|
};
|
|
2320
2331
|
const results = [];
|
|
2321
|
-
results.push(...await collectCdbFiles(baseDir));
|
|
2322
2332
|
const expansionsDir = joinPath3(pathMod, baseDir, "expansions");
|
|
2323
2333
|
results.push(...await collectCdbFiles(expansionsDir));
|
|
2334
|
+
results.push(...await collectCdbFiles(baseDir));
|
|
2324
2335
|
return results;
|
|
2325
2336
|
}
|
|
2326
2337
|
function isRootCdbEntry(entryName) {
|