diff --git a/src/common/hotbar-store.ts b/src/common/hotbar-store.ts index c1f5af7991..5bfb1ac73a 100644 --- a/src/common/hotbar-store.ts +++ b/src/common/hotbar-store.ts @@ -69,6 +69,42 @@ export class HotbarStore extends BaseStore { return this.hotbarIndex(this.activeHotbarId); } + @action + protected fromStore(data: Partial = {}) { + if (!data.hotbars || !data.hotbars.length) { + const hotbar = getEmptyHotbar("Default"); + const { metadata: { uid, name, source } } = catalogEntity; + const initialItem = { entity: { uid, name, source } }; + + hotbar.items[0] = initialItem; + + this.hotbars = [hotbar]; + } else { + this.hotbars = data.hotbars; + } + + this.hotbars.forEach(ensureExactHotbarItemLength); + + if (data.activeHotbarId) { + if (this.getById(data.activeHotbarId)) { + this.activeHotbarId = data.activeHotbarId; + } + } + + if (!this.activeHotbarId) { + this.activeHotbarId = this.hotbars[0].id; + } + } + + toJSON(): HotbarStoreModel { + const model: HotbarStoreModel = { + hotbars: this.hotbars, + activeHotbarId: this.activeHotbarId + }; + + return toJS(model); + } + getActive() { return this.getById(this.activeHotbarId); } @@ -238,42 +274,6 @@ export class HotbarStore extends BaseStore { hotbarStore.activeHotbarId = hotbarStore.hotbars[index].id; } - - @action - protected fromStore(data: Partial = {}) { - if (!data.hotbars || !data.hotbars.length) { - const hotbar = getEmptyHotbar("Default"); - const { metadata: { uid, name, source } } = catalogEntity; - const initialItem = { entity: { uid, name, source } }; - - hotbar.items[0] = initialItem; - - this.hotbars = [hotbar]; - } else { - this.hotbars = data.hotbars; - } - - this.hotbars.forEach(ensureExactHotbarItemLength); - - if (data.activeHotbarId) { - if (this.getById(data.activeHotbarId)) { - this.activeHotbarId = data.activeHotbarId; - } - } - - if (!this.activeHotbarId) { - this.activeHotbarId = this.hotbars[0].id; - } - } - - toJSON(): HotbarStoreModel { - const model: HotbarStoreModel = { - hotbars: this.hotbars, - activeHotbarId: this.activeHotbarId - }; - - return toJS(model); - } } /**