Browse Source

Allow for drag-and-drop

tags/v0.1.0
Fen Dweller 5 years ago
parent
commit
3706bb1ed5
1 changed files with 26 additions and 10 deletions
  1. +26
    -10
      macrovision.js

+ 26
- 10
macrovision.js View File

@@ -1871,21 +1871,37 @@ document.addEventListener("DOMContentLoaded", () => {


const file = item.getAsFile(); const file = item.getAsFile();


file.arrayBuffer().then(buf => {
arr = new Uint8Array(buf);
blob = new Blob([arr], {type: file.type });
url = window.URL.createObjectURL(blob)
makeCustomEntity(url);
});
customEntityFromFile(file);
}); });

document.querySelector("#world").addEventListener("dragover", e => {
e.preventDefault();
})

document.querySelector("#world").addEventListener("drop", e => {
e.preventDefault();
if (e.dataTransfer.files.length > 0) {
let entX = document.querySelector("#entities").getBoundingClientRect().x;
let entY = document.querySelector("#entities").getBoundingClientRect().y;
let coords = abs2rel({x: e.clientX-entX, y: e.clientY-entY});
customEntityFromFile(e.dataTransfer.files[0], coords.x, coords.y);
}
})
clearEntityOptions(); clearEntityOptions();
clearViewOptions(); clearViewOptions();
clearAttribution(); clearAttribution();
}); });


function makeCustomEntity(url) {
function customEntityFromFile(file, x=0.5, y=0.5) {
file.arrayBuffer().then(buf => {
arr = new Uint8Array(buf);
blob = new Blob([arr], {type: file.type });
url = window.URL.createObjectURL(blob)
makeCustomEntity(url, x, y);
});
}

function makeCustomEntity(url, x=0.5, y=0.5) {
const maker = createEntityMaker( const maker = createEntityMaker(
{ {
name: "Custom Entity" name: "Custom Entity"
@@ -1914,7 +1930,7 @@ function makeCustomEntity(url) {
const entity = maker.constructor(); const entity = maker.constructor();


entity.ephemeral = true; entity.ephemeral = true;
displayEntity(entity, "custom", 0.5, 0.5, true, true);
displayEntity(entity, "custom", x, y, true, true);
} }
function prepareEntities() { function prepareEntities() {
availableEntities["buildings"] = makeBuildings(); availableEntities["buildings"] = makeBuildings();


Loading…
Cancel
Save