Read Me
Welcome to the LEGO Island web port project! This is a recreation of the classic 1997 PC game, rebuilt to run in modern web browsers using Emscripten.
@@ -659,7 +656,7 @@
@@ -682,7 +679,7 @@
-
+
@@ -879,7 +874,6 @@
preRun: function() {
Module["addRunDependency"]("isle");
Module.running = true;
- ENV.MY_FILE_ROOT = "/usr/lib/test";
},
canvas: (function() {
return document.getElementById('canvas');
@@ -1036,9 +1030,9 @@
},
async saveConfig() {
- const handle = await this.getFileHandle();
- if (!handle) return;
-
+ // This function now uses an inline Web Worker for maximum compatibility,
+ // especially with Safari, which does not support createWritable().
+
let iniContent = '[isle]\n';
const elements = this.form.elements;
@@ -1064,10 +1058,50 @@
}
}
- const writable = await handle.createWritable();
- await writable.write(iniContent);
- await writable.close();
- console.log('Config saved to', this.filePath);
+ const workerCode = `
+ self.onmessage = async (e) => {
+ if (e.data.action === 'save') {
+ try {
+ const root = await navigator.storage.getDirectory();
+ const handle = await root.getFileHandle(e.data.filePath, { create: true });
+ const accessHandle = await handle.createSyncAccessHandle();
+ const encoder = new TextEncoder();
+ const encodedData = encoder.encode(e.data.content);
+
+ accessHandle.truncate(0);
+ accessHandle.write(encodedData, { at: 0 });
+ accessHandle.flush();
+ accessHandle.close();
+
+ self.postMessage({ status: 'success', message: 'Config saved to ' + e.data.filePath });
+ } catch (err) {
+ self.postMessage({ status: 'error', message: 'Failed to save config: ' + err.message });
+ }
+ }
+ };
+ `;
+
+ const blob = new Blob([workerCode], { type: 'application/javascript' });
+ const workerUrl = URL.createObjectURL(blob);
+ const worker = new Worker(workerUrl);
+
+ worker.postMessage({
+ action: 'save',
+ content: iniContent,
+ filePath: this.filePath
+ });
+
+ worker.onmessage = (e) => {
+ console.log(e.data.message);
+ URL.revokeObjectURL(workerUrl); // Clean up the temporary URL
+ worker.terminate();
+ };
+
+ worker.onerror = (e) => {
+ console.error('An error occurred in the config-saving worker:', e.message);
+ URL.revokeObjectURL(workerUrl);
+ worker.terminate();
+ };
},
async loadConfig() {
@@ -1139,4 +1173,4 @@
-