257 lines
12 KiB
TypeScript
257 lines
12 KiB
TypeScript
"use client";
|
|
|
|
import { useLocalStorage } from "@/hooks/useLocalStorage"
|
|
import { PREF } from "@/utils/const"
|
|
import { parsePlayerData } from "@/utils/dataparser";
|
|
import ChargedButton from "../ChargedButton";
|
|
import styles from "@/css/Tour.module.css";
|
|
import MapView, { PlaceMarker } from "../MapView";
|
|
import { MouseEventHandler, useEffect, useState } from "react";
|
|
import { usePermissions } from "@/hooks/usePermission";
|
|
import PermissionCheck from "../PermissionCheck";
|
|
import clsx from "clsx";
|
|
import OldButton from "../OldButton";
|
|
import RiddleScreen from "../RiddleScreen";
|
|
import OldPopUp from "../OldPopUp";
|
|
import { MAX_POINTS, MIN_POINTS } from "@/utils/points";
|
|
|
|
export default function Tour() {
|
|
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
|
const [ activeRiddle, setActiveRiddle ] = useState<string | null>("riddle_1");
|
|
const [ clickedMarker, setClickedMarker ] = useState({
|
|
"id": "riddle_1",
|
|
"station_name": "Station 1",
|
|
"station_title": "Der Hüter des Tores"
|
|
});
|
|
const [ tourCode, setTourCode ] = useLocalStorage(PREF.code, "");
|
|
const [ completedRiddlesStr, setCompletedRiddles ] = useLocalStorage(PREF.completed_riddles, "");
|
|
const [ playersStr, setPlayers ] = useLocalStorage(PREF.players, "");
|
|
const [ pointsStr, setPoints ] = useLocalStorage(PREF.points, "0");
|
|
const [ markers, setMarkers ] = useState<PlaceMarker[]>([]);
|
|
const { gpsStatus, cameraStatus } = usePermissions();
|
|
const points = Number.parseInt(pointsStr);
|
|
const players = parsePlayerData(playersStr);
|
|
|
|
const permissionsGranted = gpsStatus === "granted" && cameraStatus === "granted";
|
|
|
|
const riddleData = {
|
|
"riddle_1": {
|
|
"id": "riddle_1",
|
|
"station_name": "Station 1",
|
|
"station_title": "Der Hüter des Tores"
|
|
},
|
|
"riddle_2": {
|
|
"id": "riddle_2",
|
|
"station_name": "Station 2",
|
|
"station_title": "Das Schwert im Stein"
|
|
},
|
|
"riddle_3": {
|
|
"id": "riddle_3",
|
|
"station_name": "Station 3",
|
|
"station_title": "Die Stimme des neuen Königs"
|
|
},
|
|
"riddle_4": {
|
|
"id": "riddle_4",
|
|
"station_name": "Station 4",
|
|
"station_title": "Stimmen am Wegesrand"
|
|
},
|
|
"riddle_5": {
|
|
"id": "riddle_5",
|
|
"station_name": "Station 5",
|
|
"station_title": "Jenseits der bekannten Wege"
|
|
},
|
|
"riddle_6": {
|
|
"id": "riddle_6",
|
|
"station_name": "Station 6",
|
|
"station_title": "Die Prüfung der Stille"
|
|
},
|
|
"riddle_7": {
|
|
"id": "riddle_7",
|
|
"station_name": "Station 7",
|
|
"station_title": "Lancelots Urteil"
|
|
},
|
|
"riddle_8": {
|
|
"id": "riddle_8",
|
|
"station_name": "Station 8",
|
|
"station_title": "Merlins Prüfung"
|
|
},
|
|
"riddle_9": {
|
|
"id": "riddle_9",
|
|
"station_name": "Station 9",
|
|
"station_title": "Die Tafelrunde"
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
let timerId: string | number | NodeJS.Timeout | undefined;
|
|
|
|
const requestPosition = () => {
|
|
timerId = setTimeout(() => {
|
|
navigator.geolocation.getCurrentPosition(
|
|
(position) => {
|
|
setMarkers([
|
|
{
|
|
id: "riddle_1",
|
|
title: "Erstes Rätsel",
|
|
description: "Test Punkt verschoben vom Standort",
|
|
lng: position.coords.longitude + 0.002,
|
|
lat: position.coords.latitude,
|
|
},
|
|
{
|
|
id: "riddle_2",
|
|
title: "Zweites Rätsel",
|
|
description: "Test Punkt verschoben vom Standort",
|
|
lng: position.coords.longitude + 0.004,
|
|
lat: position.coords.latitude,
|
|
},
|
|
{
|
|
id: "riddle_3",
|
|
title: "Drittes Rätsel",
|
|
description: "Test Punkt verschoben vom Standort",
|
|
lng: position.coords.longitude + 0.006,
|
|
lat: position.coords.latitude,
|
|
},
|
|
{
|
|
id: "riddle_4",
|
|
title: "Viertes Rätsel",
|
|
description: "Test Punkt verschoben vom Standort",
|
|
lng: position.coords.longitude + 0.008,
|
|
lat: position.coords.latitude,
|
|
},
|
|
{
|
|
id: "riddle_5",
|
|
title: "Fünftes Rätsel",
|
|
description: "Test Punkt verschoben vom Standort",
|
|
lng: position.coords.longitude + 0.01,
|
|
lat: position.coords.latitude,
|
|
},
|
|
{
|
|
id: "riddle_6",
|
|
title: "Sechstes Rätsel",
|
|
description: "Test Punkt verschoben vom Standort",
|
|
lng: position.coords.longitude + 0.012,
|
|
lat: position.coords.latitude,
|
|
},
|
|
{
|
|
id: "riddle_7",
|
|
title: "Siebtes Rätsel",
|
|
description: "Test Punkt verschoben vom Standort",
|
|
lng: position.coords.longitude + 0.014,
|
|
lat: position.coords.latitude,
|
|
},
|
|
{
|
|
id: "riddle_8",
|
|
title: "Achtes Rätsel",
|
|
description: "Test Punkt verschoben vom Standort",
|
|
lng: position.coords.longitude + 0.016,
|
|
lat: position.coords.latitude,
|
|
},
|
|
{
|
|
id: "riddle_9",
|
|
title: "Neuntes Rätsel",
|
|
description: "Test Punkt verschoben vom Standort",
|
|
lng: position.coords.longitude + 0.018,
|
|
lat: position.coords.latitude,
|
|
},
|
|
]);
|
|
},
|
|
(error) => {
|
|
requestPosition();
|
|
}
|
|
);
|
|
}, 500);
|
|
};
|
|
|
|
requestPosition();
|
|
|
|
return () => clearTimeout(timerId);
|
|
}, []);
|
|
|
|
const _dismissFunc = () => {
|
|
setActiveRiddle(null);
|
|
setClickedMarker(null);
|
|
};
|
|
|
|
const dismissFunc: MouseEventHandler<HTMLImageElement> = (e) => {
|
|
_dismissFunc();
|
|
e.stopPropagation();
|
|
};
|
|
|
|
return (
|
|
<div className={styles["screen-container"]}>
|
|
<div className={styles["top-bar"]}>
|
|
<div className={styles["top-bar-content"]}>
|
|
<div className={styles["corner-bar"]}>
|
|
<img src="/container/Ecke_Verzierung.webp" className={clsx(styles["corner"])} style={{rotate: "90deg"}} />
|
|
<img src="/container/Ecke_Verzierung.webp" className={clsx(styles["corner"])} style={{rotate: "180deg"}} />
|
|
</div>
|
|
<img src="/icons/krone.svg" className={clsx(styles["crown"])} />
|
|
<p className="eisenkraft-regular">Rufpunkte</p>
|
|
<span className={styles["points-outer-box"]}>
|
|
<svg
|
|
style={{position: "absolute", inset: "0", width: "100%", height: "100%", overflow: "visible"}}
|
|
viewBox="0 0 290 20"
|
|
preserveAspectRatio="none"
|
|
>
|
|
<rect width="100%" height="100%" fill="none" />
|
|
<path d="M 6 0 H 284 Q 284 6 290 6 V 14 Q 284 14 284 20 H 6 Q 6 14 0 14 V 6 Q 6 6 6 0 Z"
|
|
fill="none"
|
|
stroke="#71654d"
|
|
strokeWidth="2"
|
|
vectorEffect="non-scaling-stroke"
|
|
/>
|
|
</svg>
|
|
<div className={styles["points-inner-box"]} style={{width: `${((points+Math.abs(MIN_POINTS))/(MAX_POINTS+Math.abs(MIN_POINTS)))*100}%`}}>
|
|
</div>
|
|
</span>
|
|
<p className="eisenkraft-regular" style={{marginTop: "4px"}}>{`${points} / ${MAX_POINTS}`}</p>
|
|
</div>
|
|
</div>
|
|
<div className={styles["main-content"]}>
|
|
<div className={styles["map"]}>
|
|
<MapView markers={markers} onMarkerClick={(marker) => {
|
|
console.log(marker);
|
|
setClickedMarker(marker["id"]);
|
|
}}></MapView>
|
|
</div>
|
|
<div className={styles["riddle-overlay"]} style={{display: clickedMarker !== null ? "" : "none"}}>
|
|
{ activeRiddle === null ?
|
|
<OldPopUp onDismiss={dismissFunc}>
|
|
<div style={{textAlign: "center", width: "100%"}}>
|
|
<p className="eisenkraft-regular" style={{fontSize: "1.25rem"}}>{riddleData[clickedMarker]?.["station_name"]}</p>
|
|
<p className="eisenkraft-regular" style={{fontSize: "1.75rem"}}>{riddleData[clickedMarker]?.["station_title"]}</p>
|
|
<OldButton
|
|
red={false}
|
|
long={true}
|
|
style={{margin: "auto", marginTop: "8px"}}
|
|
onAction={(e) => {
|
|
setActiveRiddle(clickedMarker);
|
|
e.stopPropagation();
|
|
}}
|
|
>STARTEN</OldButton>
|
|
</div>
|
|
</OldPopUp>
|
|
:
|
|
<RiddleScreen onDismiss={_dismissFunc} riddle={riddleData?.[activeRiddle]}></RiddleScreen>
|
|
}
|
|
</div>
|
|
{ !permissionsGranted ?
|
|
<div className={styles["permissions-overlay"]}>
|
|
<PermissionCheck className={styles["permission-check"]}></PermissionCheck>
|
|
</div>
|
|
: null
|
|
}
|
|
</div>
|
|
<ChargedButton holdDuration={600} onAction={() => {
|
|
setStep("0");
|
|
setPlayers("");
|
|
setPoints("");
|
|
setCompletedRiddles("");
|
|
setTourCode("");
|
|
localStorage.clear();
|
|
}}
|
|
style={{position: "absolute", bottom: "50px", left: "0", zIndex: 9}}
|
|
>Zurücksetzen</ChargedButton>
|
|
</div>
|
|
)
|
|
} |