www.spaceplanner.app

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

commit 41406cefc566d89a9d0343fa085b37fbe7efcd69
parent 609f592f10c4841171b674a2c8a38bbfcfcc0f7a
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Mon, 14 Oct 2024 13:41:35 -0700

Add buttons to change door swing

I plan to give all these types of functions a button in order to
document it, then users can either use the button or the more
hands-on approach depending on their preference (and they can find
out about the hands-on approach naturally).

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

diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js @@ -330,6 +330,33 @@ function selectHandler(event, editor, state) { c.appendChild(document.createElement("li")) .appendChild(document.createTextNode("Length: " + userLength(editor, editor.pointmapLength(groups.pntmap[0])))) + + let pm = editor.backend.reqObj(groups.pntmap[0]) + if (pm.type === "door") { + const swingButton = function(backward) { + return ui.button(backward ? "prevswing" : "swing", + `Swing door${backward ? " backward" : ""} (you may also click, drag, and release on a door)`, + backward ? "arrow-back" : "arrow-forward", { + handlers: { + click: function() { + let pm = editor.backend.reqObj(groups.pntmap[0]) + editor.mapPoints({ door_swing: (backward ? prevSwing : nextSwing)(pm.door_swing) }, groups.pntmap[0]) + } + } + }) + } + let swingOps = c.appendChild(document.createElement("li")) + swingOps.append(document.createTextNode("Swing: ")) + swingOps.append(swingButton(true)) + swingOps.append(swingButton(false)) + swingOps.append(ui.button("Reset", "Reset door swing", null, { + handlers: { + click: function() { + editor.mapPoints({ door_swing: null }, groups.pntmap[0]) + } + } + })) + } } if (groups.furmap) { @@ -1347,3 +1374,29 @@ function precision(a) { } return p } + +function nextSwing(swing) { + let next + if (!swing) { + next = 'a-' + } else if (swing[1] === '-') { + next = (swing[0] === 'a' ? 'b' : 'a') + '+' + } else { + next = swing[0] + '-' + } + console.debug("nextSwing", `${swing} -> ${next}`) + return next +} + +function prevSwing(swing) { + let prev + if (!swing) { + prev = 'a-' + } else if (swing[1] === '+') { + prev = (swing[0] === 'a' ? 'b' : 'a') + '-' + } else { + prev = swing[0] + '+' + } + console.debug("prevSwing", `${swing} -> ${prev}`) + return prev +}