Small UI fixes and finetuned quadtree settings

This commit is contained in:
Peaceultime 2024-06-13 23:22:14 +02:00
parent 209a070464
commit 8f0100c466
2 changed files with 19 additions and 12 deletions

View File

@ -37,25 +37,32 @@ Renderer.scene.add(Asset.instance);
Renderer.startRendering(); Renderer.startRendering();
Input.onDragStart((_, button) => { if(button & 1) Selector.hide(); }); Input.onDragStart((_, button) => { if(button & 1) Selector.hide(); });
Input.onDragEnd((start, end, button) => { Input.onDragEnd((s, e, button) => {
if(button & 1) if(button & 1)
{ {
const s = performance.now(); const n = performance.now();
const selection = quad.query({x1: Math.min(start.x, end.x), x2: Math.max(start.x, end.x), y1: Math.min(start.y, end.y), y2: Math.max(start.y, end.y)}).map(e => Asset.assets[e]); const selection = quad.query({x1: Math.min(s.x, e.x), x2: Math.max(s.x, e.x), y1: Math.min(s.y, e.y), y2: Math.max(s.y, e.y)}).map(e => Asset.assets[e]);
console.log("Fetching %s out of %s elements in %sms", selection.length, Asset.assets.length, performance.now() - s); console.log("Fetching %s out of %s elements in %sms", selection.length, Asset.assets.length, performance.now() - n);
if(Input.keys['Shift']) Selector.toggle(selection); if(Input.keys['Shift']) Selector.toggle(selection);
else Selector.select(selection); else Selector.select(selection);
} }
}); });
Input.onDrag((delta, start, end, button) => { if(button & 1) Selector.preview(start, end); else Renderer.move(-delta.x, -delta.y); }); Input.onDrag((delta, start, end, button) => { if(button & 1) Selector.preview(start, end); else Renderer.move(-delta.x, -delta.y); });
Input.onClick((point, button) => { Input.onClick((p, button) => {
if(button & 1) if(button & 1)
{ {
const selection = quad.fetch(point.x, point.y).map(e => Asset.assets[e]); const selection = quad.fetch(p.x, p.y)[0];
if(Input.keys['Shift']) Selector.toggle(selection); if (selection === undefined)
else Selector.select(selection); {
if (!Input.keys['Shift'])
Selector.clear();
return;
}
if (Input.keys['Shift']) Selector.toggle([Asset.assets[selection]]);
else Selector.select([Asset.assets[selection]]);
} }
}); });
Input.onWheel(delta => Renderer.zoom = clamp(Renderer.zoom * 1 + (delta * -0.001), 0.9, 5)); Input.onWheel(delta => Renderer.zoom = clamp(Renderer.zoom * 1 + (delta * -0.001), 0.9, 5));

View File

@ -114,16 +114,16 @@ export default class Input
static #mousemove(e: MouseEvent): void static #mousemove(e: MouseEvent): void
{ {
e.preventDefault(); e.preventDefault();
const cursor = Renderer.screenSpaceToCameraSpace(e.clientX, e.clientY);
const cursorOmitted = Renderer.screenSpaceToCameraSpace(e.clientX, e.clientY, true);
if(Input.#dragging && !Input.#dragStarted) if(Input.#dragging && !Input.#dragStarted && cursor.x !== this.#dragInitPos.x && cursor.y !== this.#dragInitPos.y)
{ {
Input.#dragStartCb && Input.#dragStartCb(Input.#dragInitPos, e.buttons); Input.#dragStartCb && Input.#dragStartCb(Input.#dragInitPos, e.buttons);
Input.#dragStarted = true; Input.#dragStarted = true;
} }
const cursor = Renderer.screenSpaceToCameraSpace(e.clientX, e.clientY);
const cursorOmitted = Renderer.screenSpaceToCameraSpace(e.clientX, e.clientY, true);
Input.#cursor = cursor; Input.#cursor = cursor;
if(Input.dragging) if(Input.dragging)