fix downloadfile + importsprites
This commit is contained in:
parent
2ecdfcebf0
commit
c98810a01c
30
src/index.js
30
src/index.js
@ -86,7 +86,9 @@ importButton.onclick = async () => {
|
||||
});
|
||||
const code = items.find((x) => x.tag === "code");
|
||||
delete code.tag;
|
||||
spriteEditor.importSprites(sprites);
|
||||
spriteEditor.importSprites(
|
||||
sprites.map(({ name, mime, content }) => ({ name, mime, bytes: content })),
|
||||
);
|
||||
const dec = new TextDecoder();
|
||||
editor.setValue(dec.decode(code.content));
|
||||
};
|
||||
@ -108,10 +110,10 @@ runButton.onclick = () => {
|
||||
}
|
||||
};
|
||||
|
||||
function downloadBinaryFile(content, extension) {
|
||||
function downloadFile(content, extension, mime) {
|
||||
const filename = prompt("Filename?");
|
||||
|
||||
const blob = new Blob([content]);
|
||||
const blob = new Blob([content], { type: mime });
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const element = document.createElement("a");
|
||||
@ -127,22 +129,6 @@ function downloadBinaryFile(content, extension) {
|
||||
document.body.removeChild(element);
|
||||
}
|
||||
|
||||
function downloadTextFile(content, mime, extension) {
|
||||
const filename = prompt("Filename?");
|
||||
|
||||
const element = document.createElement("a");
|
||||
|
||||
element.href = `data:${mime};charset=utf-8,${encodeURIComponent(content)}`;
|
||||
element.download = filename.endsWith(extension) ? filename : filename + extension;
|
||||
element.style.display = "none";
|
||||
|
||||
document.body.appendChild(element);
|
||||
|
||||
element.click();
|
||||
|
||||
document.body.removeChild(element);
|
||||
}
|
||||
|
||||
function minifyJs(code) {
|
||||
return code
|
||||
.replace(/[\s\n]+/g, " ")
|
||||
@ -161,7 +147,7 @@ saveButton.onclick = () => {
|
||||
};
|
||||
|
||||
saveJsButton.onclick = () => {
|
||||
downloadTextFile(editor.getValue(), "text/javascript", ".js");
|
||||
downloadFile(editor.getValue(), ".js", "text/javascript");
|
||||
};
|
||||
|
||||
saveHtmlButton.onclick = async () => {
|
||||
@ -206,11 +192,11 @@ ${js}
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
downloadTextFile(html, "text/html", ".html");
|
||||
downloadTextFile(html, ".html", "text/html");
|
||||
};
|
||||
|
||||
saveKarlkoderButton.onclick = () => {
|
||||
downloadBinaryFile(
|
||||
downloadFile(
|
||||
Vermiparous.en(
|
||||
editor.getValue(),
|
||||
spriteEditor.sprites,
|
||||
|
@ -21,7 +21,11 @@ export class SpriteEditor {
|
||||
}
|
||||
|
||||
importSprites(sprites) {
|
||||
this.sprites = sprites;
|
||||
this.sprites = [];
|
||||
for (const sprite of sprites) {
|
||||
console.log(sprite);
|
||||
this.addSprite({ name: sprite.name, bytes: sprite.bytes, mime: sprite.mime });
|
||||
}
|
||||
this.renderList();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user