mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-04 23:32:54 +01:00
stop touch screen dragging
This commit is contained in:
3 files changed
+77
-47
No files matched your search
@@ -5,7 +5,7 @@ export default defineConfig({
|
||||
devToolbar: { enabled: false },
|
||||
|
||||
vite: {
|
||||
server: { allowedHosts: [] },
|
||||
server: { allowedHosts: [".trycloudflare.com"] },
|
||||
esbuild: { target: "es2022" },
|
||||
build: { cssCodeSplit: false },
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<HTMLDivElement>) {
|
||||
event.preventDefault();
|
||||
const aimAt = useCallback(
|
||||
(event: MouseEvent<HTMLDivElement>) => {
|
||||
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<HTMLDivElement>) => {
|
||||
if (event.pointerType === "touch") return;
|
||||
aimAt(event);
|
||||
},
|
||||
[aimAt],
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={container}
|
||||
className={styles.visualizer}
|
||||
onPointerMove={updateAngle}
|
||||
onPointerMove={handlePointerMove}
|
||||
onClick={aimAt}
|
||||
>
|
||||
<div className={styles.armor}>
|
||||
<div className={styles.texture} />
|
||||
@@ -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<HTMLDivElement>) {
|
||||
if (!container.current || !range.current) return;
|
||||
const moveTo = useCallback((event: MouseEvent<HTMLDivElement>) => {
|
||||
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<HTMLDivElement>) => {
|
||||
if (event.pointerType === "touch") return;
|
||||
moveTo(event);
|
||||
},
|
||||
[moveTo],
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={container}
|
||||
className={styles["view-range"]}
|
||||
onPointerMove={follow}
|
||||
onPointerMove={handlePointerMove}
|
||||
onClick={moveTo}
|
||||
>
|
||||
<div
|
||||
className={styles.map}
|
||||
@@ -805,35 +825,43 @@ export function FlexibilityToy() {
|
||||
const dotX = r * Math.sin(yaw);
|
||||
const dotY = r * Math.cos(yaw);
|
||||
|
||||
function update(event: PointerEvent<HTMLDivElement>) {
|
||||
event.preventDefault();
|
||||
const aimAt = useCallback(
|
||||
(event: MouseEvent<HTMLDivElement>) => {
|
||||
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<HTMLDivElement>) => {
|
||||
if (event.pointerType === "touch") return;
|
||||
aimAt(event);
|
||||
},
|
||||
[aimAt],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={styles.flexibility}>
|
||||
@@ -856,7 +884,12 @@ export function FlexibilityToy() {
|
||||
/>
|
||||
</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.square}>
|
||||
|
||||
Reference in new issue
Block a user