Просмотр исходного кода

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.
master
Fen Dweller 5 лет назад
Родитель
Сommit
ccad30569a
1 измененных файлов: 19 добавлений и 9 удалений
  1. +19
    -9
      macrovision.js

+ 19
- 9
macrovision.js Просмотреть файл

@@ -1587,6 +1587,11 @@ const settingsData = {
}, },
} }


function getBoundingBox(entities, margin = 0.05) {

}


function prepareSettings(userSettings) { function prepareSettings(userSettings) {
const menubar = document.querySelector("#settings-menu"); const menubar = document.querySelector("#settings-menu");


@@ -2246,14 +2251,9 @@ document.addEventListener("DOMContentLoaded", () => {
}); });


document.querySelector("#fit").addEventListener("click", e => { 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 => { document.querySelector("#fit").addEventListener("mousedown", e => {
@@ -2684,14 +2684,18 @@ function prepareEntities() {


const worldWidth = config.height.toNumber("meters") / canvasHeight * canvasWidth; const worldWidth = config.height.toNumber("meters") / canvasHeight * canvasWidth;


makers.map(element => {
const spawned = makers.map(element => {
const category = document.querySelector("#category-picker").value; const category = document.querySelector("#category-picker").value;
const maker = availableEntities[category][element.value]; const maker = availableEntities[category][element.value];
const entity = maker.constructor() const entity = maker.constructor()
displayEntity(entity, entity.view, -worldWidth * 0.45 + config.x + worldWidth * 0.9 * index / (count - 1), config.y); displayEntity(entity, entity.view, -worldWidth * 0.45 + config.x + worldWidth * 0.9 * index / (count - 1), config.y);
index += 1; index += 1;
entity;
}); });
updateSizes(true); 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 => { 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) { function fitWorld(manual = false, factor = 1.1) {
fitEntities(entities, factor);
}

function fitEntities(manual = false, factor = 1.1) {
let minX = Infinity; let minX = Infinity;
let maxX = -Infinity; let maxX = -Infinity;
let minY = Infinity; let minY = Infinity;
@@ -2943,6 +2951,8 @@ function fitWorld(manual = false, factor = 1.1) {
let width = image.width; let width = image.width;
let height = image.height; let height = image.height;


console.log(width, height);

// only really relevant if the images haven't loaded in yet // only really relevant if the images haven't loaded in yet
if (height == 0) { if (height == 0) {
height = 100; height = 100;


Загрузка…
Отмена
Сохранить