From 3a2b8eb4b8b9978586689f8c49731c94d31b3860 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Fri, 7 May 2021 14:19:39 +0300 Subject: [PATCH] Migration for adding extra data to hotbar items Signed-off-by: Alex Andreev --- src/migrations/hotbar-store/5.0.0-alpha.0.ts | 6 +--- src/migrations/hotbar-store/5.0.0-beta.4.ts | 30 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 src/migrations/hotbar-store/5.0.0-beta.4.ts diff --git a/src/migrations/hotbar-store/5.0.0-alpha.0.ts b/src/migrations/hotbar-store/5.0.0-alpha.0.ts index b9ec80103b..58d7073761 100644 --- a/src/migrations/hotbar-store/5.0.0-alpha.0.ts +++ b/src/migrations/hotbar-store/5.0.0-alpha.0.ts @@ -22,11 +22,7 @@ export default migration({ } hotbar.items.push({ - entity: { - uid: cluster.id, - name: cluster.name, - source: cluster.source - }, + entity: { uid: cluster.id }, params: {} }); }); diff --git a/src/migrations/hotbar-store/5.0.0-beta.4.ts b/src/migrations/hotbar-store/5.0.0-beta.4.ts new file mode 100644 index 0000000000..a8d3be0fd6 --- /dev/null +++ b/src/migrations/hotbar-store/5.0.0-beta.4.ts @@ -0,0 +1,30 @@ +import { Hotbar } from "../../common/hotbar-store"; +import { migration } from "../migration-wrapper"; +import { catalogEntityRegistry } from "../../renderer/api/catalog-entity-registry"; + +export default migration({ + version: "5.0.0-beta.4", + run(store) { + const hotbars: Hotbar[] = store.get("hotbars"); + + hotbars.forEach((hotbar, hotbarIndex) => { + hotbar.items.forEach((item, itemIndex) => { + const entity = catalogEntityRegistry.items.find((entity) => entity.metadata.uid === item?.entity.uid); + + if (!entity) { + // Clear disabled item + hotbars[hotbarIndex].items[itemIndex] = null; + } else { + // Save additional data + hotbars[hotbarIndex].items[itemIndex].entity = { + ...item.entity, + name: entity.metadata.name, + source: entity.metadata.source + }; + } + }); + }); + + store.set("hotbars", hotbars); + } +});