122 lines
5.1 KiB
TypeScript
122 lines
5.1 KiB
TypeScript
import clsx from "clsx";
|
|
import styles from "@/css/RiddleScreen.module.css";
|
|
import StyledContainer from "./StyledContainer";
|
|
import OldButton from "./OldButton";
|
|
import { ComponentType, Dispatch, SetStateAction, useRef, useState } from "react";
|
|
import Riddle_1 from "./riddles/Riddle_1";
|
|
import Riddle_2 from "./riddles/Riddle_2";
|
|
import Riddle_3 from "./riddles/Riddle_3";
|
|
import Riddle_4 from "./riddles/Riddle_4";
|
|
import Riddle_5 from "./riddles/Riddle_5";
|
|
import Riddle_6 from "./riddles/Riddle_6";
|
|
import Riddle_7 from "./riddles/Riddle_7";
|
|
import Riddle_8 from "./riddles/Riddle_8";
|
|
import Riddle_9 from "./riddles/Riddle_9";
|
|
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
|
import { PREF } from "@/utils/const";
|
|
import { VoiceOverMode } from "@/types/voiceOverMode";
|
|
import { Riddle } from "@/types/riddle";
|
|
import { createStationName } from "@/utils/stringer";
|
|
|
|
export interface RiddleScreenControls {
|
|
riddle: Riddle;
|
|
exitFunction: () => Promise<void>;
|
|
showBanner: Dispatch<SetStateAction<boolean>>;
|
|
page: number;
|
|
setPage: (pageIndex: number) => void;
|
|
voiceOverMode: VoiceOverMode;
|
|
requestingHint: boolean;
|
|
dismissHint: () => void;
|
|
onRegisterCloseInterceptor: (closeInterceptor: () => Promise<boolean>) => void;
|
|
};
|
|
|
|
interface RiddleScreenProps {
|
|
riddle: Riddle;
|
|
onDismiss: () => void;
|
|
};
|
|
|
|
export default function RiddleScreen({ riddle, onDismiss }: RiddleScreenProps) {
|
|
const [page, setPage ] = useState(0);
|
|
const [ showHintPage, setShowHintPage ] = useState(false);
|
|
const [ voiceOverState, setVoiceOverState ] = useLocalStorage(PREF.voiceover, "off");
|
|
const [ showBanner, setShowBanner ] = useState(true);
|
|
const contentRef = useRef<HTMLDivElement | null>(null);
|
|
const closeInterceptorRef = useRef<(() => Promise<boolean>) | null>(null);
|
|
|
|
const exitFunction = async () => {
|
|
if (closeInterceptorRef.current) {
|
|
if (!await closeInterceptorRef.current()) {
|
|
return;
|
|
}
|
|
}
|
|
onDismiss();
|
|
};
|
|
|
|
const pageUpdateFunction = (pageIndex: number) => {
|
|
setPage(pageIndex);
|
|
if (contentRef.current !== null) {
|
|
contentRef.current.scrollTop = 0;
|
|
}
|
|
};
|
|
|
|
const props: RiddleScreenControls = {
|
|
"page": page,
|
|
"setPage": pageUpdateFunction,
|
|
"riddle": riddle,
|
|
"showBanner": setShowBanner,
|
|
"exitFunction": exitFunction,
|
|
"voiceOverMode": voiceOverState as VoiceOverMode,
|
|
"requestingHint": showHintPage,
|
|
"dismissHint": () => {
|
|
setShowHintPage(false);
|
|
},
|
|
"onRegisterCloseInterceptor": (fn) => {
|
|
closeInterceptorRef.current = fn;
|
|
}
|
|
};
|
|
|
|
const riddleComponents: Record<number, ComponentType<RiddleScreenControls>> = {
|
|
0: Riddle_1,
|
|
1: Riddle_2,
|
|
2: Riddle_3,
|
|
3: Riddle_4,
|
|
4: Riddle_5,
|
|
5: Riddle_6,
|
|
6: Riddle_7,
|
|
7: Riddle_8,
|
|
8: Riddle_9
|
|
};
|
|
|
|
const SelectedRiddle = riddleComponents[riddle.step];
|
|
|
|
return (
|
|
<div className={clsx("screen-container", styles["container"])}>
|
|
<img src={"/bg/Hintergrund_ohne_Verzierung.webp"} style={{
|
|
position: "absolute",
|
|
top: 0,
|
|
left: 0,
|
|
width: "100%",
|
|
height: "100%",
|
|
objectFit: "fill",
|
|
zIndex: 1
|
|
}} alt="Background" loading="eager"/>
|
|
<StyledContainer riddleDesign={true}>
|
|
<div className={styles["actions-bookmark"]}>
|
|
<img src={"/icons/hinweis.svg"} className={styles["bookmark-icon"]} style={{width: "24px", height: "auto", margin: "12px 24px", marginTop: "12px"}} onClick={() => setShowHintPage(true)} />
|
|
<img src={voiceOverState === "off" ? "/icons/Vorlese-Icon.svg" : "/icons/Vorlese-Icon-leise.svg"} className={styles["bookmark-icon"]} style={{width: "32px", height: "24px", margin: "10px 20px 24px"}} onClick={() => {
|
|
setVoiceOverState(voiceOverState === "off" ? "on" : "off");
|
|
}} />
|
|
</div>
|
|
<img src={(showHintPage) ? "/icons/pfeil.svg" : "/icons/kreuz.svg"} className={clsx(styles["close"], showHintPage && styles["dismiss-hint"])} onClick={(showHintPage) ? () => setShowHintPage(false) : exitFunction}/>
|
|
<div className={styles["content-container"]} ref={contentRef}>
|
|
{ showBanner && !showHintPage ? <div className={styles["title"]}>
|
|
<p className="eisenkraft-regular" style={{fontSize: "1.25rem", color: "var(--blue)"}}>{createStationName(riddle)}</p>
|
|
<p className="eisenkraft-regular" style={{fontSize: "1.75rem", color: "var(--blue)"}}>{riddle.name}</p>
|
|
<img src={"/res/tour/riddle_" + (riddle.step + 1) + "/story.svg"} width={"75%"}/>
|
|
</div> : null }
|
|
{ SelectedRiddle ? <SelectedRiddle {...props}></SelectedRiddle> : <p style={{color: "red"}}>Station konnte nicht gefunden werden!</p>}
|
|
</div>
|
|
</StyledContainer>
|
|
</div>
|
|
);
|
|
} |