Riddle_6
This commit is contained in:
1 parent
d8f840efa8
commit
26a2a9fb69
5 files changed
+236
-102
No files matched your search
@@ -1,22 +1,27 @@
|
||||
import styles from "@/css/OldPopUp.module.css";
|
||||
import clsx from "clsx";
|
||||
import { MouseEventHandler, ReactNode } from "react";
|
||||
|
||||
interface OldPopUpProps {
|
||||
children?: ReactNode;
|
||||
onDismiss?: MouseEventHandler<HTMLImageElement>;
|
||||
haveDismissButton?: boolean;
|
||||
contentClassName?: string;
|
||||
};
|
||||
|
||||
export default function OldPopUp({
|
||||
children,
|
||||
onDismiss,
|
||||
haveDismissButton = true,
|
||||
contentClassName
|
||||
}: OldPopUpProps) {
|
||||
return (
|
||||
<div className={styles["popup-container"]}>
|
||||
<img src="/bg/Pop-Up.webp" className={styles["popup-img"]}/>
|
||||
<div className={styles["popup-controls"]}>
|
||||
<div style={{textAlign: "right", width: "100%"}}>
|
||||
<div className={clsx(styles["popup-controls"], contentClassName)}>
|
||||
{ haveDismissButton && <div style={{textAlign: "right", width: "100%"}}>
|
||||
<img src="/icons/kreuz.svg" className={styles["popup-close"]} onClick={onDismiss}/>
|
||||
</div>
|
||||
</div> }
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { VoiceOverMode } from "@/types/voiceOverMode";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { ReactEventHandler, useEffect, useRef } from "react";
|
||||
|
||||
export type VoiceOverSource = {
|
||||
src: string;
|
||||
@@ -9,9 +9,10 @@ export type VoiceOverSource = {
|
||||
interface VoiceOverProps {
|
||||
sources: VoiceOverSource[];
|
||||
voiceOverMode: VoiceOverMode;
|
||||
onEnded?: ReactEventHandler<HTMLAudioElement> | undefined;
|
||||
}
|
||||
|
||||
export default function VoiceOver({ sources, voiceOverMode }: VoiceOverProps) {
|
||||
export default function VoiceOver({ sources, voiceOverMode, onEnded = undefined }: VoiceOverProps) {
|
||||
const audioRef = useRef<HTMLAudioElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -34,6 +35,7 @@ export default function VoiceOver({ sources, voiceOverMode }: VoiceOverProps) {
|
||||
controlsList="nodownload nofullscreen"
|
||||
preload="auto"
|
||||
playsInline={true}
|
||||
onEnded={onEnded}
|
||||
>
|
||||
{sources.map((source, index) => (
|
||||
<source key={source.src || index} src={source.src} type={source.type} />
|
||||
|
||||
@@ -11,4 +11,30 @@
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
.error-popup {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100dvh;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.error-message-text {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.error-content {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
@@ -1,37 +1,25 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useEffect, useState, useRef } from "react";
|
||||
import OldButton from "../OldButton";
|
||||
import OldPopUp from "../OldPopUp";
|
||||
import styles from "@/css/RiddleStyles.module.css";
|
||||
import screenStyles from "@/css/RiddleScreen.module.css";
|
||||
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
||||
import { PREF } from "@/utils/const";
|
||||
import { RiddleScreenControls } from "../RiddleScreen";
|
||||
import { addPoints } from "@/utils/points";
|
||||
import RiddleCompleteBanner from "../RiddleCompleteBanner";
|
||||
import { getPlayers } from "@/utils/players";
|
||||
import ChargedButton from "../ChargedButton";
|
||||
import clsx from "clsx";
|
||||
import extraStyles from "@/components/riddles-css/Riddle_6.module.css";
|
||||
import VoiceOver from "../VoiceOver";
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
const ERROR_MESSAGES = [
|
||||
{ text: "Noch seid ihr zu unruhig. Ein angehender König sollte schließlich nicht zittern wie ein Blatt im Herbstwind. Findet eure Ruhe und versucht es erneut.", audio: "/res/tour/riddle_6/voiceovers/Fehlermeldung_1.mp3" },
|
||||
{ text: "Fast geschafft. Eure Ruhe reicht noch nicht ganz aus; atmet langsam, bewegt euch so wenig wie möglich und versucht es noch einmal.", audio: "/res/tour/riddle_6/voiceovers/Fehlermeldung_2.mp3" },
|
||||
{ text: "Die Prüfung läuft weiter. Die alten Ritter hätten euch für diesen Versuch wohl noch keinen Platz an ihrer Tafel angeboten. Sammelt euch und versucht es erneut.", audio: "/res/tour/riddle_6/voiceovers/Fehlermeldung_3.mp3" },
|
||||
{ text: "Nicht jede Prüfung lässt sich erzwingen. Je mehr ihr euch zur Ruhe zwingt, desto schwerer scheint sie zu werden. Lockert die Schultern, findet euren Rhythmus und beginnt erneut.", audio: "/res/tour/riddle_6/voiceovers/Fehlermeldung_4.mp3" },
|
||||
{ text: "Das war knapp. Für einen Augenblick wart ihr vollkommen ruhig, doch eine kleine Bewegung hat euch verraten. Versucht es noch einmal – diesmal fehlt nicht mehr viel.", audio: "/res/tour/riddle_6/voiceovers/Fehlermeldung_5.mp3" },
|
||||
{ text: "Der Wald ist still, ihr noch nicht ganz. Nehmt euch einen Moment, kommt zur Ruhe und versucht es erneut. Die Ritter haben schließlich Jahrhunderte gewartet; ein paar Sekunden mehr werden sie verkratzen.", audio: "/res/tour/riddle_6/voiceovers/Fehlermeldung_6.mp3" }
|
||||
];
|
||||
|
||||
export default function Riddle_6({
|
||||
page,
|
||||
@@ -40,47 +28,168 @@ export default function Riddle_6({
|
||||
showBanner,
|
||||
exitFunction,
|
||||
voiceOverMode,
|
||||
requestingHint,
|
||||
dismissHint,
|
||||
}: RiddleScreenControls) {
|
||||
const [aclTest, setAclTest ] = useState("X: -\nY: -\nZ: -\nO: -");
|
||||
const [ overallChange, setOverallChange ] = useState(0);
|
||||
const [ animValue, setAnimValue ] = useState(0.0);
|
||||
const [mode, setMode] = useState<'idle' | 'tracking' | 'fallback' | 'won'>('idle');
|
||||
const [popupData, setPopupData] = useState<{ text: string, audio: string } | null>(null);
|
||||
const closePopupRef = useRef<(() => void) | null>(null);
|
||||
|
||||
const voiceOverModeRef = useRef(voiceOverMode);
|
||||
useEffect(() => {
|
||||
voiceOverModeRef.current = voiceOverMode;
|
||||
}, [voiceOverMode]);
|
||||
|
||||
const handleClosePopup = () => {
|
||||
if (closePopupRef.current) {
|
||||
closePopupRef.current();
|
||||
} else {
|
||||
setPopupData(null);
|
||||
}
|
||||
};
|
||||
|
||||
// Nur bei "off" greift der 6-Sekunden-Timer. Bei "on" steuert das VoiceOver (via onEnded) wann es schließt.
|
||||
useEffect(() => {
|
||||
if (!popupData || voiceOverMode === "on") return;
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
handleClosePopup();
|
||||
}, 9000);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [popupData, voiceOverMode]);
|
||||
|
||||
useEffect(() => {
|
||||
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)];
|
||||
if (lastAclReading !== null) {
|
||||
animVal = Math.max(0, animVal - 25.5);
|
||||
const o = (lastAclReading[0] - readings[0]) + (lastAclReading[1] - readings[1]) + (lastAclReading[2] - readings[2]);
|
||||
setOverallChange(o);
|
||||
if (Math.abs(o) > 3) {
|
||||
animVal = 255;
|
||||
if (page !== 2 || mode === 'won') return;
|
||||
|
||||
let animationFrameId: number;
|
||||
let motionListener: (event: DeviceMotionEvent) => void;
|
||||
|
||||
let lastMovementTime = Date.now();
|
||||
let lastSensorTick = Date.now();
|
||||
|
||||
let popupActive = false;
|
||||
|
||||
// Fallback-spezifische Variablen
|
||||
let fallbackErrorIndex = 0;
|
||||
let selectedErrorMessages: typeof ERROR_MESSAGES = [];
|
||||
let lastFallbackTriggerTime = Date.now();
|
||||
let nextFallbackInterval = (Math.random() * 6000) + 8000;
|
||||
|
||||
const count = Math.floor(Math.random() * 6) + 1;
|
||||
const shuffled = [...ERROR_MESSAGES].sort(() => 0.5 - Math.random());
|
||||
selectedErrorMessages = shuffled.slice(0, count);
|
||||
console.log(selectedErrorMessages);
|
||||
|
||||
const closePopup = () => {
|
||||
setPopupData(null);
|
||||
popupActive = false;
|
||||
lastMovementTime = Date.now();
|
||||
// Wenn der VoiceOver-Modus an ist, starten wir das Intervall erst NACHDEM das PopUp geschlossen wurde
|
||||
lastFallbackTriggerTime = Date.now();
|
||||
};
|
||||
|
||||
closePopupRef.current = closePopup;
|
||||
|
||||
const triggerNextFallbackError = () => {
|
||||
if (fallbackErrorIndex < selectedErrorMessages.length) {
|
||||
popupActive = true;
|
||||
setPopupData(selectedErrorMessages[fallbackErrorIndex]);
|
||||
fallbackErrorIndex++;
|
||||
} else {
|
||||
winRiddle();
|
||||
}
|
||||
};
|
||||
|
||||
const winRiddle = () => {
|
||||
setMode('won');
|
||||
setPage(3);
|
||||
showBanner(true);
|
||||
};
|
||||
|
||||
if (mode === 'tracking') {
|
||||
motionListener = (event) => {
|
||||
lastSensorTick = Date.now();
|
||||
const { x, y, z } = event.acceleration || {};
|
||||
|
||||
if (x !== null && y !== null && z !== null) {
|
||||
const magnitude = Math.sqrt(x * x + y * y + z * z);
|
||||
|
||||
if (magnitude > 1.2) {
|
||||
lastMovementTime = Date.now();
|
||||
if (!popupActive) {
|
||||
// Im Tracking-Modus wird weiterhin ein zufälliges aus allen Fehlern gewählt
|
||||
popupActive = true;
|
||||
const randomMsg = ERROR_MESSAGES[Math.floor(Math.random() * ERROR_MESSAGES.length)];
|
||||
setPopupData(randomMsg);
|
||||
}
|
||||
}
|
||||
setAclTest(`X: ${readings[0]}\nY: ${readings[1]}\nZ: ${readings[2]}\nO: ${o}`);
|
||||
setAnimValue(animVal);
|
||||
} else {
|
||||
setAclTest(`X: ${readings[0]}\nY: ${readings[1]}\nZ: ${readings[2]}\nO: -`);
|
||||
}
|
||||
lastAclReading = [...readings];
|
||||
});
|
||||
acl.start();*/
|
||||
ran = true;
|
||||
};
|
||||
window.addEventListener('devicemotion', motionListener);
|
||||
}
|
||||
}, [page]);
|
||||
|
||||
const gameLoop = () => {
|
||||
const now = Date.now();
|
||||
|
||||
if (mode === 'tracking') {
|
||||
if (now - lastSensorTick > 2000) {
|
||||
setMode('fallback');
|
||||
// Reset Timer für den Fallback-Start
|
||||
lastFallbackTriggerTime = Date.now();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!popupActive && (now - lastMovementTime >= 10000)) {
|
||||
winRiddle();
|
||||
return;
|
||||
}
|
||||
} else if (mode === 'fallback') {
|
||||
// Wenn kein Popup offen ist und die Zeitklausel für den nächsten Abstand erreicht ist
|
||||
if (!popupActive && (now - lastFallbackTriggerTime >= nextFallbackInterval)) {
|
||||
triggerNextFallbackError();
|
||||
// Nächstes Intervall wieder zufällig bestimmen (8-14 Sekunden)
|
||||
nextFallbackInterval = (Math.random() * 6000) + 8000;
|
||||
lastFallbackTriggerTime = Date.now();
|
||||
}
|
||||
}
|
||||
|
||||
animationFrameId = requestAnimationFrame(gameLoop);
|
||||
};
|
||||
|
||||
animationFrameId = requestAnimationFrame(gameLoop);
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(animationFrameId);
|
||||
if (motionListener) {
|
||||
window.removeEventListener('devicemotion', motionListener);
|
||||
}
|
||||
};
|
||||
}, [page, mode, showBanner, setPage]);
|
||||
|
||||
const handleStartTracking = async () => {
|
||||
let hasSensor = false;
|
||||
|
||||
if (typeof DeviceMotionEvent !== 'undefined' && typeof (DeviceMotionEvent as any).requestPermission === 'function') {
|
||||
try {
|
||||
const permission = await (DeviceMotionEvent as any).requestPermission();
|
||||
if (permission === 'granted') {
|
||||
hasSensor = true;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Berechtigung fehlgeschlagen", error);
|
||||
}
|
||||
} else {
|
||||
hasSensor = true;
|
||||
}
|
||||
|
||||
setMode(hasSensor ? 'tracking' : 'fallback');
|
||||
setPage(2);
|
||||
showBanner(false);
|
||||
};
|
||||
|
||||
const pages = [
|
||||
(
|
||||
<div key={0}>
|
||||
<VoiceOver voiceOverMode={voiceOverMode} sources={[
|
||||
{
|
||||
"src": "/res/tour/riddle_6/voiceovers/Geschichte.mp3",
|
||||
"type": "audio/mpeg"
|
||||
}
|
||||
]}/>
|
||||
<VoiceOver voiceOverMode={voiceOverMode} sources={[{ "src": "/res/tour/riddle_6/voiceovers/Geschichte.mp3", "type": "audio/mpeg" }]}/>
|
||||
<div className={styles["content"]}>
|
||||
<p>Die Spur der alten Ritter führt euch tiefer in den Wald zu Sir Galahad. Doch statt Schwertern, Zielscheiben oder einem Gegner erwartet euch hier etwas vollkommen anderes: Ruhe.</p>
|
||||
<p>Die Ritter der Tafelrunde wussten, dass ein Herrscher nicht nur andere führen, sondern auch sich selbst beherrschen muss. Wer im Zorn entscheidet, bereut; wer aus Angst handelt, verliert den klaren Blick, und wer niemals innehält, hört irgendwann nur noch seine eigene Stimme.</p>
|
||||
@@ -93,12 +202,7 @@ export default function Riddle_6({
|
||||
),
|
||||
(
|
||||
<div key={1}>
|
||||
<VoiceOver voiceOverMode={voiceOverMode} sources={[
|
||||
{
|
||||
"src": "/res/tour/riddle_6/voiceovers/Aufgabe.mp3",
|
||||
"type": "audio/mpeg"
|
||||
}
|
||||
]}/>
|
||||
<VoiceOver voiceOverMode={voiceOverMode} sources={[{ "src": "/res/tour/riddle_6/voiceovers/Aufgabe.mp3", "type": "audio/mpeg" }]}/>
|
||||
<div className={styles["content"]}>
|
||||
<p>Eine Person aus eurer Gruppe legt sich auf die Waldliege.</p>
|
||||
<p>Legt das Spielhandy vorsichtig auf den Bauch dieser Person und versucht, vollkommen ruhig zu bleiben.</p>
|
||||
@@ -108,27 +212,7 @@ export default function Riddle_6({
|
||||
<p>Legt das Spielhandy vorsichtig darauf.</p>
|
||||
<p>Nun versucht ihr gemeinsam, das Handy so ruhig wie möglich zu halten.</p>
|
||||
<div className="center-flex">
|
||||
<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}>STARTEN</OldButton>
|
||||
<OldButton red={false} onAction={handleStartTracking} disabled={false}>STARTEN</OldButton>
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles["buttons"]}>
|
||||
@@ -137,38 +221,54 @@ export default function Riddle_6({
|
||||
</div>
|
||||
),
|
||||
(
|
||||
<div key={2} style={{width: "100%"}}>
|
||||
<div key={2} style={{width: "100%", height: "100%", position: "relative"}}>
|
||||
{/* Automatisches PopUp für Fehlermeldungen */}
|
||||
{popupData && (
|
||||
<div className={extraStyles["error-popup"]}>
|
||||
<OldPopUp haveDismissButton={false} contentClassName={extraStyles["error-content"]}>
|
||||
<VoiceOver
|
||||
voiceOverMode={voiceOverMode}
|
||||
sources={[{ "src": popupData.audio, "type": "audio/mpeg" }]}
|
||||
onEnded={voiceOverMode === "on" ? handleClosePopup : undefined}
|
||||
/>
|
||||
<div className={extraStyles["error-message-text"]}>
|
||||
<p>{popupData.text}</p>
|
||||
</div>
|
||||
</OldPopUp>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className={styles["content"]}>
|
||||
<div className={screenStyles["title"]}>
|
||||
<p className="eisenkraft-regular" style={{fontSize: "1.25rem", color: "var(--blue)"}}>{riddle["station_name"]}</p>
|
||||
<p className="eisenkraft-regular" style={{fontSize: "1.75rem", color: "var(--blue)"}}>{riddle["station_title"]}</p>
|
||||
</div>
|
||||
|
||||
<div className={extraStyles["heart-container"]}>
|
||||
<div className={clsx(extraStyles["heart"])} style={{backgroundColor: "rgb(" + animValue + ", 0, 0)"}}>
|
||||
<p style={{color: "white", whiteSpace: "pre-line"}}>{aclTest}</p>
|
||||
</div>
|
||||
<img
|
||||
src="/icons/Herz.svg"
|
||||
alt="Bitte ruhig halten"
|
||||
style={{ width: "200px", height: "auto", objectFit: "contain" }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles["buttons"]}>
|
||||
<ChargedButton
|
||||
holdDuration={300}
|
||||
red={true}
|
||||
onAction={() => {
|
||||
setPage(3);
|
||||
showBanner(true);
|
||||
}}
|
||||
>Done Testing...</ChargedButton>
|
||||
holdDuration={300}
|
||||
red={true}
|
||||
onAction={() => {
|
||||
setPage(3);
|
||||
showBanner(true);
|
||||
}}
|
||||
>
|
||||
Überspringen (Dev)
|
||||
</ChargedButton>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
(
|
||||
<div key={3}>
|
||||
<VoiceOver voiceOverMode={voiceOverMode} sources={[
|
||||
{
|
||||
"src": "/res/tour/riddle_6/voiceovers/Erfolg.mp3",
|
||||
"type": "audio/mpeg"
|
||||
}
|
||||
]}/>
|
||||
<VoiceOver voiceOverMode={voiceOverMode} sources={[{ "src": "/res/tour/riddle_6/voiceovers/Erfolg.mp3", "type": "audio/mpeg" }]}/>
|
||||
<div className={styles["content"]}>
|
||||
<RiddleCompleteBanner points={500} win={true}></RiddleCompleteBanner>
|
||||
<p>Endlich herrscht vollkommene Ruhe, und für einen kurzen Augenblick scheint selbst der Wald mit euch den Atem anzuhalten.</p>
|
||||
|
||||
Reference in new issue
Block a user