Преглед изворни кода

Add import-from-clipboard button

tags/v0.1.0
Fen Dweller пре 6 година
родитељ
комит
2ff248952b
1 измењених фајлова са 30 додато и 22 уклоњено
  1. +30
    -22
      macrovision.js

+ 30
- 22
macrovision.js Прегледај датотеку

@@ -1207,10 +1207,15 @@ function prepareMenu() {
icon: "fas fa-link" icon: "fas fa-link"
}, },
{ {
name: "Export",
name: "Export to clipboard",
id: "menu-export", id: "menu-export",
icon: "fas fa-share" icon: "fas fa-share"
}, },
{
name: "Import from clipboard",
id: "menu-import",
icon: "fas fa-share"
},
{ {
name: "Save", name: "Save",
id: "menu-save", id: "menu-save",
@@ -1777,24 +1782,6 @@ document.addEventListener("DOMContentLoaded", () => {


}); });


document.addEventListener("paste", e => {
try {
const data = JSON.parse(e.clipboardData.getData("text"));
if (data.entities === undefined) {
return;
}
if (data.world === undefined) {
return;
}

importScene(data);
} catch (err) {
console.error(err);

// probably wasn't valid data
}
});

window.addEventListener("resize", handleResize); window.addEventListener("resize", handleResize);


// TODO: further investigate why the tool initially starts out with wrong // TODO: further investigate why the tool initially starts out with wrong
@@ -1815,6 +1802,10 @@ document.addEventListener("DOMContentLoaded", () => {
copyScene(); copyScene();
}); });


document.querySelector("#menu-import").addEventListener("click", e => {
pasteScene();
});

document.querySelector("#menu-save").addEventListener("click", e => { document.querySelector("#menu-save").addEventListener("click", e => {
saveScene(); saveScene();
}); });
@@ -2113,11 +2104,28 @@ function linkScene() {
function copyScene() { function copyScene() {
const results = exportScene(); const results = exportScene();


navigator.clipboard.writeText(JSON.stringify(results))

alert("Scene copied to clipboard. Paste text into the page to load the scene.");
navigator.clipboard.writeText(JSON.stringify(results));
} }


function pasteScene() {
try {
navigator.clipboard.readText().then(text => {
const data = JSON.parse(text);
if (data.entities === undefined) {
return;
}
if (data.world === undefined) {
return;
}

importScene(data);
}).catch(err => alert(err));
} catch (err) {
console.error(err);

// probably wasn't valid data
}
}
// TODO - don't just search through every single entity // TODO - don't just search through every single entity
// probably just have a way to do lookups directly // probably just have a way to do lookups directly




Loading…
Откажи
Сачувај