From ccad30569aac79211832dfd5a0fea4fab19cbda7 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sun, 31 May 2020 15:34:01 -0400 Subject: [PATCH] Make autosize logic more consistent Everything should be passing a list of entities to a function that computes a bounding box and fits things now. --- macrovision.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/macrovision.js b/macrovision.js index 58071b05..3b184697 100644 --- a/macrovision.js +++ b/macrovision.js @@ -1587,6 +1587,11 @@ const settingsData = { }, } +function getBoundingBox(entities, margin = 0.05) { + +} + + function prepareSettings(userSettings) { const menubar = document.querySelector("#settings-menu"); @@ -2246,14 +2251,9 @@ document.addEventListener("DOMContentLoaded", () => { }); document.querySelector("#fit").addEventListener("click", e => { - const x = parseFloat(selected.dataset.x); - const y = parseFloat(selected.dataset.y); - config.x = x; - config.y = y; - - const entity = entities[selected.dataset.key]; - const height = math.multiply(entity.views[entity.view].height, 1.1); - setWorldHeight(config.height, height); + if (selected) { + fitEntities([selected]); + } }); document.querySelector("#fit").addEventListener("mousedown", e => { @@ -2684,14 +2684,18 @@ function prepareEntities() { const worldWidth = config.height.toNumber("meters") / canvasHeight * canvasWidth; - makers.map(element => { + const spawned = makers.map(element => { const category = document.querySelector("#category-picker").value; const maker = availableEntities[category][element.value]; const entity = maker.constructor() displayEntity(entity, entity.view, -worldWidth * 0.45 + config.x + worldWidth * 0.9 * index / (count - 1), config.y); index += 1; + entity; }); updateSizes(true); + + if (config.autoFitAdd) + fitEntities(spawned); }); Array.from(filterSets[filter.id]).map(name => [name, filter.render(name)]).sort(filterDefs[filter.id].sort).forEach(name => { @@ -2920,6 +2924,10 @@ function checkFitWorld() { } function fitWorld(manual = false, factor = 1.1) { + fitEntities(entities, factor); +} + +function fitEntities(manual = false, factor = 1.1) { let minX = Infinity; let maxX = -Infinity; let minY = Infinity; @@ -2943,6 +2951,8 @@ function fitWorld(manual = false, factor = 1.1) { let width = image.width; let height = image.height; + console.log(width, height); + // only really relevant if the images haven't loaded in yet if (height == 0) { height = 100;