Optimized fog shapes to only include needed data

This commit is contained in:
Mitchell McCaffrey 2021-01-23 15:44:25 +11:00
parent 96450eb1d0
commit b9d8a007e5
3 changed files with 31 additions and 2 deletions

View File

@ -314,7 +314,7 @@ function MapFog({
} else if (toolSettings.type === "toggle") {
onShapesEdit(
editingShapes.map((shape) => ({
...shape,
id: shape.id,
visible: !shape.visible,
}))
);

View File

@ -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

View File

@ -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);
}