Sfoglia il codice sorgente

Add a button to order entities by height

tags/v0.0.3
Fen Dweller 5 anni fa
parent
commit
b9ff268133
2 ha cambiato i file con 27 aggiunte e 0 eliminazioni
  1. +1
    -0
      macrovision.html
  2. +26
    -0
      macrovision.js

+ 1
- 0
macrovision.html Vedi File

@@ -21,6 +21,7 @@
<body class="toggle-bottom-name toggle-entity-name">
<div id="menubar">
<button id="menu-clear">Clear</button>
<button id="menu-order">Order by height</button>
</div>
<div id="main-area">
<div id="options">


+ 26
- 0
macrovision.js Vedi File

@@ -483,6 +483,17 @@ function testClick(event) {
}
}

function arrangeEntities(order) {
let x = 0.1;

order.forEach(key => {
document.querySelector("#entity-" + key).dataset.x = x;
x += 0.8 / order.length
});

updateSizes();
}

function removeAllEntities() {
Object.keys(entities).forEach(key => {
removeEntity(document.querySelector("#entity-" + key));
@@ -599,6 +610,21 @@ document.addEventListener("DOMContentLoaded", () => {
document.querySelector("#menu-clear").addEventListener("click", e => {
removeAllEntities();
});

document.querySelector("#menu-order").addEventListener("click", e => {
const order = Object.keys(entities).sort((a,b) => {
const entA = entities[a];
const entB = entities[b];
const viewA = document.querySelector("#entity-" + a).dataset.view;
const viewB = document.querySelector("#entity-" + b).dataset.view;
const heightA = entA.views[viewA].height.to("meter").value;
const heightB = entB.views[viewB].height.to("meter").value;
return heightA - heightB;
});

arrangeEntities(order);
});

prepareEntities();
});



Loading…
Annulla
Salva