RIDDLE!!!!!!!!!! 6!!!!!!!!!!!!!
This commit is contained in:
1 parent
4929b39bfd
commit
376640092e
1 file changed
+39
-7
@@ -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({
|
||||
<p>Die Prüfung beginnt, sobald ihr bereit seid.</p>
|
||||
</div>
|
||||
<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);
|
||||
showBanner(false);
|
||||
}} disabled={false} holdDuration={500}>STARTEN</ChargedButton>
|
||||
}} disabled={false}>STARTEN</OldButton>
|
||||
<OldButton red={true} onAction={() => setPage(0)}>ZURÜCK</OldButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user