diff --git a/src/common/hotbar-store.ts b/src/common/hotbar-store.ts index b90a007b34..bad8b95a31 100644 --- a/src/common/hotbar-store.ts +++ b/src/common/hotbar-store.ts @@ -26,6 +26,7 @@ import * as uuid from "uuid"; import isNull from "lodash/isNull"; import { toJS } from "./utils"; import { CatalogEntity } from "./catalog"; +import { catalogEntity } from "../main/catalog-sources/general"; export interface HotbarItem { entity: { @@ -94,7 +95,15 @@ export class HotbarStore extends BaseStore { @action protected async fromStore(data: Partial = {}) { - this.hotbars = data.hotbars; + if (!data.hotbars || !data.hotbars.length) { + this.hotbars = [{ + id: uuid.v4(), + name: "Default", + items: this.defaultHotbarInitialItems, + }]; + } else { + this.hotbars = data.hotbars; + } if (data.activeHotbarId) { if (this.getById(data.activeHotbarId)) { @@ -107,6 +116,16 @@ export class HotbarStore extends BaseStore { } } + get defaultHotbarInitialItems() { + const { metadata: { uid, name, source } } = catalogEntity; + const initialItem = { entity: { uid, name, source }}; + + return [ + initialItem, + ...Array.from(Array(defaultHotbarCells - 1).fill(null)) + ]; + } + getActive() { return this.getById(this.activeHotbarId); }