From 0bfd4b3a9f13deaaa842a5bae6730e600ceb110d Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 29 Sep 2024 06:43:58 -0500 Subject: [PATCH] refactor: rendered distributing --- app/react/components/ui.jsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/react/components/ui.jsx b/app/react/components/ui.jsx index 3534c6a..15f052a 100644 --- a/app/react/components/ui.jsx +++ b/app/react/components/ui.jsx @@ -46,7 +46,7 @@ function Ui({disconnected}) { const [showDisconnected, setShowDisconnected] = useState(false); const [bufferSlot, setBufferSlot] = useState(); const hadBufferSlot = useRef(); - const distributing = useRef(new Map()); + const [distributing, setDistributing] = useState({}); const [devtoolsIsOpen, setDevtoolsIsOpen] = useState(false); const ratio = (RESOLUTION.x * (devtoolsIsOpen ? 2 : 1)) / RESOLUTION.y; const [camera, setCamera] = useState({x: 0, y: 0}); @@ -438,7 +438,10 @@ function Ui({disconnected}) { }, [bufferSlot, client, keepHotbarOpen, losing, mainEntityRef, trading]); const hotbarOnSlotMouseMove = useCallback((i) => { if (hadBufferSlot.current) { - distributing.current.set([mainEntityRef.current, i + 1].join(':'), true); + setDistributing((distributing) => ({ + [[mainEntityRef.current, i + 1].join(':')]: true, + ...distributing, + })) } }, [mainEntityRef]); const hotbarOnSlotMouseUp = useCallback((i, event) => { @@ -449,18 +452,18 @@ function Ui({disconnected}) { else { switch (event.button) { case 0: - if (distributing.current.size > 0) { + if (Object.keys(distributing).length > 0) { client.send({ type: 'Action', payload: { type: 'distribute', value: [ 0, - Array.from(distributing.current.keys()).map((idAndSlot) => idAndSlot.split(':')), + Object.keys(distributing).map((idAndSlot) => idAndSlot.split(':')), ], }, }); - distributing.current.clear(); + setDistributing({}); } else if (hadBufferSlot.current) { client.send({ @@ -483,7 +486,7 @@ function Ui({disconnected}) { } } hadBufferSlot.current = undefined; - }, [client, keepHotbarOpen, mainEntityRef, trading]); + }, [client, distributing, keepHotbarOpen, mainEntityRef, trading]); const bagOnSlotMouseDown = useCallback((i) => { if (trading) { const index = losing.indexOf(i + 11);