diff --git a/packages/website/astro.config.ts b/packages/website/astro.config.ts index 36c0c6204..073b3eff7 100644 --- a/packages/website/astro.config.ts +++ b/packages/website/astro.config.ts @@ -5,7 +5,7 @@ export default defineConfig({ devToolbar: { enabled: false }, vite: { - server: { allowedHosts: [] }, + server: { allowedHosts: [".trycloudflare.com"] }, esbuild: { target: "es2022" }, build: { cssCodeSplit: false }, diff --git a/packages/website/src/components/TankopediaToys/index.module.css b/packages/website/src/components/TankopediaToys/index.module.css index b8d0d0108..e25af7a4b 100644 --- a/packages/website/src/components/TankopediaToys/index.module.css +++ b/packages/website/src/components/TankopediaToys/index.module.css @@ -36,7 +36,6 @@ width: 100%; height: 100%; overflow: hidden; - touch-action: none; border-radius: inherit; background-color: var(--gray-2); @@ -390,7 +389,6 @@ .view-range { width: 100%; height: 100%; - touch-action: none; border-radius: inherit; user-select: none; @@ -468,7 +466,6 @@ width: 100%; height: 100%; overflow: hidden; - touch-action: none; border-radius: inherit; user-select: none; diff --git a/packages/website/src/components/TankopediaToys/index.tsx b/packages/website/src/components/TankopediaToys/index.tsx index 505fa8dd4..e5ebf6e0d 100644 --- a/packages/website/src/components/TankopediaToys/index.tsx +++ b/packages/website/src/components/TankopediaToys/index.tsx @@ -9,6 +9,7 @@ import { useRef, useState, type CSSProperties, + type MouseEvent, type PointerEvent, } from "react"; import { clamp, degToRad, radToDeg } from "three/src/math/MathUtils.js"; @@ -60,23 +61,34 @@ export function RicochetToy({ characteristics }: ToyProps) { : Math.sign(angle) * Math.max(0, Math.abs(angle) - normalization); const armorPercentage = Math.min(999, 100 / Math.cos(effectiveAngle)); - function updateAngle(event: PointerEvent) { - event.preventDefault(); + const aimAt = useCallback( + (event: MouseEvent) => { + if (explodes) return; - if (!container.current || explodes) return; + const rect = container.current!.getBoundingClientRect(); + const x = event.clientX - rect.left - rect.width / 3; + const y = event.clientY - rect.top - rect.height / 2; - const rect = container.current.getBoundingClientRect(); - const x = event.clientX - rect.left - rect.width / 3; - const y = event.clientY - rect.top - rect.height / 2; + setAngle(clamp(Math.atan2(-y, x), -Math.PI / 2, Math.PI / 2)); + }, + [explodes], + ); - setAngle(clamp(Math.atan2(-y, x), -Math.PI / 2, Math.PI / 2)); - } + // touch only aims on tap so flicks over the toy still scroll the page + const handlePointerMove = useCallback( + (event: PointerEvent) => { + if (event.pointerType === "touch") return; + aimAt(event); + }, + [aimAt], + ); return (
@@ -599,19 +611,27 @@ export function ViewRangeToy({ characteristics }: ToyProps) { const viewRange = characteristics.get("view_range") as number; const resolvedViewRange = viewRange * (1 - camouflage); - function follow(event: PointerEvent) { - if (!container.current || !range.current) return; + const moveTo = useCallback((event: MouseEvent) => { + const rect = container.current!.getBoundingClientRect(); + range.current!.style.left = `${event.clientX - rect.left}px`; + range.current!.style.top = `${event.clientY - rect.top - 16}px`; + }, []); - const rect = container.current.getBoundingClientRect(); - range.current.style.left = `${event.clientX - rect.left}px`; - range.current.style.top = `${event.clientY - rect.top - 16}px`; - } + // touch only moves on tap so flicks over the toy still scroll the page + const handlePointerMove = useCallback( + (event: PointerEvent) => { + if (event.pointerType === "touch") return; + moveTo(event); + }, + [moveTo], + ); return (
) { - event.preventDefault(); + const aimAt = useCallback( + (event: MouseEvent) => { + const rect = container.current!.getBoundingClientRect(); + const size = Math.min(rect.width, rect.height); + const u = event.clientX - rect.left - rect.width / 2; + const v = event.clientY - rect.top - rect.height / 2; + const [min, max] = pitchRange(Math.atan2(u, -v)); + const nextYaw = min[1]; + const distance = clamp( + 2 * Math.sqrt((u / size) ** 2 + (v / size) ** 2), + 0, + 1, + ); + const nextPitch = clamp( + degToRad(magInverse(-distance)) + initialTurretPitch, + min[0], + max[0], + ); - if (!container.current) return; + setPitch(nextPitch); + setYaw(nextYaw); + setMinPitch(min[0] - initialTurretPitch); + setMaxPitch(max[0] - initialTurretPitch); - const rect = container.current.getBoundingClientRect(); - const size = Math.min(rect.width, rect.height); - const u = event.clientX - rect.left - rect.width / 2; - const v = event.clientY - rect.top - rect.height / 2; - const [min, max] = pitchRange(Math.atan2(u, -v)); - const nextYaw = min[1]; - const distance = clamp( - 2 * Math.sqrt((u / size) ** 2 + (v / size) ** 2), - 0, - 1, - ); - const nextPitch = clamp( - degToRad(magInverse(-distance)) + initialTurretPitch, - min[0], - max[0], - ); + modelTransformEvent.dispatch({ pitch: nextPitch, yaw: nextYaw }); + }, + [pitchRange, initialTurretPitch], + ); - setPitch(nextPitch); - setYaw(nextYaw); - setMinPitch(min[0] - initialTurretPitch); - setMaxPitch(max[0] - initialTurretPitch); - - modelTransformEvent.dispatch({ pitch: nextPitch, yaw: nextYaw }); - } + // touch only aims on tap so flicks over the toy still scroll the page + const handlePointerMove = useCallback( + (event: PointerEvent) => { + if (event.pointerType === "touch") return; + aimAt(event); + }, + [aimAt], + ); return (
@@ -856,7 +884,12 @@ export function FlexibilityToy() { />
-
+