diff --git a/src/common/hotbar-store.ts b/src/common/hotbar-store.ts index 5b84be9b9d..55f96a4550 100644 --- a/src/common/hotbar-store.ts +++ b/src/common/hotbar-store.ts @@ -106,6 +106,26 @@ export class HotbarStore extends BaseStore { } } + switchToPrevious() { + let index = hotbarStore.activeHotbarIndex - 1; + + if (index < 0) { + index = hotbarStore.hotbars.length - 1; + } + + hotbarStore.activeHotbarId = hotbarStore.hotbars[index].id; + } + + switchToNext() { + let index = hotbarStore.activeHotbarIndex + 1; + + if (index >= hotbarStore.hotbars.length) { + index = 0; + } + + hotbarStore.activeHotbarId = hotbarStore.hotbars[index].id; + } + toJSON(): HotbarStoreModel { const model: HotbarStoreModel = { hotbars: this.hotbars, diff --git a/src/renderer/components/hotbar/hotbar-menu.tsx b/src/renderer/components/hotbar/hotbar-menu.tsx index 90b0fc9978..64e7477a74 100644 --- a/src/renderer/components/hotbar/hotbar-menu.tsx +++ b/src/renderer/components/hotbar/hotbar-menu.tsx @@ -44,23 +44,11 @@ export class HotbarMenu extends React.Component { } previous() { - let index = hotbarStore.activeHotbarIndex - 1; - - if (index < 0) { - index = hotbarStore.hotbars.length - 1; - } - - hotbarStore.activeHotbarId = hotbarStore.hotbars[index].id; + hotbarStore.switchToPrevious(); } next() { - let index = hotbarStore.activeHotbarIndex + 1; - - if (index >= hotbarStore.hotbars.length) { - index = 0; - } - - hotbarStore.activeHotbarId = hotbarStore.hotbars[index].id; + hotbarStore.switchToNext(); } openSelector() {