diff --git a/public/res/testvid.webm b/public/res/testvid.webm new file mode 100644 index 0000000..b4e4249 Binary files /dev/null and b/public/res/testvid.webm differ diff --git a/src/app/page.tsx b/src/app/page.tsx index 22a394e..4d2b39d 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -19,17 +19,6 @@ export default function Main() { const [ players, setPlayers ] = useLocalStorage(PREF.players, ""); const [ tourCode, setTourCode ] = useLocalStorage(PREF.code, ""); const step = Number.parseInt(stepStr) || 0; - /*const [doTest, setDoTest] = useState(false); - { - console.log("Click!"); - }} - holdDuration={2000} - >Hello - - {doTest && }*/ console.log("STEP", step); console.log("PLAYERS", players, parsePlayerData(players)); diff --git a/src/components/ChargedButton.tsx b/src/components/ChargedButton.tsx index 7263b22..3410698 100644 --- a/src/components/ChargedButton.tsx +++ b/src/components/ChargedButton.tsx @@ -18,7 +18,7 @@ export default function ChargedButton({ children, style, className, - holdDuration = 1000, + holdDuration = 500, onAction, disabled = false, }: ChargedButtonProps) { diff --git a/src/components/MapView.tsx b/src/components/MapView.tsx index a65db11..2236626 100644 --- a/src/components/MapView.tsx +++ b/src/components/MapView.tsx @@ -39,7 +39,7 @@ const TILE_CACHE_NAME = 'excalibur-offline-map-tiles-v1'; const DEFAULT_TILE_URL = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'; export default function MapView({ - initialCenter = [11.5761, 48.1371], // Munich default [lng, lat] + initialCenter = [9.281477, 49.088795], initialZoom = 13, markers = [], onMarkerClick, @@ -55,6 +55,7 @@ export default function MapView({ // 1. Initialize Map instance useEffect(() => { if (!mapContainerRef.current) return; + if (mapRef.current) return; // Standard OpenStreetMap raster style (can be swapped for MapTiler / custom PBF vector style) const mapStyle: maplibregl.StyleSpecification = { @@ -85,10 +86,8 @@ export default function MapView({ zoom: initialZoom, }); - // Default Controls - map.addControl(new maplibregl.NavigationControl({ visualizePitch: true }), 'top-right'); + map.addControl(new maplibregl.NavigationControl({ visualizePitch: true }), 'bottom-right'); - // Offline Geolocation Control (Uses Native Device GPS) const geolocate = new maplibregl.GeolocateControl({ positionOptions: { enableHighAccuracy: true, @@ -97,17 +96,26 @@ export default function MapView({ showUserLocation: true, showAccuracyCircle: true, }); - map.addControl(geolocate, 'top-right'); + map.addControl(geolocate, 'bottom-right'); map.addControl(new maplibregl.ScaleControl({ unit: 'metric' }), 'bottom-left'); + map.on('load', async () => { + navigator.geolocation.getCurrentPosition((pos) => { + map.setCenter([pos.coords.longitude, pos.coords.latitude]); + geolocate.trigger(); + }, () => { + geolocate.trigger(); + }); + }); + mapRef.current = map; return () => { map.remove(); mapRef.current = null; }; - }, [initialCenter, initialZoom, tileUrlTemplate]); + }, [/*initialCenter, initialZoom, tileUrlTemplate Create your own listeners*/]); // 2. Manage Markers Sync useEffect(() => { @@ -217,7 +225,7 @@ export default function MapView({ return (
-
+ {/*
)} -
+
*/}
diff --git a/src/components/screens/Intro.tsx b/src/components/screens/Intro.tsx index 2dd8bdd..74ec743 100644 --- a/src/components/screens/Intro.tsx +++ b/src/components/screens/Intro.tsx @@ -1,21 +1,94 @@ import { useLocalStorage } from "@/hooks/useLocalStorage" import { PREF } from "@/utils/const" 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"; 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 introVideoRef = useRef(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 handleVideoClick = (e: PointerEvent): boolean => { + e.currentTarget.play(); + return true; + }; return (
-

CODE EINGELÖST

-

TON AN

-

Für diese Tour werden extra Berechtigungen gebraucht.

-

- { - setStep("2"); - }} holdDuration={1200}> - Video ansehen - + { !rewatchScreen ? +
+

CODE EINGELÖST

+

TON AN

+

Für diese Tour werden extra Berechtigungen gebraucht.

+

Kamera: {cameraStatus}

+

GPS: {gpsStatus}

+

+ + + +

+ { + setRewatchScreen(true); + }} holdDuration={500} disabled={gpsStatus !== "granted" || cameraStatus !== "granted"}> + Video ansehen + +
+ +
+
+ : +
+ + { videoEnded ?
+ { + if (introVideoRef.current) { + introVideoRef.current.pause(); + introVideoRef.current.currentTime = 0; + introVideoRef.current.play(); + setVideoEnded(false); + } + }}>Video wiederholen? + { + setStep("2"); + }}>Wir sind bereit! +
: null } +
+ }
) } \ No newline at end of file diff --git a/src/components/screens/Tour.tsx b/src/components/screens/Tour.tsx index 2fab7a5..b598ad0 100644 --- a/src/components/screens/Tour.tsx +++ b/src/components/screens/Tour.tsx @@ -2,6 +2,8 @@ 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"; export default function Tour() { const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0"); @@ -16,7 +18,7 @@ export default function Tour() { return (
-

{"Points: " + points}

+

{"Ruf: " + points}

{"Players: " + playersStr}



{ @@ -30,12 +32,11 @@ export default function Tour() { Zurücksetzen
-
- Contains both -
- Map +
+
+
-
+
Riddle Overlay
diff --git a/src/components/screens/WelcomeScreen.tsx b/src/components/screens/WelcomeScreen.tsx index 1f14061..41d3d07 100644 --- a/src/components/screens/WelcomeScreen.tsx +++ b/src/components/screens/WelcomeScreen.tsx @@ -27,6 +27,10 @@ export default function WelcomeScreen() { return tourCode.length === CODE_LENGTH; }; + const cleanTourCode = (dirtyTourCode: string): string => { + return dirtyTourCode.toUpperCase().replaceAll(/\W/g, "").substring(0, 9); + }; + useEffect(() => { if (checkCooldown()) { setIsCooldown(true); @@ -41,7 +45,7 @@ export default function WelcomeScreen() { }, [lastSubmitTs]); const submit = () => { - const value = tourCodeRef.current; + const value = cleanTourCode(tourCodeRef.current); if (!isTourCodeValid() && checkCooldown()) { return; @@ -63,7 +67,7 @@ export default function WelcomeScreen() { return false; } tourCodeRef.current = value; - setTourCode(value.toUpperCase().replaceAll(/\W/g, "")); + setTourCode(cleanTourCode(value)); return true; }; @@ -83,7 +87,7 @@ export default function WelcomeScreen() {