diff --git a/app/ecs-components/inventory.js b/app/ecs-components/inventory.js index bf9dd1c..1fa7124 100644 --- a/app/ecs-components/inventory.js +++ b/app/ecs-components/inventory.js @@ -65,6 +65,26 @@ export default function(Component) { }); return proxy; }; + Instance.prototype.swapSlots = function(l, r) { + const {slots} = this; + const tmp = slots[l]; + const change = {}; + if (slots[r]) { + change[l] = slots[l] = slots[r]; + } + else { + change[l] = false; + delete slots[l]; + } + if (tmp) { + change[r] = slots[r] = tmp; + } + else { + change[r] = false; + delete slots[r]; + } + Component.markChange(this.entity, 'slotChange', change); + }; return Instance; } static schema = new Schema({ diff --git a/app/engine.js b/app/engine.js index cfa1c36..2c8e9c2 100644 --- a/app/engine.js +++ b/app/engine.js @@ -233,6 +233,10 @@ export default class Engine { Controlled[payload.type] = payload.value; break; } + case 'swapSlots': { + Inventory.swapSlots(...payload.value); + break; + } case 'use': { const item = Inventory.item(Wielder.activeSlot + 1); if (item) { diff --git a/app/react-components/ui.jsx b/app/react-components/ui.jsx index 276108f..0cb51de 100644 --- a/app/react-components/ui.jsx +++ b/app/react-components/ui.jsx @@ -180,7 +180,7 @@ export default function Ui({disconnected}) { onActivate={(i) => { client.send({ type: 'Action', - payload: {type: 'changeSlot', value: i + 1}, + payload: {type: 'swapSlots', value: [0, i + 1]}, }); }} slots={hotbarSlots}