commit 773fd6e55a8a72cfd46b065909c3a47cbf68b3a9
parent ff930a93521900c87906b2f6d25c53a30480667c
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Thu, 22 Aug 2024 11:01:38 -0700
Add support for updating pointmaps in backend and editor
Diffstat:
2 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/files/floorplans/floorplan/backend.js b/files/floorplans/floorplan/backend.js
@@ -434,19 +434,32 @@ export class FloorplanBackend {
// Returns map id
mapPoints(type, a, b, options) {
- if (type != "wall") {
- throw new Error("Only walls allowed in pointmap so far")
+ if (type != "wall" && type != "door") {
+ throw new Error("Only walls and doors allowed in pointmap so far")
}
if (!this.cache.points[a] || !this.cache.points[b]) {
throw new Error("Pointmap must reference existing points")
}
+ // So it can be replaced instead of a duplicate being made.
+ // This may be an area to improve the efficiency of in the
+ // future with a points to pointmaps map.
+ let id
+ for (let key in this.cache.pointmaps) {
+ if (this.cache.pointmaps[key].a === a &&
+ this.cache.pointmaps[key].b === b) {
+ id = key
+ }
+ }
+
// NOTE: For now, a and b are numbers. May not always be the case
- return this.addData("pointmaps", {
+ id = this.addData("pointmaps", {
type: type,
a: a,
b: b
- }, options)
+ }, id, options)
+
+ return id
}
unmapPoints(id, options) {
diff --git a/files/floorplans/floorplan/editor.js b/files/floorplans/floorplan/editor.js
@@ -220,7 +220,7 @@ export class FloorplanEditor {
this.ui.bottom = this.draw.group().attr({ id: "bottom" })
let data = this.draw.group().attr({ id: "floorplan" })
- data.group().attr({ id: "walls" }) // lines
+ data.group().attr({ id: "pointmaps" }) // lines
data.group().attr({ id: "points" }) // circles
this.ui.top = this.draw.group().attr({ id: "top" })
@@ -454,7 +454,7 @@ export class FloorplanEditor {
console.debug("Editor.applyOp", diff)
let editor = this
- const ops = {
+ let ops = {
add: {
points: function(name, value) {
let cur = editor.draw.findOneMax(byId(name))
@@ -479,17 +479,24 @@ export class FloorplanEditor {
}
},
pointmaps: function(name, value) {
- if (value.type !== "wall") {
- throw new Error("Only walls currently supported")
+ if (value.type !== "wall" && value.type !== "door") {
+ throw new Error("Only walls and doors currently supported")
}
let a = editor.backend.reqId("points", value.a)
let b = editor.backend.reqId("points", value.b)
- let wall = editor.draw.findOneMax(name)
+ let wall = editor.draw.findOneMax(byId(name))
if (wall) {
wall.plot(a.x, a.y, b.x, b.y)
+ .removeClass(wall.data("type"))
+ .addClass(value.type)
+ .data("type", value.type)
} else {
- wall = editor.draw.findExactlyOne("#walls")
- .line(a.x, a.y, b.x, b.y).stroke("black").attr({ id: name })
+ editor.draw.findExactlyOne("#pointmaps")
+ .line(a.x, a.y, b.x, b.y)
+ .stroke({ color: "black", width: 400 })
+ .attr({ id: name })
+ .addClass(value.type)
+ .data("type", value.type)
}
}
},
@@ -503,6 +510,10 @@ export class FloorplanEditor {
}
}
}
+ if (ops.replace) {
+ throw new Error("You messed up")
+ }
+ ops.replace = ops.add
if (!ops[diff.op]) {
throw new Error(diff.op + ": Unexpected patch operation")