From b9d8a007e5c6b3273aec039b2843f57fcf728c1f Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Sat, 23 Jan 2021 15:44:25 +1100 Subject: [PATCH] Optimized fog shapes to only include needed data --- src/components/map/MapFog.js | 2 +- src/database.js | 24 ++++++++++++++++++++++++ src/helpers/drawing.js | 7 ++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/components/map/MapFog.js b/src/components/map/MapFog.js index 16a82a9..f2096d6 100644 --- a/src/components/map/MapFog.js +++ b/src/components/map/MapFog.js @@ -314,7 +314,7 @@ function MapFog({ } else if (toolSettings.type === "toggle") { onShapesEdit( editingShapes.map((shape) => ({ - ...shape, + id: shape.id, visible: !shape.visible, })) ); diff --git a/src/database.js b/src/database.js index 6164f28..53e92b3 100644 --- a/src/database.js +++ b/src/database.js @@ -280,6 +280,30 @@ function loadVersions(db) { state.editFlags = [...state.editFlags, "notes"]; }); }); + + // 1.7.0 (hotfix) - Optimized fog shape edits to only include needed data + db.version(17) + .stores({}) + .upgrade((tx) => { + return tx + .table("states") + .toCollection() + .modify((state) => { + for (let i = 0; i < state.fogDrawActions.length; i++) { + const action = state.fogDrawActions[i]; + if (action && action.type === "edit") { + for (let j = 0; j < action.shapes.length; j++) { + const shape = action.shapes[j]; + const temp = { ...shape }; + state.fogDrawActions[i].shapes[j] = { + id: temp.id, + visible: temp.visible, + }; + } + } + } + }); + }); } // Get the dexie database used in DatabaseContext diff --git a/src/helpers/drawing.js b/src/helpers/drawing.js index 4731f4e..a88123b 100644 --- a/src/helpers/drawing.js +++ b/src/helpers/drawing.js @@ -211,11 +211,16 @@ export function drawActionsToShapes(actions, actionIndex) { if (!action) { continue; } - if (action.type === "add" || action.type === "edit") { + if (action.type === "add") { for (let shape of action.shapes) { shapesById[shape.id] = shape; } } + if (action.type === "edit") { + for (let edit of action.shapes) { + shapesById[edit.id] = { ...shapesById[edit.id], ...edit }; + } + } if (action.type === "remove") { shapesById = omit(shapesById, action.shapeIds); }