commit 3fd48b0db3dce1e34a3e3c0b2d7d120472d16e57
parent 1459ee837ac79711a99cc41e2f0b7be4cf44f518
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Mon, 23 Sep 2024 10:27:16 -0700
Provide user interface to door swings
You can click on a door, drag, then release to set the door's swing.
The door's hinge is determined by which side of the line you click
on, the swing direction is determined by where you release the mouse
button.
Diffstat:
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js
@@ -643,7 +643,12 @@ function precisePointMapHandler(event, editor, state) {
if (state.door && event.type === "mouseup") {
handled(event)
- editor.backend.mapPoints(state.door.type, state.door.a, state.door.b, { door_swing: state.hinge + "+" })
+ let o = editor.findObj(state.doorID).point_offset(cursor)
+ if (state.hinge === "b") {
+ o = -o
+ }
+ let s = (o > 0 ? "+" : "-")
+ editor.backend.mapPoints(state.door.type, state.door.a, state.door.b, { door_swing: state.hinge + s })
cleanup()
return
}
@@ -669,6 +674,20 @@ function precisePointMapHandler(event, editor, state) {
editor.mapPoints("wall", data.a, sub)
editor.mapPoints("wall", sub, data.b)
editor.remove(map)
+ return
+ }
+
+ if (data.type !== "door" || event.button !== buttons.left) {
+ return
+ }
+
+ if (event.type === "mousedown") {
+ handled(event)
+ state.door = data
+ state.doorID = id
+ state.hinge = Math.round(editor.findObj(id).closestLinearInterpolation(cursor)) ? "b" : "a"
+ } else {
+ console.log("Hmm", event)
}
}