feat: more controls

This commit is contained in:
cha0s 2024-07-02 18:20:53 -05:00
parent e3ebe46bf4
commit 41d447a6a3

View File

@ -202,20 +202,66 @@ export default function Ui({disconnected}) {
}
}
}, [hotbarSlots, mainEntity, setMainEntity]);
useEffect(() => {
function onContextMenu(event) {
event.preventDefault();
}
document.body.addEventListener('contextmenu', onContextMenu);
return () => {
document.body.removeEventListener('contextmenu', onContextMenu);
};
}, [])
return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div
className={styles.ui}
onMouseDown={(event) => {
client.send({
type: 'Action',
payload: {type: 'use', value: 'keyDown'},
});
switch (event.button) {
case 0:
client.send({
type: 'Action',
payload: {type: 'use', value: 1},
});
break;
case 2:
client.send({
type: 'Action',
payload: {type: 'interact', value: 1},
});
break;
}
event.preventDefault();
}}
onMouseUp={(event) => {
client.send({
type: 'Action',
payload: {type: 'use', value: 'keyUp'},
});
switch (event.button) {
case 0:
client.send({
type: 'Action',
payload: {type: 'use', value: 0},
});
break;
case 2:
client.send({
type: 'Action',
payload: {type: 'interact', value: 0},
});
break;
}
event.preventDefault();
}}
onWheel={(event) => {
if (event.deltaY > 0) {
client.send({
type: 'Action',
payload: {type: 'changeSlot', value: 1 + ((activeSlot + 1) % 10)},
});
}
else {
client.send({
type: 'Action',
payload: {type: 'changeSlot', value: 1 + ((activeSlot + 9) % 10)},
});
}
}}
>
<style>