feat: swap slots
This commit is contained in:
parent
9b74930500
commit
869ebf7e88
|
@ -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({
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in New Issue
Block a user