From d9994b8768238573af26fbe3e3e799b2091297e6 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Thu, 20 Feb 2020 10:47:46 -0500 Subject: [PATCH] Restructure how entities are created Each entity now has an info object, a views list, and a sizes list. This will allow for more complex bio/description text --- macrovision.js | 17 ++--- presets/buildings.js | 16 +++-- presets/characters.js | 155 +++++++++++++++++------------------------- presets/cities.js | 4 +- presets/landmarks.js | 4 +- presets/naturals.js | 3 +- presets/objects.js | 4 +- presets/vehicles.js | 4 +- 8 files changed, 86 insertions(+), 121 deletions(-) diff --git a/macrovision.js b/macrovision.js index 590ea9c1..2309f702 100644 --- a/macrovision.js +++ b/macrovision.js @@ -214,14 +214,14 @@ function drawScale() { drawTicks(ctx, pixelsPer, heightPer); } -function makeEntity(name, author, views) { +function makeEntity(info, views, sizes) { const entityTemplate = { - name: name, - identifier: name, - author: author, + name: info.name, + identifier: info.name, scale: 1, + info: info, views: views, - defaults: [], + sizes: sizes === undefined ? [] : sizes, init: function () { Object.entries(this.views).forEach(([viewKey, view]) => { view.parent = this; @@ -405,7 +405,7 @@ function configEntityOptions(entity, view) { defaultHolder.innerHTML = ""; - entity.defaults.forEach(defaultInfo => { + entity.sizes.forEach(defaultInfo => { const button = document.createElement("button"); button.classList.add("options-button"); @@ -709,7 +709,6 @@ document.addEventListener("DOMContentLoaded", () => { } unitSelector.appendChild(option); - console.log(option) }); const stuff = availableEntities.characters.map(x => x.constructor).filter(x => { @@ -868,7 +867,6 @@ document.addEventListener("DOMContentLoaded", () => { document.addEventListener("paste", e => { try { const data = JSON.parse(e.clipboardData.getData("text")); - console.log(data) if (data.entities === undefined) { return; } @@ -1066,15 +1064,12 @@ function setWorldHeight(oldHeight, newHeight) { const element = document.querySelector("#entity-" + key); let newPosition; - console.log("###"); - console.log({ x: element.dataset.x, y: element.dataset.y }); if (!altHeld) { newPosition = adjustAbs({ x: element.dataset.x, y: element.dataset.y }, oldHeight, config.height); } else { newPosition = { x: element.dataset.x, y: element.dataset.y }; } - console.log(newPosition); element.dataset.x = newPosition.x; element.dataset.y = newPosition.y; }); diff --git a/presets/buildings.js b/presets/buildings.js index 5387e8a6..774b5b29 100644 --- a/presets/buildings.js +++ b/presets/buildings.js @@ -24,7 +24,7 @@ function makeBuilding(name, height, image) { }, }; - return makeEntity(name, "Building", views); + return makeEntity({name: name}, views); } @@ -44,25 +44,27 @@ function makeSkyscraper(name, image, startingSize) { }, }; - const entity = makeEntity(name, "Skyscraper", views); + const sizes = []; - entity.defaults.push({ + sizes.push({ name: "Short", height: math.unit(15, "stories") }); - entity.defaults.push({ + sizes.push({ name: "Medium", height: math.unit(40, "stories") }); - entity.defaults.push({ + sizes.push({ name: "Supertall", height: math.unit(350, "meters") }); - entity.defaults.push({ + sizes.push({ name: "Megatall", height: math.unit(650, "meters") }); + const entity = makeEntity({name: name}, views, sizes); + entity.views[entity.defaultView].height = startingSize; return entity; } @@ -148,4 +150,4 @@ function makeBuildings() { }); return results; -} \ No newline at end of file +} diff --git a/presets/characters.js b/presets/characters.js index 4a08a0c5..db839cc6 100644 --- a/presets/characters.js +++ b/presets/characters.js @@ -35,11 +35,7 @@ function makeCharacter(name, author, viewInfo, defaultSizes, defaultSize) { } }); - const entity = makeEntity(name, "author", views); - - if (defaultSizes) { - entity.defaults = defaultSizes; - } + const entity = makeEntity({name: name}, views, defaultSizes); if (defaultSize) { entity.views[entity.defaultView].height = defaultSize; @@ -184,34 +180,34 @@ function makeMarch() { } }; - const entity = makeEntity("March", "March-Dragon", views); + const entity = makeEntity({name: "March", author: "March-Dragon"}, views, []); - entity.defaults.push({ + entity.sizes.push({ name: "Normal", height: math.unit(7.9, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(220, "meters") }); - entity.defaults.push({ + entity.sizes.push({ name: "Megamacro", height: math.unit(2.98, "km") }); - entity.defaults.push({ + entity.sizes.push({ name: "Gigamacro", height: math.unit(15963, "km") }); - entity.defaults.push({ + entity.sizes.push({ name: "Teramacro", height: math.unit(2980000000, "kilometers") }); - entity.defaults.push({ + entity.sizes.push({ name: "Examacro", height: math.unit(250, "parsecs") }); @@ -245,34 +241,34 @@ function makeNoir() { } }; - const entity = makeEntity("Noir", "March-Dragon", views); + const entity = makeEntity({name: "Noir", author: "March-Dragon"}, views, []); - entity.defaults.push({ + entity.sizes.push({ name: "Normal", height: math.unit(6.6, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(500, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Megamacro", height: math.unit(2.5, "km") }); - entity.defaults.push({ + entity.sizes.push({ name: "Gigamacro", height: math.unit(22500, "km") }); - entity.defaults.push({ + entity.sizes.push({ name: "Teramacro", height: math.unit(2500000000, "kilometers") }); - entity.defaults.push({ + entity.sizes.push({ name: "Examacro", height: math.unit(200, "parsecs") }); @@ -325,7 +321,7 @@ function makeOkuri() { } }; - const entity = makeEntity("Okuri", "OrionMechadragon", views); + const entity = makeEntity({name: "Okuri", author: "OrionMechadragon"}, views, []); entity.views.front.height = math.unit(100, "miles"); return entity; } @@ -374,25 +370,25 @@ function makeManny() { } }; - const entity = makeEntity("Manny", "Dialuca01", views); + const entity = makeEntity({name: "Manny", author: "Dialuca01"}, views, []); - entity.defaults.push({ + entity.sizes.push({ name: "Normal", height: math.unit(7, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(78, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro+", height: math.unit(300, "meters") }); - entity.defaults.push({ + entity.sizes.push({ name: "Megamacro", height: math.unit(5167, "meters") }); - entity.defaults.push({ + entity.sizes.push({ name: "Gigamacro", height: math.unit(41769, "miles") }); @@ -487,25 +483,25 @@ function makeAdake() { }, }; - const entity = makeEntity("Adake", "Dialuca01", views); + const entity = makeEntity({name: "Adake", author: "Dialuca01"}, views, []); - entity.defaults.push({ + entity.sizes.push({ name: "Normal", height: math.unit(7, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(78, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro+", height: math.unit(300, "meters") }); - entity.defaults.push({ + entity.sizes.push({ name: "Megamacro", height: math.unit(5167, "meters") }); - entity.defaults.push({ + entity.sizes.push({ name: "Gigamacro", height: math.unit(41769, "miles") }); @@ -552,19 +548,19 @@ function makeElijah() { } }; - const entity = makeEntity("Elijah", "Elijah", views); + const entity = makeEntity({name: "Elijah", author: "Elijah"}, views, []); - entity.defaults.push({ + entity.sizes.push({ name: "Normal", height: math.unit(1.65, "meters") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(55, "meters") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro+", height: math.unit(105, "meters") }); @@ -637,7 +633,7 @@ function makeRai() { } }; - const entity = makeEntity("Rai", "shadowblade945", views); + const entity = makeEntity({name: "Rai", author: "shadowblade945"}, views, []); entity.views.front.height = math.unit(302, "feet"); return entity; } @@ -687,7 +683,7 @@ function makeJazzy() { } }; - const entity = makeEntity("Jazzy", "Jazzywolf", views); + const entity = makeEntity({name: "Jazzy", author: "Jazzywolf"}, views, []); entity.views.front.height = math.unit(216, "feet"); return entity; } @@ -716,14 +712,14 @@ function makeFlamm() { } }; - const entity = makeEntity("Flamm", "Flamm", views); + const entity = makeEntity({name: "Flamm", author: "Flamm"}, views, []); - entity.defaults.push({ + entity.sizes.push({ name: "Normal", height: math.unit(9.5, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(200, "feet") }); @@ -796,20 +792,20 @@ function makeZephiro() { } }; - const entity = makeEntity("Zephiro", "Zephiro", views); + const entity = makeEntity({name: "Zephiro", author: "Zephiro"}, views, []); entity.views.front.height = math.unit(118, "feet"); - entity.defaults.push({ + entity.sizes.push({ name: "Micro", height: math.unit(3, "inches") }); - entity.defaults.push({ + entity.sizes.push({ name: "Normal", height: math.unit(5 + 3/12, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(118, "feet") }); @@ -841,15 +837,15 @@ function makeFory() { } }; - const entity = makeEntity("Fory", "Manny", views); + const entity = makeEntity({name: "Fory", author: "Manny"}, views, []); - entity.defaults.push({ + entity.sizes.push({ name: "Normal", height: math.unit(5, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(50, "feet") }); @@ -945,7 +941,7 @@ function makeKurrikage() { } }; - const entity = makeEntity("Kurrikage", "Kurrikage", views); + const entity = makeEntity({name: "Kurrikage", author: "Kurrikage"}, views, []); entity.views.front.height = math.unit(12, "feet"); return entity; } @@ -974,19 +970,19 @@ function makeShingo() { } }; - const entity = makeEntity("Shingo", "Threes", views); + const entity = makeEntity({name: "Shingo", author: "Threes"}, views, []); - entity.defaults.push({ + entity.sizes.push({ name: "Micro", height: math.unit(4, "inches") }); - entity.defaults.push({ + entity.sizes.push({ name: "Normal", height: math.unit(6, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(108, "feet") }); @@ -1017,14 +1013,14 @@ function makeAigey() { } }; - const entity = makeEntity("Aigey", "Aigey", views); + const entity = makeEntity({name: "Aigey", author: "Aigey"}, views, []); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(200, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Megamacro", height: math.unit(100, "miles") }); @@ -1058,28 +1054,28 @@ function makeNatasha() { } }; - const entity = makeEntity("Natasha", "Natasha", views); + const entity = makeEntity({name: "Natasha", author: "Natasha"}, views, []); - entity.defaults.push({ + entity.sizes.push({ name: "Normal", height: math.unit(5 + 5/12, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Large", height: math.unit(12, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(100, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro+", height: math.unit(260, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro++", height: math.unit(1, "mile") }); @@ -1154,14 +1150,14 @@ function makeMalik() { }, }; - const entity = makeEntity("Malik", "Fuzzypaws", views); + const entity = makeEntity({name: "Malik", author: "Fuzzypaws"}, views, []); - entity.defaults.push({ + entity.sizes.push({ name: "Macro", height: math.unit(156, "feet") }); - entity.defaults.push({ + entity.sizes.push({ name: "Macro+", height: math.unit(1188, "feet") }); @@ -1215,40 +1211,13 @@ function makeSefer() { }, }; - const entity = makeEntity("Sefer", "Fuzzypaws", views); + const entity = makeEntity({name: "Sefer", author: "Fuzzypaws"}, views, []); entity.views[entity.defaultView].height = math.unit(6, "feet"); return entity; } -function makeMan() { - const views = { - body: { - attributes: { - height: { - name: "Height", - power: 1, - type: "length", - base: math.unit(2, "meter") - }, - weight: { - name: "Weight", - power: 3, - type: "mass", - base: math.unit(80, "kg") - } - }, - image: { - source: "./man.svg" - }, - name: "Body" - } - }; - - return makeEntity("Normal Man", "Fen", views); -} - characterMakers["North"] = () => { return makeCharacter( "North", diff --git a/presets/cities.js b/presets/cities.js index 92c53dfc..daa9b67f 100644 --- a/presets/cities.js +++ b/presets/cities.js @@ -19,7 +19,7 @@ function makeCity(name, height) { console.log(views) - return makeEntity(name, "City", views); + return makeEntity({name: name}, views); } function addCity(name, height) { @@ -78,4 +78,4 @@ function makeCities() { }); return results; -} \ No newline at end of file +} diff --git a/presets/landmarks.js b/presets/landmarks.js index eafebae8..bd997ae4 100644 --- a/presets/landmarks.js +++ b/presets/landmarks.js @@ -14,7 +14,7 @@ function makeLandmark(name, height, image) { }, }; - return makeEntity(name, "Building", views); + return makeEntity({name: name}, views); } function makeLandmarks() { @@ -99,4 +99,4 @@ function makeLandmarks() { }); return results; -} \ No newline at end of file +} diff --git a/presets/naturals.js b/presets/naturals.js index 018a2f7f..4c5d8fe9 100644 --- a/presets/naturals.js +++ b/presets/naturals.js @@ -2,8 +2,7 @@ function makeState(name, height, width, area) { return { name: name, constructor: () => makeEntity( - name, - "State", + {name: name}, { state: { attributes: { diff --git a/presets/objects.js b/presets/objects.js index 35a2a5fa..a10f4064 100644 --- a/presets/objects.js +++ b/presets/objects.js @@ -25,7 +25,7 @@ function makeObject(name, viewInfo) { } }); - return makeEntity(name, "Object", views); + return makeEntity({name: name}, views); } function makeObjects() { @@ -66,4 +66,4 @@ function makeObjects() { }); return results; -} \ No newline at end of file +} diff --git a/presets/vehicles.js b/presets/vehicles.js index 2ba20122..6d52d697 100644 --- a/presets/vehicles.js +++ b/presets/vehicles.js @@ -24,7 +24,7 @@ function makeVehicle(name, sides, mass) { } }); - return makeEntity(name, "Vehicle", views); + return makeEntity({name: name}, views); } function makeVehicles() { @@ -102,4 +102,4 @@ function makeVehicles() { }); return results; -} \ No newline at end of file +}