Explorar el Código

Don't snap things back in-bounds if they've never been in-bounds yet

This way, if you slightly adjust where an object is, you won't need to hold
alt the whole time. This also makes pressing alt reset this behavior, so if you
hold alt, drag out of bounds, release alt, and then move, you won't be thrown back
in-bounds.
master
Fen Dweller hace 6 años
padre
commit
d843a33b32
Se han modificado 1 ficheros con 14 adiciones y 1 borrados
  1. +14
    -1
      macrovision.js

+ 14
- 1
macrovision.js Ver fichero

@@ -4,6 +4,7 @@ let selectedEntity = null;
let entityIndex = 0; let entityIndex = 0;


let clicked = null; let clicked = null;
let movingInBounds = false;
let dragging = false; let dragging = false;
let clickTimeout = null; let clickTimeout = null;
let dragOffsetX = null; let dragOffsetX = null;
@@ -597,6 +598,7 @@ function combineInfo(existing, next) {


function clickDown(target, x, y) { function clickDown(target, x, y) {
clicked = target; clicked = target;
movingInBounds = false;
const rect = target.getBoundingClientRect(); const rect = target.getBoundingClientRect();
let entX = document.querySelector("#entities").getBoundingClientRect().x; let entX = document.querySelector("#entities").getBoundingClientRect().x;
let entY = document.querySelector("#entities").getBoundingClientRect().y; let entY = document.querySelector("#entities").getBoundingClientRect().y;
@@ -2308,6 +2310,7 @@ document.addEventListener("DOMContentLoaded", () => {
e.preventDefault(); e.preventDefault();
} else if (e.key == "Alt") { } else if (e.key == "Alt") {
altHeld = true; altHeld = true;
movingInBounds = false; // don't snap the object back in bounds when we let go
e.preventDefault(); e.preventDefault();
} }
}); });
@@ -2879,7 +2882,17 @@ function clearFilter() {


document.addEventListener("mousemove", (e) => { document.addEventListener("mousemove", (e) => {
if (clicked) { if (clicked) {
const position = snapPos(pix2pos({ x: e.clientX - dragOffsetX, y: e.clientY - dragOffsetY }));
let position = pix2pos({ x: e.clientX - dragOffsetX, y: e.clientY - dragOffsetY });

if (movingInBounds) {
position = snapPos(position);
} else {
let x = e.clientX - dragOffsetX;
let y = e.clientY - dragOffsetY;
if (x >= 0 && x <= canvasWidth && y >= 0 && y <= canvasHeight) {
movingInBounds = true;
}
}
clicked.dataset.x = position.x; clicked.dataset.x = position.x;
clicked.dataset.y = position.y; clicked.dataset.y = position.y;
updateEntityElement(entities[clicked.dataset.key], clicked); updateEntityElement(entities[clicked.dataset.key], clicked);


Cargando…
Cancelar
Guardar