|
66 | 66 | const file = e.target.files[0]; |
67 | 67 | if (!file) return; |
68 | 68 |
|
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); |
81 | 87 | } |
82 | | - } catch (err) { |
83 | | - console.error("[Emulator] State 导入失败:", err); |
84 | 88 | } |
85 | | - } |
| 89 | + }; |
| 90 | + |
| 91 | + // 开始以 ArrayBuffer 格式读取文件 |
| 92 | + reader.readAsArrayBuffer(file); |
86 | 93 |
|
87 | | - // 核心细节:清空 input 的值,确保玩家可以连续多次导入同一个 State 文件 |
| 94 | + // 清空 input,允许连续多次点击导入同一个文件 |
88 | 95 | e.target.value = ''; |
89 | 96 | }); |
90 | 97 | </script> |
|
0 commit comments