www.spaceplanner.app

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

commit ebd09db2a8c3ac42f4d5bea60271d0621834ec49
parent d064fe5c27dfe1c147136458b4b1edc7c4ac0725
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Thu, 17 Oct 2024 15:23:43 -0700

Provide easy method to get selected objects

It allows you to select by type, or ensure there's only one thing
selected, or that there's only one object selected of a given type.

This allows us to remove various old and unflexible methods like
mapSelected (which wasn't even in use).

Diffstat:
Mfiles/floorplans/floorplan/editor.js | 25++++++++++---------------
Mfiles/floorplans/floorplan/main.js | 2+-
2 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/files/floorplans/floorplan/editor.js b/files/floorplans/floorplan/editor.js @@ -631,11 +631,6 @@ export class FloorplanEditor { return inside } - mapSelected(type) { - let points = this.selectedPoints() - return this.mapPoints({ type, a: points.a, b: points.b }) - } - mapPoints(params, id) { if (params.a) { params.a = getID(params.a, "points") @@ -658,19 +653,19 @@ export class FloorplanEditor { return this.backend.addMappedFurniture(params, id) } - selectedPoints() { - return { - a: this.selectedPoint(), - b: this.lastSelectedPoint() + selected(type) { + if (type === "furniture_maps") { + type = "furniture_layouts > * >" } + return this.draw.find(`#${type} > .selected`) } - selectedPoint() { - return this.draw.findOneMax("#points > .selected") - } - - lastSelectedPoint() { - return this.draw.findOneMax("#points > .last_selected") + selectedOne(type) { + let sel = this.selected(type) + if (sel.length != 1) { + return null + } + return sel[0] } applyDiffs(diffs) { diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js @@ -959,7 +959,7 @@ function precisePointHandler(event, editor, state) { return } - state.from = editor.selectedPoint() + state.from = editor.selectedOne("points") if (!state.from) { return }