RIDDLE!!!!!!!!!! 6!!!!!!!!!!!!!

This commit is contained in:
LionTion committed 2026-10-05 21:09:29 +02:00
1 parent 4929b39bfd
commit 376640092e
1 file changed
+39 -7
+39 -7
View File
@@ -15,21 +15,36 @@ import clsx from "clsx";
import extraStyles from "@/components/riddles-css/Riddle_6.module.css"; import extraStyles from "@/components/riddles-css/Riddle_6.module.css";
let acl = null; let acl = null;
let ran = false;
let animVal = 0.0; 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({ export default function Riddle_6({
riddle, riddle,
exitFunction, exitFunction,
showBanner showBanner
}: RiddleScreenControls) { }: RiddleScreenControls) {
const [ page, setPage ] = useState(2); const [ page, setPage ] = useState(1);
const [aclTest, setAclTest ] = useState("X: -\nY: -\nZ: -\nO: -"); const [aclTest, setAclTest ] = useState("X: -\nY: -\nZ: -\nO: -");
const [ overallChange, setOverallChange ] = useState(0); const [ overallChange, setOverallChange ] = useState(0);
const [ animValue, setAnimValue ] = useState(0.0); const [ animValue, setAnimValue ] = useState(0.0);
useEffect(() => { useEffect(() => {
if (page === 2 && acl === null) { if (page === 2 && !ran) {
acl = new Accelerometer({ frequency: 60 }); /*acl = new Accelerometer({ frequency: 60 });
let lastAclReading: number[] | null = null; let lastAclReading: number[] | null = null;
acl.addEventListener("reading", () => { acl.addEventListener("reading", () => {
const readings = [acl.x.toFixed(2), acl.y.toFixed(2), acl.z.toFixed(2)]; 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]; lastAclReading = [...readings];
}); });
acl.start(); acl.start();*/
showBanner(false); // FIXME: TESTING ran = true;
} }
}, [page]); }, [page]);
@@ -73,10 +88,27 @@ export default function Riddle_6({
<p>Die Prüfung beginnt, sobald ihr bereit seid.</p> <p>Die Prüfung beginnt, sobald ihr bereit seid.</p>
</div> </div>
<div className={styles["buttons"]}> <div className={styles["buttons"]}>
<ChargedButton red={false} onAction={() => { <OldButton red={false} onAction={() => {
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); setPage(2);
showBanner(false); showBanner(false);
}} disabled={false} holdDuration={500}>STARTEN</ChargedButton> }} disabled={false}>STARTEN</OldButton>
<OldButton red={true} onAction={() => setPage(0)}>ZURÜCK</OldButton> <OldButton red={true} onAction={() => setPage(0)}>ZURÜCK</OldButton>
</div> </div>
</div> </div>