118 lines
5.4 KiB
TypeScript
118 lines
5.4 KiB
TypeScript
"use client";
|
|
|
|
import styles from "@/css/RiddleHintPage.module.css";
|
|
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
|
import { Riddle } from "@/types/riddle";
|
|
import { PREF } from "@/utils/const";
|
|
import clsx from "clsx";
|
|
import { useMemo, useState } from "react";
|
|
import OldButton from "./OldButton";
|
|
import { addBoughtHint, getBoughtHints } from "@/utils/boughtHints";
|
|
import OldPopUp from "./OldPopUp";
|
|
import { getPoints, takePoints } from "@/utils/points";
|
|
import VoiceOver from "./VoiceOver";
|
|
import { VoiceOverMode } from "@/types/voiceOverMode";
|
|
|
|
interface RiddleHintProps {
|
|
riddle: Riddle;
|
|
onSkip?: (() => void) | null;
|
|
dismissHintPage: () => void;
|
|
voiceOverMode: VoiceOverMode;
|
|
};
|
|
|
|
export default function RiddleHintPage({
|
|
riddle,
|
|
onSkip,
|
|
dismissHintPage,
|
|
voiceOverMode
|
|
}: RiddleHintProps) {
|
|
//const [ pointsStr, ] = useLocalStorage(PREF.points, "");
|
|
const [ boughtHintsStr, ] = useLocalStorage(PREF.boughtHints, "");
|
|
const [ showBuyHint, setShowBuyHint ] = useState(false);
|
|
const [ showSkipRiddle, setShowSkipRiddle ] = useState(false);
|
|
const [ currentVoiceOver, setCurrentVoiceOver ] = useState(-1);
|
|
|
|
const boughtHints = useMemo(() => {
|
|
return getBoughtHints();
|
|
}, [boughtHintsStr]);
|
|
|
|
/*const points = useMemo(() => {
|
|
return getPoints();
|
|
}, [pointsStr]);*/
|
|
|
|
const sortedHints = useMemo(() => {
|
|
return [...riddle.hints].sort((a, b) => a.hintOrder - b.hintOrder);
|
|
}, [riddle.hints]);
|
|
|
|
const boughtHintObjects = useMemo(() => {
|
|
return sortedHints.filter(h => boughtHints.includes(h.id));
|
|
}, [sortedHints, boughtHints]);
|
|
|
|
const nextHintToBuy = useMemo(() => {
|
|
return sortedHints.find(h => !boughtHints.includes(h.id));
|
|
}, [sortedHints, boughtHints]);
|
|
|
|
return (
|
|
<div className={clsx(styles["container"])}>
|
|
{ currentVoiceOver > -1 ?
|
|
<VoiceOver voiceOverMode={voiceOverMode}
|
|
sources={[
|
|
{
|
|
src: "/res/tour/riddle_" + (riddle.step + 1) + "/voiceovers/Hinweis " + currentVoiceOver + ".mp3",
|
|
type: "audio/mpeg"
|
|
}
|
|
]}
|
|
/>
|
|
: null}
|
|
<div className={styles["header"]}>
|
|
<img src={"/icons/hinweis-dunkel.svg"} className={styles["hint-icon"]}/>
|
|
<p className={clsx(styles["hint-p"], "eisenkraft-regular")}>Hinweise</p>
|
|
</div>
|
|
{ nextHintToBuy && nextHintToBuy.penaltyPoints > 0 && <p>Ein {boughtHintObjects.length > 0 ? "weiterer" : ""} Hinweis kostet euch {nextHintToBuy.penaltyPoints} Rufpunkte.</p> }
|
|
{ nextHintToBuy && nextHintToBuy.penaltyPoints === 0 && <p>Ein {boughtHintObjects.length > 0 ? "weiterer" : ""} Hinweis kostet euch zum Glück keine Rufpunkte.</p> }
|
|
{ riddle.hints.length === 0 && <p>Für das Rätsel gibt es keine Hinweise!</p> }
|
|
{ riddle.skipPenaltyPoints === 0 && <p>Überspringt ihr das Rätsel, bekommt ihr keine Rufpunkte.</p> }
|
|
{ riddle.skipPenaltyPoints > 0 && <p>Überspringt ihr das Rätsel, bekommt ihr {riddle.skipPenaltyPoints} Rufpunkte abgezogen.</p> }
|
|
{ riddle.skipPenaltyPoints < 0 && <p>Das Rätsel kann nicht übersprungen werden!</p> }
|
|
<div className="center-flex">
|
|
<OldButton red={false} onAction={() => setShowBuyHint(true)} disabled={nextHintToBuy === undefined} style={{marginBottom: "1rem"}}>HINWEIS KAUFEN</OldButton>
|
|
</div>
|
|
{boughtHintObjects.map((hint, index) => (
|
|
<div key={hint.id}>
|
|
<p><strong>Hinweis {index + 1}:</strong> <br></br>{hint.hint}</p>
|
|
</div>
|
|
))}
|
|
<div className="center-flex">
|
|
<OldButton red={true} onAction={() => setShowSkipRiddle(true)} disabled={riddle.skipPenaltyPoints < 0} style={{marginTop: "1rem"}}>RÄTSEL ÜBERSPRINGEN</OldButton>
|
|
</div>
|
|
{ (showBuyHint || showSkipRiddle) && <div className={clsx(styles["popup"])}>
|
|
{ showBuyHint && nextHintToBuy &&
|
|
<OldPopUp onDismiss={() => setShowBuyHint(false)}>
|
|
<div className="center-flex">
|
|
<p>Möchtet ihr diesen Hinweis für {nextHintToBuy.penaltyPoints} Rufpunkte kaufen?</p>
|
|
<OldButton red={true} /*disabled={points >= nextHintToBuy.penaltyPoints}*/ onAction={() => {
|
|
addBoughtHint(nextHintToBuy.id);
|
|
setCurrentVoiceOver(nextHintToBuy.hintOrder + 1)
|
|
takePoints(nextHintToBuy.penaltyPoints);
|
|
setShowBuyHint(false);
|
|
}}>JA, KAUFEN!</OldButton>
|
|
</div>
|
|
</OldPopUp>
|
|
}
|
|
{ showSkipRiddle &&
|
|
<OldPopUp onDismiss={() => setShowSkipRiddle(false)}>
|
|
<div className="center-flex">
|
|
<p>Wollt ihr das Rätsel wirklich überspringen?</p>
|
|
<OldButton red={true} onAction={() => {
|
|
takePoints(riddle.skipPenaltyPoints);
|
|
dismissHintPage();
|
|
if (onSkip) onSkip();
|
|
//TODO: Add completeRiddle
|
|
}}>JA, ÜBERSPRINGEN</OldButton>
|
|
</div>
|
|
</OldPopUp>
|
|
}
|
|
</div> }
|
|
</div>
|
|
);
|
|
} |