From 376640092e4ff8d34dc4044c3f4c22aee1ca3a88 Mon Sep 17 00:00:00 2001 From: LionTion Date: Mon, 5 Oct 2026 21:09:29 +0200 Subject: [PATCH] RIDDLE!!!!!!!!!! 6!!!!!!!!!!!!! --- src/components/riddles/Riddle_6.tsx | 46 ++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/components/riddles/Riddle_6.tsx b/src/components/riddles/Riddle_6.tsx index 5aeada1..bbb374d 100644 --- a/src/components/riddles/Riddle_6.tsx +++ b/src/components/riddles/Riddle_6.tsx @@ -15,21 +15,36 @@ import clsx from "clsx"; import extraStyles from "@/components/riddles-css/Riddle_6.module.css"; let acl = null; +let ran = false; let animVal = 0.0; +async function startMotionTracking(listener, fallback) { + // iOS 13+ requires requesting explicit permission + if (typeof DeviceMotionEvent !== 'undefined' && typeof DeviceMotionEvent.requestPermission === 'function') { + const permission = await DeviceMotionEvent.requestPermission(); + if (permission !== 'granted') { + fallback(); + return; + } + window.addEventListener('devicemotion', listener); + } else { + fallback(); + } +} + export default function Riddle_6({ riddle, exitFunction, showBanner }: RiddleScreenControls) { - const [ page, setPage ] = useState(2); + const [ page, setPage ] = useState(1); const [aclTest, setAclTest ] = useState("X: -\nY: -\nZ: -\nO: -"); const [ overallChange, setOverallChange ] = useState(0); const [ animValue, setAnimValue ] = useState(0.0); useEffect(() => { - if (page === 2 && acl === null) { - acl = new Accelerometer({ frequency: 60 }); + if (page === 2 && !ran) { + /*acl = new Accelerometer({ frequency: 60 }); let lastAclReading: number[] | null = null; acl.addEventListener("reading", () => { const readings = [acl.x.toFixed(2), acl.y.toFixed(2), acl.z.toFixed(2)]; @@ -47,8 +62,8 @@ export default function Riddle_6({ } lastAclReading = [...readings]; }); - acl.start(); - showBanner(false); // FIXME: TESTING + acl.start();*/ + ran = true; } }, [page]); @@ -73,10 +88,27 @@ export default function Riddle_6({

Die Prüfung beginnt, sobald ihr bereit seid.

- { + { + startMotionTracking((event) => { + const { x, y, z } = event.acceleration || {}; + + if (x !== null && y !== null && z !== null) { + const magnitude = Math.sqrt(x * x + y * y + z * z); + setAclTest(`X: ${x.toFixed(2)}\nY: ${y.toFixed(2)}\nZ: ${z.toFixed(2)}`); + + if (magnitude > 3) { + animVal = 255; + } else { + animVal -= 22.5; + } + setAnimValue(animVal); + } + }, () => { + + }); setPage(2); showBanner(false); - }} disabled={false} holdDuration={500}>STARTEN + }} disabled={false}>STARTEN setPage(0)}>ZURÜCK