fix save/load, especially for embeds
This commit is contained in:
parent
bdc8a32e36
commit
2116920340
1 changed files with 51 additions and 47 deletions
|
@ -4,7 +4,7 @@
|
||||||
Features a somewhat efficient compression algorithm.
|
Features a somewhat efficient compression algorithm.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function download_file(data, filename) {
|
function downloadFile(data, filename) {
|
||||||
// ONLY works with ascii/latin1 characters. if you'd like to be able to download UTF-16 data (for compression, etc), please find a base64-encoding library for UTF-16, and replace "btoa".
|
// ONLY works with ascii/latin1 characters. if you'd like to be able to download UTF-16 data (for compression, etc), please find a base64-encoding library for UTF-16, and replace "btoa".
|
||||||
|
|
||||||
let a = document.createElement("a");
|
let a = document.createElement("a");
|
||||||
|
@ -15,7 +15,7 @@ function download_file(data, filename) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function upload_file(options = {}) {
|
function uploadFile(options = {}) {
|
||||||
base64_output = Boolean(options.useBase64);
|
base64_output = Boolean(options.useBase64);
|
||||||
textEncoding = options.textEncoding ? options.textEncoding : "UTF-8";
|
textEncoding = options.textEncoding ? options.textEncoding : "UTF-8";
|
||||||
|
|
||||||
|
@ -90,12 +90,10 @@ function save() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
download_file(JSON.stringify(jason), "game-data.json");
|
downloadFile(JSON.stringify(jason), "game-data.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
function load() {
|
function loadFile(text_data) {
|
||||||
upload_file().then((text_data) => {
|
|
||||||
try {
|
|
||||||
let jason = JSON.parse(text_data);
|
let jason = JSON.parse(text_data);
|
||||||
|
|
||||||
let json = jason.data;
|
let json = jason.data;
|
||||||
|
@ -138,6 +136,12 @@ function load() {
|
||||||
for (let i in canvas.temp) {
|
for (let i in canvas.temp) {
|
||||||
canvas.temp[i] = mainTiles.tiles[canvas.blocks[i]].attributes.temperature;
|
canvas.temp[i] = mainTiles.tiles[canvas.blocks[i]].attributes.temperature;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function load() {
|
||||||
|
uploadFile().then((text_data) => {
|
||||||
|
try {
|
||||||
|
loadFile(text_data);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
alert("This save file is invalid! Please provide a JSON file, with Altboxels save data.")
|
alert("This save file is invalid! Please provide a JSON file, with Altboxels save data.")
|
||||||
}
|
}
|
||||||
|
@ -153,7 +157,7 @@ var loc2;
|
||||||
|
|
||||||
if (loc) {
|
if (loc) {
|
||||||
(async function() {
|
(async function() {
|
||||||
document.querySelector('#code').value = await fetch(loc).then(x => x.text());
|
loadFile(await fetch(loc).then(x => x.text()));
|
||||||
load();
|
load();
|
||||||
loc2 = loc3;
|
loc2 = loc3;
|
||||||
})()
|
})()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue