background data stuff
This commit is contained in:
parent
66d0642006
commit
3d55d03097
2 changed files with 38 additions and 27 deletions
|
@ -8,7 +8,7 @@ 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".
|
||||
|
||||
let a = document.createElement("a");
|
||||
a.href = "data:text/plain;base64,"+(btoa(data));
|
||||
a.href = "data:text/plain;base64," + (btoa(data));
|
||||
a.setAttribute("download", filename);
|
||||
a.click();
|
||||
a.remove();
|
||||
|
@ -19,7 +19,7 @@ function uploadFile(options = {}) {
|
|||
base64_output = Boolean(options.useBase64);
|
||||
textEncoding = options.textEncoding ? options.textEncoding : "UTF-8";
|
||||
|
||||
return new Promise(function(res) {
|
||||
return new Promise(function (res) {
|
||||
var input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
|
||||
|
@ -33,7 +33,7 @@ function uploadFile(options = {}) {
|
|||
|
||||
}
|
||||
|
||||
if(base64_output)
|
||||
if (base64_output)
|
||||
reader.readAsDataURL(file);
|
||||
else
|
||||
reader.readAsText(file, textEncoding);
|
||||
|
@ -71,7 +71,7 @@ function save() {
|
|||
otherArray = new Uint8Array(64);
|
||||
|
||||
for (let i in otherArray) {
|
||||
otherArray[i] = (((pal.indexOf(arr[i*2]) * 8) + pal.indexOf(arr[i*2+1])) + 'A'.charCodeAt()) % 128;
|
||||
otherArray[i] = (((pal.indexOf(arr[i * 2]) * 8) + pal.indexOf(arr[i * 2 + 1])) + 'A'.charCodeAt()) % 128;
|
||||
}
|
||||
|
||||
} else if (pal.length > 8) {
|
||||
|
@ -102,7 +102,7 @@ function loadFile(text_data) {
|
|||
canvas.height = jason.height;
|
||||
canvas.resize();
|
||||
|
||||
let mainPal = jason.pal.map(x => mainTiles.resolveID(x[0],x[1]));
|
||||
let mainPal = jason.pal.map(x => mainTiles.resolveID(x[0], x[1]));
|
||||
|
||||
console.log(mainPal);
|
||||
|
||||
|
@ -115,22 +115,22 @@ function loadFile(text_data) {
|
|||
|
||||
if (pal.length < 2) {
|
||||
for (let i in otherArray) {
|
||||
otherArray[i] = mainPal[(pal[0])];
|
||||
otherArray[i] = mainPal[(pal[0])];
|
||||
}
|
||||
|
||||
} else if (pal.length < 9) {
|
||||
for (let i in dat) {
|
||||
otherArray[i*2] = mainPal[pal[((dat[i] - 'A'.charCodeAt()) & 0x38) / 8]];
|
||||
otherArray[i*2+1] = mainPal[pal[(dat[i] - 'A'.charCodeAt()) & 0x7]];
|
||||
otherArray[i * 2] = mainPal[pal[((dat[i] - 'A'.charCodeAt()) & 0x38) / 8]];
|
||||
otherArray[i * 2 + 1] = mainPal[pal[(dat[i] - 'A'.charCodeAt()) & 0x7]];
|
||||
}
|
||||
|
||||
} else {
|
||||
for (let i in dat) {
|
||||
otherArray[i] = mainPal[pal[(dat[i] - 'A'.charCodeAt()) & 0x7F]];
|
||||
otherArray[i] = mainPal[pal[(dat[i] - 'A'.charCodeAt()) & 0x7F]];
|
||||
}
|
||||
}
|
||||
|
||||
canvas.blocks.set(otherArray,Math.min(i*128,canvas.blocks.length - 128));
|
||||
canvas.blocks.set(otherArray, Math.min(i * 128, canvas.blocks.length - 128));
|
||||
}
|
||||
|
||||
for (let i in canvas.temp) {
|
||||
|
@ -142,7 +142,7 @@ 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.")
|
||||
}
|
||||
})
|
||||
|
@ -156,7 +156,7 @@ if (loc3.get('oops') == 'true') {
|
|||
var loc2;
|
||||
|
||||
if (loc) {
|
||||
(async function() {
|
||||
(async function () {
|
||||
loadFile(await fetch(loc).then(x => x.text()));
|
||||
load();
|
||||
loc2 = loc3;
|
||||
|
|
11
js/tile.js
11
js/tile.js
|
@ -62,6 +62,7 @@ function TileManager(row, row2) {
|
|||
this.row = row;
|
||||
this.row2 = row2;
|
||||
this.sel = 0;
|
||||
this.usedAnon = {};
|
||||
|
||||
this.used = {};
|
||||
|
||||
|
@ -106,6 +107,16 @@ TileManager.prototype.loadSet = function (namespace, tiles) {
|
|||
|
||||
elem.addEventListener('click', () => {
|
||||
this.sel = tile.number;
|
||||
if (!this.usedAnon[this.sel]) {
|
||||
fetch("https://data.dervland.net/", {
|
||||
"method": "post",
|
||||
"body": JSON.stringify({'action': `Used ${tile.id} in Altboxels`}),
|
||||
"headers": {
|
||||
"content-type": "application/json"
|
||||
}
|
||||
})
|
||||
}
|
||||
this.usedAnon[this.sel] = true;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue