mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
feat: inputs
This commit is contained in:
1 parent
73f7e84192
commit
b40b7b2472
2 files changed
+75
-1
No files matched your search
@@ -39,6 +39,7 @@ import {
|
|||||||
tankDefinitions,
|
tankDefinitions,
|
||||||
tankNamesDiacritics,
|
tankNamesDiacritics,
|
||||||
} from '../../../../core/blitzkrieg/tankDefinitions';
|
} from '../../../../core/blitzkrieg/tankDefinitions';
|
||||||
|
import { normalizeAngle180 } from '../../../../core/math/normalizeAngle180';
|
||||||
import * as styles from '../page.css';
|
import * as styles from '../page.css';
|
||||||
import { TankAlignment } from './components/tankAlignment';
|
import { TankAlignment } from './components/tankAlignment';
|
||||||
|
|
||||||
@@ -73,6 +74,8 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
const gunOrigin = new Vector3(...turret.gunOrigin);
|
const gunOrigin = new Vector3(...turret.gunOrigin);
|
||||||
const [turretRotation, setTurretRotation] = useState(0);
|
const [turretRotation, setTurretRotation] = useState(0);
|
||||||
const [orbitControlsEnabled, setOrbitControlsEnabled] = useState(true);
|
const [orbitControlsEnabled, setOrbitControlsEnabled] = useState(true);
|
||||||
|
const turretRotationInput = useRef<HTMLInputElement>(null);
|
||||||
|
const gunRotationInput = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!turret.guns.some(({ id }) => gun.id === id)) {
|
if (!turret.guns.some(({ id }) => gun.id === id)) {
|
||||||
@@ -89,6 +92,11 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
setVersusGun(versusTurret.guns.at(-1)!);
|
setVersusGun(versusTurret.guns.at(-1)!);
|
||||||
}
|
}
|
||||||
}, [versusTurret]);
|
}, [versusTurret]);
|
||||||
|
useEffect(() => {
|
||||||
|
turretRotationInput.current!.value = `${Math.round(
|
||||||
|
turretRotation * (180 / Math.PI),
|
||||||
|
)}`;
|
||||||
|
}, [turretRotation]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageWrapper color="purple">
|
<PageWrapper color="purple">
|
||||||
@@ -255,7 +263,9 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
}
|
}
|
||||||
function handlePointerUp(event: PointerEvent) {
|
function handlePointerUp(event: PointerEvent) {
|
||||||
setOrbitControlsEnabled(true);
|
setOrbitControlsEnabled(true);
|
||||||
setTurretRotation(draftTurretRotation);
|
setTurretRotation(
|
||||||
|
normalizeAngle180(draftTurretRotation),
|
||||||
|
);
|
||||||
|
|
||||||
window.removeEventListener(
|
window.removeEventListener(
|
||||||
'pointermove',
|
'pointermove',
|
||||||
@@ -302,6 +312,58 @@ export default function Page({ params }: { params: { id: string } }) {
|
|||||||
<Text>Enhanced armor</Text>
|
<Text>Enhanced armor</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<Flex
|
||||||
|
gap="2"
|
||||||
|
align="center"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
left: 16,
|
||||||
|
bottom: 16,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TextField.Root
|
||||||
|
variant="surface"
|
||||||
|
style={{
|
||||||
|
width: 115,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TextField.Slot>Turret</TextField.Slot>
|
||||||
|
<TextField.Input
|
||||||
|
onBlur={() => {
|
||||||
|
setTurretRotation(
|
||||||
|
normalizeAngle180(
|
||||||
|
Number(turretRotationInput.current?.value) *
|
||||||
|
(Math.PI / 180),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
turretRotationInput.current?.blur();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
ref={turretRotationInput}
|
||||||
|
style={{ textAlign: 'right' }}
|
||||||
|
/>
|
||||||
|
<TextField.Slot>°</TextField.Slot>
|
||||||
|
</TextField.Root>
|
||||||
|
|
||||||
|
<TextField.Root
|
||||||
|
variant="surface"
|
||||||
|
style={{
|
||||||
|
width: 115,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TextField.Slot>Gun</TextField.Slot>
|
||||||
|
<TextField.Input
|
||||||
|
ref={gunRotationInput}
|
||||||
|
value={0}
|
||||||
|
style={{ textAlign: 'right' }}
|
||||||
|
/>
|
||||||
|
<TextField.Slot>°</TextField.Slot>
|
||||||
|
</TextField.Root>
|
||||||
|
</Flex>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
export function normalizeAngle180(angle: number) {
|
||||||
|
const newAngle = angle % (2 * Math.PI);
|
||||||
|
|
||||||
|
if (newAngle > Math.PI) {
|
||||||
|
return newAngle - 2 * Math.PI;
|
||||||
|
}
|
||||||
|
if (newAngle < -Math.PI) {
|
||||||
|
return newAngle + 2 * Math.PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newAngle;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user