intro, map, layout, permissions
This commit is contained in:
1 parent
efdbbdfc76
commit
d9387f464f
16 files changed
+204
-131
No files matched your search
@@ -4,50 +4,38 @@ import ChargedButton from "../ChargedButton";
|
||||
import { usePermissions } from "@/hooks/usePermission";
|
||||
import styles from "@/css/Intro.module.css";
|
||||
import { InputEvent, MouseEvent, MouseEventHandler, PointerEvent, useRef, useState } from "react";
|
||||
import Image from "next/image";
|
||||
import PermissionCheck from "../PermissionCheck";
|
||||
import { PermissionStateResult } from "@/utils/permissions";
|
||||
|
||||
export default function Intro() {
|
||||
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
const { gpsStatus, cameraStatus, refresh } = usePermissions();
|
||||
const [ rewatchScreen, setRewatchScreen ] = useState(false);
|
||||
const [ videoEnded, setVideoEnded ] = useState(false);
|
||||
const [ videoPaused, setVideoPaused ] = useState(false);
|
||||
const introVideoRef = useRef<HTMLVideoElement | null>(null);
|
||||
|
||||
const requestGPSPermission = () => {
|
||||
navigator.geolocation.getCurrentPosition(() => refresh, () => refresh);
|
||||
}
|
||||
const requestCamPermission = () => {
|
||||
navigator.mediaDevices.getUserMedia({
|
||||
"video": { facingMode: { ideal: "environment" } },
|
||||
"audio": false,
|
||||
}).then((stream) => {
|
||||
refresh();
|
||||
stream.getTracks().forEach(track => track.stop());
|
||||
alert("Keine Sorge! Die Kamera ist wieder ausgeschalten. Der Gerät zeigt Ihnen nur, dass darauf kurz zugegriffen wurde.");
|
||||
}).catch((e) => refresh);
|
||||
}
|
||||
const [ granted, setGranted ] = useState(false);
|
||||
|
||||
const handleVideoClick = (e: PointerEvent<HTMLVideoElement>): boolean => {
|
||||
e.currentTarget.play();
|
||||
return true;
|
||||
};
|
||||
|
||||
const handlePermissions = (gps: PermissionStateResult, cam: PermissionStateResult) => {
|
||||
setGranted(gps === "granted" && cam === "granted");
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="screen-container">
|
||||
{ !rewatchScreen ?
|
||||
<div>
|
||||
<p>CODE EINGELÖST</p>
|
||||
<p>TON AN</p>
|
||||
<p>Für diese Tour werden extra Berechtigungen gebraucht.</p>
|
||||
<p>Kamera: {cameraStatus}</p>
|
||||
<p>GPS: {gpsStatus}</p>
|
||||
<br></br>
|
||||
<button onClick={requestGPSPermission} style={{marginBottom: "2rem", marginRight: "3rem"}}>GPS</button>
|
||||
<button onClick={requestCamPermission} style={{marginBottom: "2rem", marginRight: "3rem"}}>Cam</button>
|
||||
<button onClick={refresh} style={{marginBottom: "2rem", marginRight: "3rem"}}>Refresh</button>
|
||||
<PermissionCheck onRefresh={handlePermissions}></PermissionCheck>
|
||||
<br></br>
|
||||
<ChargedButton onAction={() => {
|
||||
setRewatchScreen(true);
|
||||
}} holdDuration={500} disabled={gpsStatus !== "granted" || cameraStatus !== "granted"}>
|
||||
}} holdDuration={500} disabled={!granted}>
|
||||
Video ansehen
|
||||
</ChargedButton>
|
||||
<div className={styles["overlay-video"]}>
|
||||
@@ -66,14 +54,23 @@ export default function Intro() {
|
||||
onEnded={() => setVideoEnded(true)}
|
||||
onAbort={() => setVideoEnded(true)}
|
||||
onError={() => setVideoEnded(true)}
|
||||
onPause={() => setVideoPaused(true)}
|
||||
onPlay={() => setVideoPaused(false)}
|
||||
onClick={handleVideoClick}
|
||||
onContextMenu={(e) => {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<source src="/res/testvid.webm" type="video/webm"/>
|
||||
<source src="/res/intro/testvid.webm" type="video/webm"/>
|
||||
</video>
|
||||
{ !videoEnded && videoPaused ?
|
||||
<div className={styles["pause-screen"]}>
|
||||
<Image src="/icons/pause.svg" alt="Pause Icon" width={48} height={48}/>
|
||||
</div>
|
||||
:
|
||||
null
|
||||
}
|
||||
{ videoEnded ? <div className={styles["rewatch-controls"]}>
|
||||
<ChargedButton holdDuration={500} onAction={() => {
|
||||
if (introVideoRef.current) {
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
"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 from "../MapView";
|
||||
import MapView, { PlaceMarker } from "../MapView";
|
||||
import { useEffect, useState } from "react";
|
||||
import { usePermissions } from "@/hooks/usePermission";
|
||||
import PermissionCheck from "../PermissionCheck";
|
||||
|
||||
export default function Tour() {
|
||||
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
@@ -11,13 +16,46 @@ export default function Tour() {
|
||||
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 step = Number.parseInt(stepStr) || 0;
|
||||
const points = Number.parseInt(pointsStr) || 0;
|
||||
const players = parsePlayerData(playersStr);
|
||||
|
||||
const permissionsGranted = gpsStatus === "granted" && cameraStatus === "granted";
|
||||
|
||||
const [ test, setTest ] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let timerId: string | number | NodeJS.Timeout | undefined;
|
||||
|
||||
const requestPosition = () => {
|
||||
timerId = setTimeout(() => {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(position) => {
|
||||
setMarkers([{
|
||||
id: "riddle_one",
|
||||
title: "Erstes Rätsel",
|
||||
description: "Test Punkt verschoben vom Standort",
|
||||
lng: position.coords.longitude + 0.002,
|
||||
lat: position.coords.latitude,
|
||||
}]);
|
||||
},
|
||||
(error) => {
|
||||
requestPosition();
|
||||
}
|
||||
);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
requestPosition();
|
||||
|
||||
return () => clearTimeout(timerId);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="screen-container">
|
||||
<div>
|
||||
<div className={styles["screen-container"]}>
|
||||
<div className={styles["top-bar"]}>
|
||||
<p>{"Ruf: " + points}</p>
|
||||
<p>{"Players: " + playersStr}</p>
|
||||
<br></br>
|
||||
@@ -34,11 +72,23 @@ export default function Tour() {
|
||||
</div>
|
||||
<div className={styles["main-content"]}>
|
||||
<div className={styles["map"]}>
|
||||
<MapView></MapView>
|
||||
<MapView markers={markers} onMarkerClick={(marker) => {
|
||||
if (marker.id === "riddle_one") {
|
||||
setTest(true);
|
||||
}
|
||||
}}></MapView>
|
||||
</div>
|
||||
<div className={styles["riddle-overlay"]}>
|
||||
Riddle Overlay
|
||||
<div className={styles["riddle-overlay"]} style={{display: test ? "block" : "none"}} onClick={() => setTest(false)}>
|
||||
<p>Riddle Overlay</p>
|
||||
<p>Idealer weise dann mit Popup Animation (Slide In oder Fade In)</p>
|
||||
<p>Klicken um zu schließen</p>
|
||||
</div>
|
||||
{ !permissionsGranted ?
|
||||
<div className={styles["permissions-overlay"]}>
|
||||
<PermissionCheck></PermissionCheck>
|
||||
</div>
|
||||
: null
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user