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 },
|
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 x = event.clientX - rect.left - rect.width / 3;
|
||||||
|
const y = event.clientY - rect.top - rect.height / 2;
|
||||||
|
|
||||||
const rect = container.current.getBoundingClientRect();
|
setAngle(clamp(Math.atan2(-y, x), -Math.PI / 2, Math.PI / 2));
|
||||||
const x = event.clientX - rect.left - rect.width / 3;
|
},
|
||||||
const y = event.clientY - rect.top - rect.height / 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 (
|
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,35 +825,43 @@ 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();
|
||||||
|
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();
|
modelTransformEvent.dispatch({ pitch: nextPitch, yaw: nextYaw });
|
||||||
const size = Math.min(rect.width, rect.height);
|
},
|
||||||
const u = event.clientX - rect.left - rect.width / 2;
|
[pitchRange, initialTurretPitch],
|
||||||
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],
|
|
||||||
);
|
|
||||||
|
|
||||||
setPitch(nextPitch);
|
// touch only aims on tap so flicks over the toy still scroll the page
|
||||||
setYaw(nextYaw);
|
const handlePointerMove = useCallback(
|
||||||
setMinPitch(min[0] - initialTurretPitch);
|
(event: PointerEvent<HTMLDivElement>) => {
|
||||||
setMaxPitch(max[0] - initialTurretPitch);
|
if (event.pointerType === "touch") return;
|
||||||
|
aimAt(event);
|
||||||
modelTransformEvent.dispatch({ pitch: nextPitch, yaw: nextYaw });
|
},
|
||||||
}
|
[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}>
|
||||||
|
|||||||
Reference in new issue
Block a user