From fa108e30dc0dfa4fedf417ce52bb904a4354a180 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Thu, 6 Feb 2020 17:18:58 -0500 Subject: [PATCH] Construct a new entity each time, instead of using the same one repeatedly --- macrovision.js | 9 ++-- presets/buildings.js | 105 +++++++++++++++++++++++++----------------- presets/characters.js | 10 +++- 3 files changed, 77 insertions(+), 47 deletions(-) diff --git a/macrovision.js b/macrovision.js index e6c8e14d..dcc1afd9 100644 --- a/macrovision.js +++ b/macrovision.js @@ -501,6 +501,7 @@ function displayEntity(entity, view, x, y) { box.appendChild(img); box.appendChild(nameTag); + console.log(entity) img.src = entity.views[view].image.source; box.dataset.x = x; @@ -539,12 +540,13 @@ function displayEntity(entity, view, x, y) { } document.addEventListener("DOMContentLoaded", () => { - const stuff = [makeFen()].concat(makeBuildings()) + const stuff = [makeFen].concat( makeBuildings().map(x => x.constructor)) + console.log(stuff) let x = 0.2; stuff.forEach(entity => { - displayEntity(entity, entity.defaultView, x, 1); + displayEntity(entity(), entity().defaultView, x, 1); x += 0.7 / stuff.length; }) @@ -611,7 +613,8 @@ function prepareEntities() { button.innerText = "Create " + category; button.addEventListener("click", e => { - displayEntity(entityList[select.value], entityList[select.value].defaultView, 0.5, 0.5); + const newEntity = entityList[select.value].constructor() + displayEntity(newEntity, newEntity.defaultView, 0.5, 0.5); }); holder.appendChild(select); diff --git a/presets/buildings.js b/presets/buildings.js index 91e48d65..7e688bc7 100644 --- a/presets/buildings.js +++ b/presets/buildings.js @@ -19,48 +19,69 @@ function makeBuilding(name, height, image) { function makeBuildings() { const results = []; - - results.push(makeBuilding( - "Burj Khalifa", - math.unit(829.8, "meter"), - {source: "./media/buildings/burj-khalifa.svg"} - )); - - results.push(makeBuilding( - "Canton Tower", - math.unit(604, "meter"), - {source: "./media/buildings/canton-tower.svg"} - )); - - results.push(makeBuilding( - "CN Tower", - math.unit(553.3, "meter"), - {source: "./media/buildings/cn-tower.svg"} - )); - - results.push(makeBuilding( - "Taipei 101", - math.unit(509.2, "meter"), - {source: "./media/buildings/taipei-101.svg"} - )); - - results.push(makeBuilding( - "Empire State Building", - math.unit(443.2, "meter"), - {source: "./media/buildings/empire-state-building.svg"} - )); - - results.push(makeBuilding( - "Eiffel Tower", - math.unit(324, "meter"), - {source: "./media/buildings/eiffel-tower.svg"} - )); - - results.push(makeBuilding( - "Chrysler Building", - math.unit(318.9, "meter"), - {source: "./media/buildings/chrysler-building.svg"} - )); + + results.push({ + name: "Burj Khalifa", + constructor: () => makeBuilding( + "Burj Khalifa", + math.unit(829.8, "meter"), + { source: "./media/buildings/burj-khalifa.svg" } + ) + }); + + results.push({ + name: "Canton Tower", + constructor: () => makeBuilding( + "Canton Tower", + math.unit(604, "meter"), + { source: "./media/buildings/canton-tower.svg" } + ) + }); + + results.push({ + name: "CN Tower", + constructor: () => makeBuilding( + "CN Tower", + math.unit(553.3, "meter"), + { source: "./media/buildings/cn-tower.svg" } + ) + }); + + results.push({ + name: "Taipei 101", + constructor: () => makeBuilding( + "Taipei 101", + math.unit(509.2, "meter"), + { source: "./media/buildings/taipei-101.svg" } + ) + }); + + results.push({ + name: "Empire State Building", + constructor: () => makeBuilding( + "Empire State Building", + math.unit(443.2, "meter"), + { source: "./media/buildings/empire-state-building.svg" } + ) + }); + + results.push({ + name: "Eiffel Tower", + constructor: () => makeBuilding( + "Eiffel Tower", + math.unit(324, "meter"), + { source: "./media/buildings/eiffel-tower.svg" } + ) + }); + + results.push({ + name: "Chrysler Building", + constructor: () => makeBuilding( + "Chrysler Building", + math.unit(318.9, "meter"), + { source: "./media/buildings/chrysler-building.svg" } + ) + }); return results; } \ No newline at end of file diff --git a/presets/characters.js b/presets/characters.js index df2ac57a..1dadea9e 100644 --- a/presets/characters.js +++ b/presets/characters.js @@ -86,7 +86,13 @@ function makeMan() { function makeCharacters() { const results = []; - results.push(makeFen()); - results.push(makeMan()); + results.push({ + name: "Fen", + constructor: makeFen + }); + results.push({ + name: "Normal man", + constructor: makeMan + }); return results; } \ No newline at end of file