feat: quick and dirty inventory

This commit is contained in:
cha0s 2024-06-22 11:44:49 -05:00
parent 3c562ca69a
commit ea2337ee00
3 changed files with 20 additions and 4 deletions

View File

@ -19,6 +19,7 @@ export default function Ui({disconnected}) {
const client = useContext(ClientContext);
const [mainEntity, setMainEntity] = useMainEntity();
const [showDisconnected, setShowDisconnected] = useState(false);
const [hotbarSlots, setHotbarSlots] = useState(Array(10).fill(0).map(() => {}));
const [activeSlot, setActiveSlot] = useState(0);
useEffect(() => {
let handle;
@ -141,12 +142,23 @@ export default function Ui({disconnected}) {
setMainEntity(localMainEntity = id);
}
if (localMainEntity === id) {
if (payload.ecs[id].Inventory) {
const newHotbarSlots = [...hotbarSlots];
payload.ecs[id].Inventory.slots
.forEach(({qty, slotIndex, source}) => {
newHotbarSlots[slotIndex] = {
image: source + '/icon.png',
qty,
};
});
setHotbarSlots(newHotbarSlots);
}
if (payload.ecs[id].Wielder && 'activeSlot' in payload.ecs[id].Wielder) {
setActiveSlot(payload.ecs[id].Wielder.activeSlot);
}
}
}
}, [mainEntity, setMainEntity]);
}, [hotbarSlots, mainEntity, setMainEntity]);
return (
<div className={styles.ui}>
<style>
@ -166,7 +178,7 @@ export default function Ui({disconnected}) {
payload: {type: 'changeSlot', value: i + 1},
});
}}
slots={Array(10).fill(0).map(() => {})}
slots={hotbarSlots}
/>
{showDisconnected && (
<Disconnected />

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@ -1,3 +1,7 @@
wielder.Health.health += 10
wielder.Inventory.slots[0].qty -= 1
console.log('hi', wielder.Health.health, wielder.Inventory.slots[0]);
wielder.Inventory.slots = [
{
...wielder.Inventory.slots[0],
qty: wielder.Inventory.slots[0].qty - 1,
}
]