Working stuff!
This commit is contained in:
1 parent
9d69d13aa5
commit
5b73127836
9 files changed
+168
-38
No files matched your search
@@ -18,7 +18,7 @@ export default function ChargedButton({
|
||||
children,
|
||||
style,
|
||||
className,
|
||||
holdDuration = 1000,
|
||||
holdDuration = 500,
|
||||
onAction,
|
||||
disabled = false,
|
||||
}: ChargedButtonProps) {
|
||||
|
||||
@@ -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 (
|
||||
<div className={styles.mapWrapper}>
|
||||
<div className={styles.controlOverlay}>
|
||||
{/*<div className={styles.controlOverlay}>
|
||||
<button
|
||||
className={styles.precacheButton}
|
||||
onClick={precacheCurrentRegion}
|
||||
@@ -241,7 +249,7 @@ export default function MapView({
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>*/}
|
||||
|
||||
<div ref={mapContainerRef} className={styles.mapContainer} />
|
||||
</div>
|
||||
|
||||
@@ -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<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 handleVideoClick = (e: PointerEvent<HTMLVideoElement>): boolean => {
|
||||
e.currentTarget.play();
|
||||
return true;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="screen-container">
|
||||
<p>CODE EINGELÖST</p>
|
||||
<p>TON AN</p>
|
||||
<p>Für diese Tour werden extra Berechtigungen gebraucht.</p>
|
||||
<br></br>
|
||||
<ChargedButton onAction={() => {
|
||||
setStep("2");
|
||||
}} holdDuration={1200}>
|
||||
Video ansehen
|
||||
</ChargedButton>
|
||||
{ !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>
|
||||
<br></br>
|
||||
<ChargedButton onAction={() => {
|
||||
setRewatchScreen(true);
|
||||
}} holdDuration={500} disabled={gpsStatus !== "granted" || cameraStatus !== "granted"}>
|
||||
Video ansehen
|
||||
</ChargedButton>
|
||||
<div className={styles["overlay-video"]}>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
:
|
||||
<div className={styles["intro-video-container"]}>
|
||||
<video
|
||||
ref={introVideoRef}
|
||||
disablePictureInPicture={true}
|
||||
autoPlay={true}
|
||||
loop={false}
|
||||
autoFocus={true}
|
||||
width={"100%"}
|
||||
onEnded={() => setVideoEnded(true)}
|
||||
onAbort={() => setVideoEnded(true)}
|
||||
onError={() => setVideoEnded(true)}
|
||||
onClick={handleVideoClick}
|
||||
onContextMenu={(e) => {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}}
|
||||
>
|
||||
<source src="/res/testvid.webm" type="video/webm"/>
|
||||
</video>
|
||||
{ videoEnded ? <div className={styles["rewatch-controls"]}>
|
||||
<ChargedButton holdDuration={500} onAction={() => {
|
||||
if (introVideoRef.current) {
|
||||
introVideoRef.current.pause();
|
||||
introVideoRef.current.currentTime = 0;
|
||||
introVideoRef.current.play();
|
||||
setVideoEnded(false);
|
||||
}
|
||||
}}>Video wiederholen?</ChargedButton>
|
||||
<ChargedButton holdDuration={500} onAction={() => {
|
||||
setStep("2");
|
||||
}}>Wir sind bereit!</ChargedButton>
|
||||
</div> : null }
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="screen-container">
|
||||
<div>
|
||||
<p>{"Points: " + points}</p>
|
||||
<p>{"Ruf: " + points}</p>
|
||||
<p>{"Players: " + playersStr}</p>
|
||||
<br></br>
|
||||
<ChargedButton onAction={() => {
|
||||
@@ -30,12 +32,11 @@ export default function Tour() {
|
||||
Zurücksetzen
|
||||
</ChargedButton>
|
||||
</div>
|
||||
<div>
|
||||
Contains both
|
||||
<div>
|
||||
Map
|
||||
<div className={styles["main-content"]}>
|
||||
<div className={styles["map"]}>
|
||||
<MapView></MapView>
|
||||
</div>
|
||||
<div>
|
||||
<div className={styles["riddle-overlay"]}>
|
||||
Riddle Overlay
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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() {
|
||||
</label>
|
||||
<br></br>
|
||||
<ChargedButton
|
||||
holdDuration={1000}
|
||||
holdDuration={500}
|
||||
onAction={submit}
|
||||
className="screen-submit"
|
||||
disabled={buttonDisabled}
|
||||
|
||||
Reference in new issue
Block a user