www.spaceplanner.app

Web client to the spaceplanner API
git clone git://jacobedwards.org/www.spaceplanner.app
Log | Files | Refs

commit 7897a84026f4699724fa5b0b7048753933bbea6d
parent 3bf4e95c18cee5aa2fc7757588d56d4aa91531a4
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Mon, 26 Aug 2024 13:20:49 -0700

Add wall subdivision handler

Double click on a wall to subdivide it on your cursor.

Diffstat:
Mfiles/floorplans/floorplan/main.js | 43+++++++++++++++++++++++++++++++++++++++----
1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js @@ -229,11 +229,10 @@ let modes = { handlers: { contextmenu: preventDefaultHandler, mousedown: [selectionHandler, precisePointHandler], - mousemove: precisePointHandler, + mousemove: [precisePointHandler, precisePointMapHandler], mouseup: precisePointHandler, - keydown: [zoomKeysHandler, undoRedoHandler, precisePointHandler], - click: precisePointHandler, - dblclick: precisePointHandler, + keydown: [zoomKeysHandler, undoRedoHandler], + dblclick: precisePointMapHandler } } } @@ -556,6 +555,42 @@ function precisePointHandler(event, editor, state) { event.preventDefault() } +// mousedown, mousemove, mouseup +function precisePointMapHandler(event, editor) { + // Explicitly check button in case UA isn't complient + if (event.type === "dblclick" && event.button == buttons.left) { + let cursor = editor.draw.point(event.clientX, event.clientY).vec() + if (editor.thingAt(cursor, "#points")) { + return + } + + let map = editor.thingAt(cursor, "#pointmaps") + if (map == null) { + return + } + + // Shouldn't really use backend as it's only correct when updateDisplay is called + let data = editor.backend.reqId("pointmaps", lib.getId(map)) + if (data.type != "wall") { + throw new Error("Changing direction of doors not yet supported") + } + + event.preventDefault() + + let sub = map.whereIsPoint(cursor.x, cursor.y) + if (sub == null) { + throw new Error("Expected point on line") + } + + sub = editor.addPoint(sub) + console.log(data, sub) + editor.mapPoints("wall", data.a, sub) + editor.mapPoints("wall", sub, data.b) + editor.remove(map) + editor.updateDisplay() + } +} + function parseUserLength(editor, length) { let a = length.replaceAll(" ", "").split(/([0-9]+)/) let amount