refactor: rendered distributing

This commit is contained in:
cha0s 2024-09-29 06:43:58 -05:00
parent 9e82b3a5c1
commit 0bfd4b3a9f

View File

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