瀏覽代碼

Add basic custom entity support

You can paste an image into the window to get a temporary entity.
tags/v0.1.0
Fen Dweller 5 年之前
父節點
當前提交
8915ad49fb
共有 1 個檔案被更改,包括 67 行新增1 行删除
  1. +67
    -1
      macrovision.js

+ 67
- 1
macrovision.js 查看文件

@@ -1845,11 +1845,77 @@ document.addEventListener("DOMContentLoaded", () => {
document.querySelector("#menu-load-autosave").addEventListener("click", e => {
loadScene("autosave");
});

document.addEventListener("paste", e => {

let index = 0;
let item = null;
let found = false;

for (; index < e.clipboardData.items.length; index++) {
item = e.clipboardData.items[index];
if (item.type == "image/png") {
found = true;
break;
}
}

if (!found) {
return;
}
console.log(item)
console.log(item.type)

let url = null;

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);
});
});
clearEntityOptions();
clearViewOptions();
clearAttribution();
});

function makeCustomEntity(url) {
const maker = createEntityMaker(
{
name: "Custom Entity"
},
{
custom: {
attributes: {
height: {
name: "Height",
power: 1,
type: "length",
base: math.unit(6, "feet")
}
},
image: {
source: url
},
name: "Image",
info: {},
rename: false
}
},
[]
);

const entity = maker.constructor();

entity.ephemeral = true;
displayEntity(entity, "custom", 0.5, 0.5, true, true);
}
function prepareEntities() {
availableEntities["buildings"] = makeBuildings();
availableEntities["characters"] = makeCharacters();
@@ -2082,7 +2148,7 @@ function exportScene() {

results.entities = [];

Object.entries(entities).forEach(([key, entity]) => {
Object.entries(entities).filter(([key, entity]) => entity.ephemeral !== true).forEach(([key, entity]) => {
const element = document.querySelector("#entity-" + key);
results.entities.push({
name: entity.identifier,


Loading…
取消
儲存