feat: more controls
This commit is contained in:
parent
e3ebe46bf4
commit
41d447a6a3
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user