It would be nice to have the possibility to export savegames. Its saver than to save the game in the localstorage
I am doing it with this code
squiffy.story.save= function() {
const localStorageData = JSON.stringify(localStorage, null, 2);
const blob = new Blob([localStorageData], { type: "application/json" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "savegame.json";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
};
squiffy.story.load= function() {
const input = document.getElementById('fileInput');
if (!input.files.length) {
squiffy.story.toggleInputBox();
alert("Choose a file and click the button 'LOAD'");
return;
}
const file = input.files[0];
const reader = new FileReader();
reader.onload = function (event) {
try {
const data = JSON.parse(event.target.result);
// Optional: Vorher localStorage leeren
localStorage.clear();
for (const key in data) {
if (data.hasOwnProperty(key)) {
localStorage.setItem(key, data[key]);
}
}
alert("Spielstand erfolgreich wiederhergestellt.");
squiffy.story.toggleInputBox();
location.reload();
} catch (error) {
alert("Fehler beim Einlesen der Datei: " + error.message);
}
};
reader.readAsText(file);
}
It would be nice to have the possibility to export savegames. Its saver than to save the game in the localstorage
I am doing it with this code