From 16c1bc15213ddcc42f2638c6cedd376c7d40c50d Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sun, 19 Apr 2020 22:23:34 -0400 Subject: [PATCH] Keep horizontal positioning consistent between window widths --- macrovision.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/macrovision.js b/macrovision.js index 62688e06..38043433 100644 --- a/macrovision.js +++ b/macrovision.js @@ -114,6 +114,7 @@ const unitChoices = { "humans", "stories", "miles", + "earths", "solarradii", "AUs", "lightyears", @@ -1166,12 +1167,27 @@ function toggleFullScreen() { } function handleResize() { + const oldEntityX = entityX; entityX = document.querySelector("#entities").getBoundingClientRect().x; + + const change = oldEntityX / entityX; + + doHorizReposition(change); + + canvasWidth = document.querySelector("#display").clientWidth - 100; canvasHeight = document.querySelector("#display").clientHeight - 50; updateSizes(); } +function doHorizReposition(change) { + Object.keys(entities).forEach(key => { + const element = document.querySelector("#entity-" + key); + const x = element.dataset.x; + element.dataset.x = (x - 0.5) * change + 0.5; + }); +} + function prepareMenu() { const menubar = document.querySelector("#popout-menu"); @@ -2084,6 +2100,8 @@ function exportScene() { unit: unit } + results.entityX = entityX; + return results; } @@ -2160,5 +2178,9 @@ function importScene(data) { config.height = math.unit(data.world.height, data.world.unit); document.querySelector("#options-height-unit").value = data.world.unit; + if (data.entityX) { + doHorizReposition(data.entityX / entityX); + } + updateSizes(); }