stop touch screen dragging

This commit is contained in:
tresabhi committed 2026-12-04 16:28:12 -06:00
1 parent 4be1955702
commit 7cd3e10492
3 files changed
+56 -26

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ export default defineConfig({
devToolbar: { enabled: false }, devToolbar: { enabled: false },
vite: { vite: {
server: { allowedHosts: [] }, server: { allowedHosts: [".trycloudflare.com"] },
esbuild: { target: "es2022" }, esbuild: { target: "es2022" },
build: { cssCodeSplit: false }, build: { cssCodeSplit: false },
@@ -36,7 +36,6 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
touch-action: none;
border-radius: inherit; border-radius: inherit;
background-color: var(--gray-2); background-color: var(--gray-2);
@@ -390,7 +389,6 @@
.view-range { .view-range {
width: 100%; width: 100%;
height: 100%; height: 100%;
touch-action: none;
border-radius: inherit; border-radius: inherit;
user-select: none; user-select: none;
@@ -468,7 +466,6 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
touch-action: none;
border-radius: inherit; border-radius: inherit;
user-select: none; user-select: none;
@@ -9,6 +9,7 @@ import {
useRef, useRef,
useState, useState,
type CSSProperties, type CSSProperties,
type MouseEvent,
type PointerEvent, type PointerEvent,
} from "react"; } from "react";
import { clamp, degToRad, radToDeg } from "three/src/math/MathUtils.js"; 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); : Math.sign(angle) * Math.max(0, Math.abs(angle) - normalization);
const armorPercentage = Math.min(999, 100 / Math.cos(effectiveAngle)); const armorPercentage = Math.min(999, 100 / Math.cos(effectiveAngle));
function updateAngle(event: PointerEvent<HTMLDivElement>) { const aimAt = useCallback(
event.preventDefault(); (event: MouseEvent<HTMLDivElement>) => {
if (explodes) return;
if (!container.current || explodes) return; const rect = container.current!.getBoundingClientRect();
const rect = container.current.getBoundingClientRect();
const x = event.clientX - rect.left - rect.width / 3; const x = event.clientX - rect.left - rect.width / 3;
const y = event.clientY - rect.top - rect.height / 2; const y = event.clientY - rect.top - rect.height / 2;
setAngle(clamp(Math.atan2(-y, x), -Math.PI / 2, Math.PI / 2)); setAngle(clamp(Math.atan2(-y, x), -Math.PI / 2, Math.PI / 2));
} },
[explodes],
);
// touch only aims on tap so flicks over the toy still scroll the page
const handlePointerMove = useCallback(
(event: PointerEvent<HTMLDivElement>) => {
if (event.pointerType === "touch") return;
aimAt(event);
},
[aimAt],
);
return ( return (
<div <div
ref={container} ref={container}
className={styles.visualizer} className={styles.visualizer}
onPointerMove={updateAngle} onPointerMove={handlePointerMove}
onClick={aimAt}
> >
<div className={styles.armor}> <div className={styles.armor}>
<div className={styles.texture} /> <div className={styles.texture} />
@@ -599,19 +611,27 @@ export function ViewRangeToy({ characteristics }: ToyProps) {
const viewRange = characteristics.get("view_range") as number; const viewRange = characteristics.get("view_range") as number;
const resolvedViewRange = viewRange * (1 - camouflage); const resolvedViewRange = viewRange * (1 - camouflage);
function follow(event: PointerEvent<HTMLDivElement>) { const moveTo = useCallback((event: MouseEvent<HTMLDivElement>) => {
if (!container.current || !range.current) return; 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(); // touch only moves on tap so flicks over the toy still scroll the page
range.current.style.left = `${event.clientX - rect.left}px`; const handlePointerMove = useCallback(
range.current.style.top = `${event.clientY - rect.top - 16}px`; (event: PointerEvent<HTMLDivElement>) => {
} if (event.pointerType === "touch") return;
moveTo(event);
},
[moveTo],
);
return ( return (
<div <div
ref={container} ref={container}
className={styles["view-range"]} className={styles["view-range"]}
onPointerMove={follow} onPointerMove={handlePointerMove}
onClick={moveTo}
> >
<div <div
className={styles.map} className={styles.map}
@@ -805,12 +825,9 @@ export function FlexibilityToy() {
const dotX = r * Math.sin(yaw); const dotX = r * Math.sin(yaw);
const dotY = r * Math.cos(yaw); const dotY = r * Math.cos(yaw);
function update(event: PointerEvent<HTMLDivElement>) { const aimAt = useCallback(
event.preventDefault(); (event: MouseEvent<HTMLDivElement>) => {
const rect = container.current!.getBoundingClientRect();
if (!container.current) return;
const rect = container.current.getBoundingClientRect();
const size = Math.min(rect.width, rect.height); const size = Math.min(rect.width, rect.height);
const u = event.clientX - rect.left - rect.width / 2; const u = event.clientX - rect.left - rect.width / 2;
const v = event.clientY - rect.top - rect.height / 2; const v = event.clientY - rect.top - rect.height / 2;
@@ -833,7 +850,18 @@ export function FlexibilityToy() {
setMaxPitch(max[0] - initialTurretPitch); setMaxPitch(max[0] - initialTurretPitch);
modelTransformEvent.dispatch({ pitch: nextPitch, yaw: nextYaw }); modelTransformEvent.dispatch({ pitch: nextPitch, yaw: nextYaw });
} },
[pitchRange, initialTurretPitch],
);
// touch only aims on tap so flicks over the toy still scroll the page
const handlePointerMove = useCallback(
(event: PointerEvent<HTMLDivElement>) => {
if (event.pointerType === "touch") return;
aimAt(event);
},
[aimAt],
);
return ( return (
<div className={styles.flexibility}> <div className={styles.flexibility}>
@@ -856,7 +884,12 @@ export function FlexibilityToy() {
/> />
</div> </div>
<div ref={container} className={styles.radial} onPointerMove={update}> <div
ref={container}
className={styles.radial}
onPointerMove={handlePointerMove}
onClick={aimAt}
>
<div className={styles.texture} /> <div className={styles.texture} />
<div className={styles.square}> <div className={styles.square}>