From ea2337ee00067f0cb3d9ac1c2d01260fc197b7f4 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 22 Jun 2024 11:44:49 -0500 Subject: [PATCH] feat: quick and dirty inventory --- app/react-components/ui.jsx | 16 ++++++++++++++-- public/assets/potion/icon.png | Bin 0 -> 3309 bytes public/assets/potion/start.js | 8 ++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 public/assets/potion/icon.png diff --git a/app/react-components/ui.jsx b/app/react-components/ui.jsx index 4587a12..eaa44f8 100644 --- a/app/react-components/ui.jsx +++ b/app/react-components/ui.jsx @@ -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 (