Skip to content

Commit 31e83ff

Browse files
committed
93
1 parent 3151f63 commit 31e83ff

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

game/emulator.html

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,32 @@
6666
const file = e.target.files[0];
6767
if (!file) return;
6868

69-
if (window.EJS_emulator) {
70-
console.log("[Emulator] 正在注入即时存档 (State):", file.name);
71-
72-
// 兼容不同版本的 EmulatorJS State 导入 API
73-
try {
74-
// 尝试高版本 API
75-
if (window.EJS_emulator.gameManager && typeof window.EJS_emulator.gameManager.loadState === 'function') {
76-
window.EJS_emulator.gameManager.loadState(file);
77-
}
78-
// 尝试基础/旧版 API
79-
else if (typeof window.EJS_emulator.loadState === 'function') {
80-
window.EJS_emulator.loadState(file);
69+
console.log("[Emulator] 正在解析即时存档 (State):", file.name);
70+
71+
// 核心修复:使用 FileReader 将 File 对象转换为底层认识的 Uint8Array
72+
const reader = new FileReader();
73+
reader.onload = function(event) {
74+
const stateData = new Uint8Array(event.target.result);
75+
76+
if (window.EJS_emulator) {
77+
try {
78+
if (window.EJS_emulator.gameManager && typeof window.EJS_emulator.gameManager.loadState === 'function') {
79+
// 传入转换后的二进制数据
80+
window.EJS_emulator.gameManager.loadState(stateData);
81+
} else if (typeof window.EJS_emulator.loadState === 'function') {
82+
window.EJS_emulator.loadState(stateData);
83+
}
84+
console.log("[Emulator] State 注入成功!");
85+
} catch (err) {
86+
console.error("[Emulator] State 注入执行报错:", err);
8187
}
82-
} catch (err) {
83-
console.error("[Emulator] State 导入失败:", err);
8488
}
85-
}
89+
};
90+
91+
// 开始以 ArrayBuffer 格式读取文件
92+
reader.readAsArrayBuffer(file);
8693

87-
// 核心细节:清空 input 的值,确保玩家可以连续多次导入同一个 State 文件
94+
// 清空 input,允许连续多次点击导入同一个文件
8895
e.target.value = '';
8996
});
9097
</script>

0 commit comments

Comments
 (0)