Просмотр исходного кода

Add import-from-clipboard button

tags/v0.1.0
Fen Dweller 6 лет назад
Родитель
Сommit
2ff248952b
1 измененных файлов: 30 добавлений и 22 удалений
  1. +30
    -22
      macrovision.js

+ 30
- 22
macrovision.js Просмотреть файл

@@ -1207,10 +1207,15 @@ function prepareMenu() {
icon: "fas fa-link"
},
{
name: "Export",
name: "Export to clipboard",
id: "menu-export",
icon: "fas fa-share"
},
{
name: "Import from clipboard",
id: "menu-import",
icon: "fas fa-share"
},
{
name: "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);

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

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

document.querySelector("#menu-save").addEventListener("click", e => {
saveScene();
});
@@ -2113,11 +2104,28 @@ function linkScene() {
function copyScene() {
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
// probably just have a way to do lookups directly



Загрузка…
Отмена
Сохранить