Przeglądaj źródła

Add export/import. Remove generic person silhouette

tags/v0.1.0
Fen Dweller 6 lat temu
rodzic
commit
5ce1dc3010
3 zmienionych plików z 90 dodań i 5 usunięć
  1. +3
    -0
      macrovision.html
  2. +86
    -0
      macrovision.js
  3. +1
    -5
      presets/characters.js

+ 3
- 0
macrovision.html Wyświetl plik

@@ -29,6 +29,9 @@
<span class="menubar-group"> <span class="menubar-group">
<button id="menu-order-height">Order by height</button> <button id="menu-order-height">Order by height</button>
</span> </span>
<span class="menubar-group">
<button id="menu-export">Export Scene</button>
</span>
<span class="menubar-group" id="spawners"> <span class="menubar-group" id="spawners">


</span> </span>


+ 86
- 0
macrovision.js Wyświetl plik

@@ -210,6 +210,7 @@ function drawScale() {
function makeEntity(name, author, views) { function makeEntity(name, author, views) {
const entityTemplate = { const entityTemplate = {
name: name, name: name,
identifier: name,
author: author, author: author,
scale: 1, scale: 1,
views: views, views: views,
@@ -814,6 +815,29 @@ document.addEventListener("DOMContentLoaded", () => {
altHeld = false; altHeld = false;
} }
}); });
document.addEventListener("paste", e => {
try {
const data = JSON.parse(e.clipboardData.getData("text"));
console.log(data)
if (data.entities === undefined) {
return;
}
if (data.world === undefined) {
return;
}

importScene(data);
} catch(err) {
console.error(err);
// probably wasn't valid data
}
});

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


function prepareEntities() { function prepareEntities() {
@@ -959,3 +983,65 @@ function setWorldHeight(oldHeight, newHeight) {


updateSizes(); updateSizes();
} }

function exportScene() {
const results = {};

results.entities = [];

Object.entries(entities).forEach(([key, entity]) => {
const element = document.querySelector("#entity-" + key);
results.entities.push({
name: entity.identifier,
scale: entity.scale,
view: entity.view,
x: element.dataset.x,
y: element.dataset.y
});
});

const unit = document.querySelector("#options-height-unit").value;
results.world = {
height: config.height.toNumber(unit),
unit: unit
}

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

alert("Scene copied to clipboard. Paste text into the page to load the scene.");
}

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

function findEntity(name) {
const groups = Object.values(availableEntities);
for (let i = 0; i < groups.length; i++) {
const entityGroup = groups[i];
for (let j = 0; j < entityGroup.length; j++) {
const candidate = entityGroup[j];
if (candidate.name === name) {
return candidate;
}
}
}

return null;
}

function importScene(data) {
removeAllEntities();

data.entities.forEach(entityInfo => {
console.log(findEntity(entityInfo.name))
const entity = findEntity(entityInfo.name).constructor();
entity.scale = entityInfo.scale
displayEntity(entity, entityInfo.view, entityInfo.x, entityInfo.y);
});

config.height = math.unit(data.world.height, data.world.unit);
document.querySelector("#options-height-unit").value = data.world.unit;

updateSizes();
}

+ 1
- 5
presets/characters.js Wyświetl plik

@@ -1195,7 +1195,7 @@ function makeMan() {
} }
}; };


return makeEntity("Man", "Fen", views);
return makeEntity("Normal Man", "Fen", views);
} }


characterMakers["North"] = () => { characterMakers["North"] = () => {
@@ -2447,10 +2447,6 @@ function makeCharacters() {
name: "Sefer", name: "Sefer",
constructor: makeSefer constructor: makeSefer
}); });
results.push({
name: "Normal man",
constructor: makeMan
});


Object.entries(characterMakers).forEach(([key, value]) => { Object.entries(characterMakers).forEach(([key, value]) => {
results.push({ results.push({


Ładowanie…
Anuluj
Zapisz