feat: swap slots

This commit is contained in:
cha0s 2024-06-24 06:40:47 -05:00
parent 9b74930500
commit 869ebf7e88
3 changed files with 25 additions and 1 deletions

View File

@ -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({

View File

@ -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) {

View File

@ -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}