commit 03164ff078c7d1f7ecaaf5946fa8516ce11a4588
parent f24faef5fc0ae6f94133b498d929bc9a62d40ba2
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Sun, 13 Oct 2024 18:12:06 -0700
Fix directly deleting cache data in furniture menu
The backend.obj method returns a mutable pointer to an object in
the cache, which can be helpful if you want to keep values updated
but really bad if you forget and mutate it. I'll have to look into
a solution for this. Maybe you can return an unmutable variable in
which case that's what I'll do. Otherwise make it a copy by default
and add a separate method to give a pointer for when you need it.
Diffstat:
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js
@@ -914,17 +914,11 @@ function furnitureMenuX(editor, pointOrID) {
}
editor.finishAction()
- let p
let id
- let params
if (typeof pointOrID === "string") {
id = pointOrID
- params = editor.backend.reqObj(id)
- let fp = editor.backend.reqObj(params.furniture_id)
- for (let k in fp) {
- params[k] = fp[k]
- }
} else {
+ let p
if (pointOrID == null) {
p = { x: 0, y: 0 }
} else if (typeof pointOrID === "object") {
@@ -939,7 +933,7 @@ function furnitureMenuX(editor, pointOrID) {
let s = editor.units.get("inch", 32)
v = { width: s, depth: s }
}
- params = {
+ let params = {
x: p.x,
y: p.y,
type,
@@ -949,11 +943,16 @@ function furnitureMenuX(editor, pointOrID) {
}
id = editor.addMappedFurniture(params)
+
editor.finishAction()
editor.findObj(id).select()
}
- /* We don't want to update these */
+ let params = structuredClone(editor.backend.reqObj(id))
+ let fp = editor.backend.reqObj(params.furniture_id)
+ for (let k in fp) {
+ params[k] = fp[k]
+ }
delete params.x
delete params.y