commit ff930a93521900c87906b2f6d25c53a30480667c
parent 74d6d44f24b4bb50b85a0f180c53ec2349bbc818
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Thu, 22 Aug 2024 10:54:24 -0700
Add generalized versions a pointAt and mapPoint Editor methods
- Add thingAt which works like pointAt except it works on any set
of elements, and update pointAt to use it
- Add mapPointsById which allows giving plain point ids instead of
point elements, and update mapPoints to use it
Diffstat:
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/files/floorplans/floorplan/editor.js b/files/floorplans/floorplan/editor.js
@@ -384,14 +384,21 @@ export class FloorplanEditor {
}
pointAt(point) {
- let pointInside = null
- this.draw.findOne("#points")
- .children().each(function(child) {
- if (child.inside(point.x, point.y)) {
- pointInside = child
- }
- })
- return pointInside
+ return this.thingAt(point, "#points")
+ }
+
+
+ thingAt(point, selector) {
+ let children = this.draw.find(selector ?? "*")
+ .children()
+ .toArray()
+
+ for (let i in children) {
+ if (children[i].inside(point.x, point.y)) {
+ return children[i]
+ }
+ }
+ return null
}
mapSelected(type) {
@@ -402,10 +409,11 @@ export class FloorplanEditor {
mapPoints(type, p1, p2) {
let pointId = function(id) { return id.split("_")[1] }
- this.backend.mapPoints(type,
- pointId(p1.attr("id")),
- pointId(p2.attr("id"))
- )
+ this.mapPointsById(type, pointId(p1.attr("id")), pointId(p2.attr("id")))
+ }
+
+ mapPointsById(type, p1, p2) {
+ this.backend.mapPoints(type, p1, p2)
this.updateDisplay()
}