From 3b1c85d55047376bfa464803ef32c9ff85aa0da0 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 14 Jan 2025 15:36:25 -0500 Subject: [PATCH] Fix issues when restoring from saved backup (re: #1489) Our `load` function was not working correctly, by considering the base state instead of the previous state when calling `updateCalculated` to fix caches. This changes the `load` function to do basically the same thing as the `replace`/`revert` functions that get called during the normal course of editing. --- modules/core/lib/Graph.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/core/lib/Graph.js b/modules/core/lib/Graph.js index fdea17d68a..ad05e7ec4a 100644 --- a/modules/core/lib/Graph.js +++ b/modules/core/lib/Graph.js @@ -451,7 +451,7 @@ export class Graph { /** * revert - * Revert an Entity back to whatver state it had in the base graph + * Revert an Entity back to whatever state it had in the base graph * @param entityID The entityID of the Entity to revert * @return A new Graph */ @@ -492,18 +492,16 @@ export class Graph { * load * Loads new Entities into the local Graph, obliterating any existing Entities. * Used when restoring history or entering/leaving walkthrough. + * This basically does the same thing as `replace`/`remove`, but without creating a new Graph. * @param entities `Object (entityID -> Entity)` * @return this Graph */ load(entities) { - const base = this._base; - const local = this._local; - local.entities = new Map(); - for (const [entityID, entity] of Object.entries(entities)) { - const original = base.entities.get(entityID); // likely undefined, but may as well check - local.entities.set(entityID, entity); - this._updateCalculated(original, entity); + const current = this.hasEntity(entityID); + const replacement = entity || undefined; + this._updateCalculated(current, replacement); + this._local.entities.set(entityID, replacement); } return this;