www.spaceplanner.app

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

commit 5d7a3c1d24b7b8478afbbf779a8bd44b2ba260c5
parent d48dc7defd1b132f0387e7e11cc04b8489e29e2d
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Sun,  8 Sep 2024 15:10:33 -0700

Update object ID system

This adds support for the new system-unique string IDs from the
server and furthermore always uses local IDs to reference objects,
and only maps to and from those IDs only when communicating with
the server. This should make things less error-prone because there's
only one place where IDs need to be updated, instead of everywhere
throughout the program's memory.

Diffstat:
Mfiles/floorplans/floorplan/backend.js | 364+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Mfiles/floorplans/floorplan/editor.js | 161+++++++++++++++++++++++++++++--------------------------------------------------
Mfiles/floorplans/floorplan/main.js | 31+++++++++++++++----------------
3 files changed, 280 insertions(+), 276 deletions(-)

diff --git a/files/floorplans/floorplan/backend.js b/files/floorplans/floorplan/backend.js @@ -1,5 +1,23 @@ import * as api from "/lib/api.js" + +// Sequence numbers for uniqueKey +let sequences = {} + +const objectPaths = { + pnt: "points", + pntmap: "pointmaps", + fur: "furniture", + furmap: "furniture_maps" +} + +const objectTypes = { + points: "pnt", + pointmaps: "pntmap", + furniture: "fur", + furniture_maps: "furmap" +} + class BackendHistory { constructor() { // The current position in history (diffs) @@ -285,30 +303,6 @@ class BackendHistory { } return group.last } - - updateId(type, oldId, newId) { - for (let i in this.diffs) { - let diff = this.diffs[i] - let r = parsePath(diff.path) - console.debug(r, type, oldId) - if (r.type === "furniture_maps" && type === "furniture") { - if (r.furniture_id === oldId) { - r.furniture_id = newId - } - } else if (r.type === "pointmaps" && type === "points") { - if (diff.value.a === oldId) { - diff.value.a = newId - } else if (diff.value.b === oldId) { - diff.value.b = newId - } - } - if (r.type === type && r.id == oldId) { - // NOTE: Above r.id is string, oldId is number - console.debug("Backend.History.updateId", type, oldId, newId) - diff.path = diffPath(r.type, newId) - } - } - } } export class FloorplanBackend { @@ -380,6 +374,12 @@ export class FloorplanBackend { // Time of last server update this.serverUpdated = null + + // A map of server idPaths pointing to localIDs + this.localIDs = {} + + // A map of local ids pointing to server ids + this.serverIDs = {} } get endpoint() { @@ -409,57 +409,48 @@ export class FloorplanBackend { * If clean is not given, it is marked dirty * (thus data from the server, with a known key, can be marked clean) */ - addData(type, value, key, options) { - if (!options) { - options = {} - } + addData(idOrType, value, options) { + options = options ?? {} - if (!key) { - /* - * We'll have to generate a temporary id for it here - * since we can't wait for the server to respond with - * the ID it decides. It will need to be updated once - * we do get the server response. - */ - key = uniqueKey(this.cache[type]) + let id + try { + id = idString(parseID(idOrType)) } - let inputKey = key - key = Number(key) - if (isNaN(key)) { - throw new Error(`${inputKey}: Invalid key, only numeric keys are accepted`) + catch { + id = this.newID(objectTypes[idOrType]) } - if (type === "pointmaps") { - this.updateMappedPoints(value.a, value.b, key) + if (idType(id) === "pntmap") { + this.updateMappedPoints(value.a, value.b, id) } - console.debug("Backend.addData", type, key, value) + console.debug("Backend.addData", id, value) + let t = idTable(id) if (!options.nodiff) { - this.history.addDiff("add", diffPath(type, key), value, this.cache[type][key], options) + this.history.addDiff("add", idPath(id), value, this.cache[t][id], options) } - this.cache[type][key] = value + this.cache[t][id] = value - return newRef(type, key) + return id } - removeData(type, key, options) { - if (!options) { - options = {} - } + removeData(id, options) { + options = options ?? {} - console.debug("Backend.removeData", type, key) - if (!this.cache[type][key]) { - throw new Error("Expected " + type + "/" + key + " to exist") + console.debug("Backend.removeData", id) + let t = idTable(id) + if (!this.cache[t][id]) { + throw new Error("Expected " + id + " to exist") } - if (type === "pointmaps") { - this.updateMappedPoints(this.cache[type][key].a, this.cache[type][key].b, null) + if (idType(id) === "pntmap") { + this.updateMappedPoints(this.cache[t][id].a, this.cache[t][id].b, null) } if (!options.nodiff) { - this.history.addDiff("remove", diffPath(type, key), null, this.cache[type][key], options) + this.history.addDiff("remove", idPath(id), null, this.cache[t][id], options) } - delete this.cache[type][key] + delete this.cache[t][id] } addPoint(point, options) { @@ -468,8 +459,8 @@ export class FloorplanBackend { if (typeof point.x !== "number" || typeof point.y !== "number") { throw new Error(`Point's x (${point.x}) and y (${point.y}) are not numbers`) } - return this.addData("points", { x: Math.round(point.x), y: Math.round(point.y) }, - options.replace, options) + return this.addData(options.replace ?? "points", + { x: Math.round(point.x), y: Math.round(point.y) }, options) } replacePoint(id, newpoint, options) { @@ -482,7 +473,7 @@ export class FloorplanBackend { options = options ?? {} if (!this.mappedPoints[id]) { - return this.removeData("points", id, options) + return this.removeData(id, options) } if (!options.unmap && !options.recurse) { @@ -493,7 +484,7 @@ export class FloorplanBackend { this.unmapPoints(this.mappedPoints[id][other]) } - this.removeData("points", id, options) + this.removeData(id, options) if (options.recurse) { this.removeOrphans() @@ -509,20 +500,16 @@ export class FloorplanBackend { throw new Error(`${a}, ${b}: Pointmap must reference existing points`) } - a = Number(a) - b = Number(b) - - // NOTE: For now, a and b are numbers. May not always be the case - return this.addData("pointmaps", { + return this.addData(this.whichPointMap(a, b) ?? "pointmaps", { type: type, a: a, b: b - }, this.whichPointMap(a, b), options) + }, options) } unmapPoints(id, options) { options = options ?? {} - this.removeData("pointmaps", id, options) + this.removeData(id, options) if (options.recurse) { this.removeOrphans() } @@ -597,28 +584,24 @@ export class FloorplanBackend { } unmapFurniture(id, options) { - this.removeData("furniture_maps", id, options) + this.removeData(id, options) } addMappedFurniture(type, x, y, options) { - let ref = this.addFurniture(type, options) - this.mapFurniture(ref.id, x, y, options) - return ref + let id = this.addFurniture(type, options) + return this.mapFurniture(id, x, y, options) } - reqId(type, id) { - let obj = this.byId(type, id) + reqObj(id) { + let obj = this.data(id) if (!obj) { - throw new Error(id + " for " + type + " doesn't exist") + throw new Error(id + " doesn't exist") } return obj } - byId(type, id) { - if (!this.cache[type]) { - throw new Error(type + ": Invalid type") - } - return this.cache[type][id] + obj(id) { + return this.cache[idTable(id)][id] } cb(name, arg) { @@ -658,7 +641,13 @@ export class FloorplanBackend { } } - patch.push( { op: op, path: dirty[i].path, value: dirty[i].value }) + let id = parsePath(dirty[i].path) + if (this.serverIDs[id]) { + patch.push({ op: op, path: idPath(this.serverIDs[id]), + value: this.remapIDsValue(dirty[i].value, this.serverIDs) }) + } else { + patch.push({ op: "new", path: dirty[i].path, value: dirty[i].value }) + } } console.debug("Backend.push (patch)", patch) @@ -679,7 +668,7 @@ export class FloorplanBackend { // WARNING: This needs a lock let backend = this - return api.fetch("PUT", this.endpoint, this.cache) + return api.fetch("PUT", this.endpoint, this.toServerIDs(this.cache)) .then(function() { backend.serverPosition = backend.history.place }) @@ -701,6 +690,7 @@ export class FloorplanBackend { let backend = this return api.fetch("GET", this.endpoint) .then(function(data) { + data = backend.toLocalIDs(data) let diff = gendiff("", backend.cache, data) console.debug("Backend.Pull (diff)", diff) backend.applyDiff(diff, { clean: true }) @@ -715,11 +705,12 @@ export class FloorplanBackend { this.history.newGroup() } for (let i in diff) { - let ref = parsePath(diff[i].path) + let id = parsePath(diff[i].path) + console.log(id, diff[i]) if (diff[i].op === "remove") { - this.removeData(ref.type, ref.id, options) + this.removeData(id, options) } else { - this.addData(ref.type, diff[i].value, ref.id, options) + this.addData(id, diff[i].value, options) } } if (!options.nodiff) { @@ -751,6 +742,52 @@ export class FloorplanBackend { console.debug("Backend.updateMappedPoints", this.mappedPoints) } + toLocalIDs(data) { + return this.remapIDs(data, this.localIDs, { createLocal: true }) + } + + toServerIDs(data) { + return this.remapIDs(data, this.serverIDs) + } + + remapIDs(data, idMap) { + let newdata = {} + for (let t in data) { + newdata[t] = {} + for (let id in data[t]) { + let nid = idMap[id] + if (nid == null) { + if (idMap != this.localIDs) { + continue + } + nid = this.newID(objectTypes[t], id) + } + newdata[t][nid] = this.remapIDsValue(data[t][id], idMap) + } + } + return newdata + } + + remapIDsValue(value, newids) { + value = structuredClone(value) + let keys = ['a', 'b', 'furniture_id'] + + for (let i in keys) { + let id = value[keys[i]] + if (id == null) { + continue + } + if (newids[id] == null) { + if (newids != this.localIDs) { + continue + } + let map = this.newID(idType(value[keys[i]]), value[keys[i]]) + } + value[keys[i]] = newids[value[keys[i]]] + } + return value + } + whichPointMap(a, b) { if (!this.mappedPoints[a]) { return undefined @@ -779,9 +816,9 @@ export class FloorplanBackend { originPoint() { for (let i in this.history.diffs) { - let ref = parsePath(this.history.diffs[i].path) - if (ref.type === "points" && this.cache.points[ref.id] != undefined) { - return ref.id + let id = parsePath(this.history.diffs[i].path) + if (idType(id) === "pnt" && this.cache.points[id] != undefined) { + return id } } @@ -800,6 +837,21 @@ export class FloorplanBackend { } return map } + + newID(type, serverID) { + let local = uniqueKey(type + "_", this.serverIDs) + if (serverID != null) { + this.mapID(local, serverID) + } + return local + } + + mapID(localID, serverID) { + if (serverID != null && this.localIDs[serverID] !== undefined) { + throw new Error("That server ID is already mapped to " + this.localIDs[serverID]) + } + this.localIDs[serverID] = localID + } } function gendiff(path, a, b) { @@ -825,87 +877,83 @@ function gendiff(path, a, b) { } function updateIds(backend, newdata) { - for (let type in newdata) { - for (let id in newdata[type]) { - let x = newdata[type][id] - if (x.old_id == undefined) { - continue - } - - backend.history.updateId(type, x.old_id, id) - console.debug("Backend.updateIds", `ID ${x.old_id} > ${id}`) - if (backend.cache[type][id]) { - // NOTE: I don't think this can actually happen - throw new Error("ERROR: Pull id conflict") - } - - backend.cache[type][id] = backend.cache[type][x.old_id] - // Both old and new exist at the moment, hense; - backend.cb("updateId", { type: type, old: x.old_id, new: id }) - delete backend.cache[type][x.old_id] - - if (type === "points") { - for (let i in backend.cache.pointmaps) { - if (backend.cache.pointmaps[i].a === x.old_id) { - console.debug(`Updated pointmap ${i} from ${x.old_id} to ${id}`) - backend.cache.pointmaps[i].a = id - } else if (backend.cache.pointmaps[i].b === x.old_id) { - backend.cache.pointmaps[i].b = id - console.debug(`Updated pointmap ${i} from ${x.old_id} to ${id}`) - } - } - if (backend.mappedPoints[x.old_id]) { - backend.mappedPoints[id] = backend.mappedPoints[x.old_id] - delete backend.mappedPoints[x.old_id] - for (let a in backend.mappedPoints) { - if (backend.mappedPoints[a][x.old_id]) { - backend.updateMappedPoints(a, id, backend.mappedPoints[a][x.old_id]) - backend.updateMappedPoints(a, x.old_id, null) - } - } - } - } else if (type === "pointmaps") { - // WARNING: This requires that pointmap a and b do not get - // modified, which I believe will hold true throughout the life - // cycle of the program. I'll probably forget and mess up but - // hopefully this provides some assistance. - backend.updateMappedPoints(x.a, x.b, id) - } else if (type === "furniture") { - let maps = backend.cache["furniture_maps"] - for (let mapid in maps) { - if (maps[mapid].furniture_id === x.old_id) { - maps[mapid].furniture_id = id - } - } - } + for (let srvID in newdata[type]) { + let x = newdata[id] + if (x.old_id != null) { + backend.localIDs[srvID] = x.old_id + backend.serverIDs[x.old_id] = srvID + } else { + backend.localIDs[srvID] = srvID + backend.serverIDs[srvID] = srvID } } } -function diffPath(type, id) { - return "/" + type + "/" + id -} - -export function parsePath(path) { - let a = path.split("/") - if (a.length != 3) { - throw new Error("Invalid path") +function uniqueKey(prefix, obj) { + if (sequences[prefix] == undefined) { + sequences[prefix] = 0 } - return newRef(a[1], Number(a[2])) -} - -export function newRef(type, id) { - return { type: String(type), id: Number(id) } -} -function uniqueKey(obj) { let key do { - key = Number(Math.random().toString().split(".").join("")) - } while (obj[key]) + key = prefix + sequences[prefix]++ + } while (obj[key] !== undefined) // Wonder if there's an atomic way of testing whether a key is undefined and doing this? // Doesn't matter much for my purposes probably. obj[key] = null return key } + +export function parseID(s) { + let a = s.split("_") + if (a.length != 2) { + throw new Error(s + ": Invalid ID") + } + return makeID(a[0], a[1]) +} + +function makeID(type, seq) { + if (!type || !seq || objectPaths[type] == null || isNaN(seq = Number(seq))) { + throw new Error(s + ": Invalid ID") + } + return { type, seq } +} + +export function idString(id) { + if (id.type == null || id.seq == null) { + throw new Error("Invalid ID") + } + return id.type + "_" + id.seq +} + +export function idType(id) { + return parseID(id).type +} + +export function idTable(id) { + return objectPaths[idType(id)] +} + +export function idPath(id) { + let table = idTable(id) + if (table == null) { + throw new Error("Invalid ID type") + } + return `/${table}/${id}` +} + +export function parsePath(path) { + let a = path.split("/") + if (a.length != 3) { + throw new Error(path + ": Invalid path") + } + if (objectTypes[a[1]] == null) { + throw new Error(path + ": Invalid path") + } + let id = parseID(a[2]) + if (id.type != objectTypes[a[1]]) { + throw new Error(path + ": Invalid path for type") + } + return idString(id) +} diff --git a/files/floorplans/floorplan/editor.js b/files/floorplans/floorplan/editor.js @@ -267,7 +267,6 @@ export class FloorplanEditor { } let editor = this - options.backend.callbacks.updateId = function(ids) { editor.updateId(ids) } this.backend = new backend.FloorplanBackend(floorplan, options.backend) @@ -476,23 +475,23 @@ export class FloorplanEditor { let later = [] for (let i in elements) { - let ref = getRef(elements[i]) - if (ref.type === "pointmaps") { - this.backend.unmapPoints(ref.id) - } else if (ref.type === "furniture_maps") { - this.backend.unmapFurniture(ref.id) + let id = getID(elements[i]) + if (backend.idType(id) === "pntmap") { + this.backend.unmapPoints(id) + } else if (backend.idType(id) === "furmap") { + this.backend.unmapFurniture(id) } else { - later.push(ref) + later.push(id) } } for (let i in later) { - if (later[i].type === "points") { - this.backend.removePoint(later[i].id, { unmap: true }) - } else if (later[i].type === "furniture_maps") { - this.backend.removeFurniture(later[i].id) + if (backend.idType(later[i])=== "pnt") { + this.backend.removePoint(later[i], { unmap: true }) + } else if (backend.idType(later[i]) === "furmap") { + this.backend.removeFurniture(later[i]) } else { - throw new Error(later[i].type + ": Unsupported type") + throw new Error(backend.idType(later[i]) + ": Unsupported type") } } @@ -501,14 +500,7 @@ export class FloorplanEditor { } movePoint(point, coordinate) { - return this.backend.replacePoint(getId(point, "points"), coordinate) - } - - removePoints(...points) { - for (let i in points) { - points[i] = backend.newRef("points", getId(points[i])) - } - return this.remove(points) + return this.backend.replacePoint(getID(point, "points"), coordinate) } pointAt(point) { @@ -541,9 +533,9 @@ export class FloorplanEditor { } mapPoints(type, p1, p2) { - let ref = this.backend.mapPoints(type, getId(p1, "points"), getId(p2, "points")) + let id = this.backend.mapPoints(type, getID(p1, "points"), getID(p2, "points")) this.updateDisplay() - return ref + return id } addFurniture(type, options) { @@ -600,8 +592,8 @@ export class FloorplanEditor { let ops = { add: { - points: function(name, value, ref) { - let cur = editor.draw.findOneMax(byId(name)) + points: function(id, value) { + let cur = editor.draw.findOneMax(byId(id)) // Update pointmaps if (cur) { cur.cx(value.x).cy(value.y) @@ -610,15 +602,15 @@ export class FloorplanEditor { editor.draw.findOne("#points") .circle(500) .cx(value.x).cy(value.y) - .attr({ id: name }) + .attr({ id }) .addClass("point") .select() } - for (let oth in editor.backend.mappedPoints[ref.id]) { - let map = editor.backend.mappedPoints[ref.id][oth] - oth = editor.backend.reqId("points", oth) - map = editor.draw.findOneMax(byId(refId((backend.newRef("pointmaps", map))))) + for (let oth in editor.backend.mappedPoints[id]) { + let map = editor.backend.mappedPoints[id][oth] + oth = editor.backend.obj(oth) + map = editor.draw.findOneMax(byId(map)) if (map) { // It's probably being added later, that said, this isn't a good solution // because it doesn't allow for checking for errors. @@ -626,13 +618,13 @@ export class FloorplanEditor { } } }, - pointmaps: function(name, value) { + pointmaps: function(id, value) { 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(byId(name)) + let a = editor.backend.obj(value.a) + let b = editor.backend.obj(value.b) + let wall = editor.draw.findOneMax(byId(id)) if (wall) { wall.plot(a.x, a.y, b.x, b.y) .removeClass(wall.data("type")) @@ -642,36 +634,32 @@ export class FloorplanEditor { editor.draw.findExactlyOne("#pointmaps") .line(a.x, a.y, b.x, b.y) .stroke({ color: "black", width: 400 }) - .attr({ id: name }) + .attr({ id }) .addClass(value.type) .data("type", value.type) } }, - furniture: function(name, value) { - let ref = idRef(name) - let maps = editor.backend.cache.furniture_maps + furniture: function(id, value) { + let maps = editor.backend.cache for (let id in maps) { - if (maps[id].furniture_id == ref.id) { - let ref = backend.newRef("furniture_maps", id) - // May be added next - let m = editor.draw.findOneMax(byId(refId(ref))) + if (maps[id].furniture_id == id) { + let m = editor.draw.findOneMax(byId(id)) if (m != null) { m.size(value.width, value.depth) } } } }, - furniture_maps: function(name, value) { - let fm = editor.draw.findOneMax(byId(name)) + furniture_maps: function(id, value) { + let fm = editor.draw.findOneMax(byId(id)) + let f = editor.backend.cache.furniture[value.furniture_id] if (!fm) { - let f = editor.backend.cache.furniture[value.furniture_id] console.log(f, editor.layoutG()) fm = editor.layoutG().rect(f.width, f.depth) .cx(value.x).cy(value.y) .fill("black") - .attr({ id: name }) + .attr({ id }) } - let f = editor.backend.cache.furniture[value.furniture_id] fm.element("title").words(f.name ?? f.type) fm.transform({ rotate: value.angle @@ -679,16 +667,16 @@ export class FloorplanEditor { } }, remove: { - points: function(name) { + points: function(id) { // Remove pointmaps - editor.draw.findExactlyOne(byId(name)).remove() + editor.draw.findExactlyOne(byId(id)).remove() }, - pointmaps: function(name) { - editor.draw.findExactlyOne(byId(name)).remove() + pointmaps: function(id) { + editor.draw.findExactlyOne(byId(id)).remove() }, furniture: function(name) {}, - furniture_maps: function(name) { - editor.draw.findExactlyOne(byId(name)).remove() + furniture_maps: function(id) { + editor.draw.findExactlyOne(byId(id)).remove() } } } @@ -701,11 +689,12 @@ export class FloorplanEditor { throw new Error(diff.op + ": Unexpected patch operation") } - let ref = backend.parsePath(diff.path) - if (!ops[diff.op][ref.type]) { + let id = backend.parsePath(diff.path) + let t = backend.idTable(id) + if (!ops[diff.op][t]) { throw new Error("Unhandled patch") } - ops[diff.op][ref.type](refId(ref), diff.value, ref) + ops[diff.op][t](id, diff.value) } switchLayout(name) { @@ -729,17 +718,8 @@ export class FloorplanEditor { return layout } - updateId(ids) { - if (ids.type == "furniture") { - return - } - let e = this.findRef(backend.newRef(ids.type, ids.old)) - e.attr({ id: refId(backend.newRef(ids.type, ids.new)) }) - console.log("Editor.updateId", `${ids.old} -> ${ids.new}`) - } - - findRef(ref) { - return this.draw.findExactlyOne(byId(refId(getRef(ref)))) + findObj(id) { + return this.draw.findExactlyOne(byId(getID(id))) } } @@ -797,52 +777,29 @@ function gridSystem(editor, system) { return last } -export function getRef(thing, type) { - console.debug("getRef", thing, type) - let ref +export function getID(thing, type) { + console.debug("getID", thing, type) + let id if (typeof thing === "object") { if (typeof thing.attr === "function") { - ref = idRef(thing.attr("id")) - } else if (typeof thing.type === "string" && typeof thing.id === "number") { - ref = thing + id = thing.attr("id") + } else if (typeof thing.type === "string" && typeof thing.id === "string") { + id = thing.id } } else if (typeof thing === "string") { - ref = idRef(thing) + id = thing } - if (!ref) { - console.error("Couldn't get ref from", thing) - throw new Error("Invalid ref") + if (id == undefined) { + console.error("Couldn't get id from", thing) + throw new Error("Invalid id") } - if (type && ref.type != type) { - throw new Error(`${ref.type}: Invalid ref type (wanted ${type})`) + if (type && backend.idTable(id) != type) { + throw new Error(`${backend.idTable(id)}: Invalid table (wanted ${type})`) } - return ref -} - -export function getId(thing, type) { - console.debug("getId", thing) - - let n = Number(thing) - if (isNaN(n)) { - return getRef(thing, type).id - } - return n -} - -export function idRef(id) { - let a = id.split("_") - if (a.length < 2) { - throw new Error(`${id}: Invalid id`) - } - id = a.pop() - return backend.newRef(a.join("_"), id) + return id } function byId(id) { return "#" + id } - -function refId(ref) { - return ref.type + "_" + ref.id -} diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js @@ -148,15 +148,15 @@ function selectHandler(event, editor) { }) ) - let refs = [] + let ids = [] for (let i in a) { - refs[i] = lib.getRef(a[i]) + ids[i] = lib.getID(a[i]) } let maps = [] - for (let i in refs) { - if (refs[i].type === "pointmaps") { - maps.push(editor.backend.cache.pointmaps[refs[i].id]) + for (let i in ids) { + if (backend.idType(ids[i]) === "pntmap") { + maps.push(editor.backend.cache.pointmaps[ids[i]]) } } @@ -424,14 +424,14 @@ function precisePointHandler(event, editor, state) { } let points = editor.thingsAt(p, "#points") - let fid = lib.getId(state.from) + let fid = lib.getID(state.from) let tid if (state.snapmap == null) { - tid = lib.getId(state.to) + tid = lib.getID(state.to) } let instead for (let i in points) { - let id = lib.getId(points[i]) + let id = lib.getID(points[i]) if (id !== tid && id !== fid) { instead = id } @@ -444,7 +444,7 @@ function precisePointHandler(event, editor, state) { } else { editor.remove(state.snapmap) } - state.to = editor.findRef(backend.newRef("points", instead)) + state.to = editor.findObj(instead) state.snapmap = editor.mapPoints("wall", state.from, state.to) } } else if (state.snapmap != null) { @@ -453,7 +453,7 @@ function precisePointHandler(event, editor, state) { state.to = editor.addPoint(p, true) editor.mapPoints("wall", state.from, state.to) editor.updateDisplay() - state.to = editor.findRef(state.to) + state.to = editor.findObj(state.to) } if (!options.leave_input) { @@ -508,9 +508,9 @@ function precisePointHandler(event, editor, state) { state.from = null // I want the first pointmap defined, but this for now - let m = editor.backend.mappedPoints[lib.getId(state.to)] + let m = editor.backend.mappedPoints[lib.getID(state.to)] for (let point in m) { - state.from = editor.findRef(backend.newRef("points", point)) + state.from = editor.findObj(point) break } if (!state.from) { @@ -521,7 +521,7 @@ function precisePointHandler(event, editor, state) { } init() } - + state.origin = state.from.vec() } else if (event.type === "mouseup") { cleanup() @@ -531,7 +531,7 @@ function precisePointHandler(event, editor, state) { state.to = editor.addPoint(cursor, true) editor.mapPoints("wall", state.from, state.to) editor.updateDisplay() - state.to = editor.findRef(state.to) + state.to = editor.findObj(state.to) init() } event.preventDefault() @@ -586,7 +586,7 @@ function precisePointMapHandler(event, editor) { } // Shouldn't really use backend as it's only correct when updateDisplay is called - let data = editor.backend.reqId("pointmaps", lib.getId(map)) + let data = editor.backend.obj(lib.getID(map)) if (data.type != "wall") { throw new Error("Changing direction of doors not yet supported") } @@ -599,7 +599,6 @@ function precisePointMapHandler(event, editor) { } sub = editor.addPoint(sub) - console.log(data, sub) editor.mapPoints("wall", data.a, sub) editor.mapPoints("wall", sub, data.b) editor.remove(map)