DEMO stuff and symbol renames
This commit is contained in:
1 parent
51e5a98a92
commit
45acdd3400
15 files changed
+193
-69
No files matched your search
+26
-19
@@ -20,6 +20,7 @@ export interface MapViewProps {
|
||||
onMarkerClick?: (marker: PlaceMarker, currentPosition?: [number, number] | null) => void;
|
||||
// Default vector tile source or tile pattern
|
||||
tileUrlTemplate?: string;
|
||||
triggerGeolocation?: boolean;
|
||||
}
|
||||
|
||||
// MapTile calculations for Bounding Box precaching (Slippy Map Tile Names)
|
||||
@@ -38,11 +39,12 @@ 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 = [9.282050, 49.090165],
|
||||
initialCenter = [9.283050, 49.091765],
|
||||
initialZoom = 15,
|
||||
markers = [],
|
||||
onMarkerClick,
|
||||
tileUrlTemplate = DEFAULT_TILE_URL,
|
||||
triggerGeolocation = true,
|
||||
}: MapViewProps) {
|
||||
const mapContainerRef = useRef<HTMLDivElement>(null);
|
||||
const mapRef = useRef<maplibregl.Map | null>(null);
|
||||
@@ -84,6 +86,7 @@ export default function MapView({
|
||||
style: mapStyle,
|
||||
center: initialCenter,
|
||||
zoom: initialZoom,
|
||||
maxZoom: 18,
|
||||
});
|
||||
|
||||
map.addControl(new maplibregl.NavigationControl({ visualizePitch: true }), 'bottom-right');
|
||||
@@ -94,33 +97,37 @@ export default function MapView({
|
||||
el.width = 42;
|
||||
el.className = styles["sword"];
|
||||
|
||||
const geolocate = new maplibregl.GeolocateControl({
|
||||
positionOptions: {
|
||||
enableHighAccuracy: true,
|
||||
},
|
||||
trackUserLocation: true,
|
||||
showUserLocation: true,
|
||||
showAccuracyCircle: false,
|
||||
});
|
||||
geolocate._dotElement = el;
|
||||
let geolocate = null;
|
||||
if (triggerGeolocation) {
|
||||
geolocate = new maplibregl.GeolocateControl({
|
||||
positionOptions: {
|
||||
enableHighAccuracy: true,
|
||||
},
|
||||
trackUserLocation: true,
|
||||
showUserLocation: true,
|
||||
showAccuracyCircle: false,
|
||||
});
|
||||
geolocate._dotElement = el;
|
||||
|
||||
geolocate.on('geolocate', (e: any) => {
|
||||
console.log(e);
|
||||
userPositionRef.current = [e.coords.longitude, e.coords.latitude];
|
||||
});
|
||||
geolocate.on('geolocate', (e: any) => {
|
||||
userPositionRef.current = [e.coords.longitude, e.coords.latitude];
|
||||
});
|
||||
|
||||
map.addControl(geolocate, 'bottom-right');
|
||||
map.addControl(geolocate, 'bottom-right');
|
||||
}
|
||||
|
||||
map.addControl(new maplibregl.ScaleControl({ unit: 'metric' }), 'bottom-left');
|
||||
|
||||
map.on('load', async () => {
|
||||
setMapReady(true);
|
||||
navigator.geolocation.getCurrentPosition((pos) => {
|
||||
userPositionRef.current = [pos.coords.longitude, pos.coords.latitude];
|
||||
map.setCenter([pos.coords.longitude, pos.coords.latitude]);
|
||||
geolocate.trigger();
|
||||
if (triggerGeolocation && geolocate) {
|
||||
userPositionRef.current = [pos.coords.longitude, pos.coords.latitude];
|
||||
map.setCenter([pos.coords.longitude, pos.coords.latitude]);
|
||||
geolocate.trigger();
|
||||
}
|
||||
}, () => {
|
||||
geolocate.trigger();
|
||||
if (triggerGeolocation && geolocate) geolocate.trigger();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ export default function RiddleHintPage({
|
||||
voiceOverMode
|
||||
}: RiddleHintProps) {
|
||||
//const [ pointsStr, ] = useLocalStorage(PREF.points, "");
|
||||
const [ boughtHintsStr, ] = useLocalStorage(PREF.boughtHints, "");
|
||||
const [ boughtHintsStr, ] = useLocalStorage(PREF.bought_hints, "");
|
||||
const [ showBuyHint, setShowBuyHint ] = useState(false);
|
||||
const [ showSkipRiddle, setShowSkipRiddle ] = useState(false);
|
||||
const [ currentVoiceOver, setCurrentVoiceOver ] = useState(-1);
|
||||
|
||||
@@ -38,7 +38,7 @@ interface RiddleScreenProps {
|
||||
export default function RiddleScreen({ riddle, onDismiss }: RiddleScreenProps) {
|
||||
const [page, setPage ] = useState(0);
|
||||
const [ showHintPage, setShowHintPage ] = useState(false);
|
||||
const [ voiceOverState, setVoiceOverState ] = useLocalStorage(PREF.voiceover, "off");
|
||||
const [ voiceOverState, setVoiceOverState ] = useLocalStorage(PREF.voice_over, "off");
|
||||
const [ showBanner, setShowBanner ] = useState(true);
|
||||
const contentRef = useRef<HTMLDivElement | null>(null);
|
||||
const closeInterceptorRef = useRef<(() => Promise<boolean>) | null>(null);
|
||||
|
||||
@@ -30,7 +30,7 @@ export default function Riddle_1({
|
||||
requestingHint,
|
||||
dismissHint,
|
||||
}: RiddleScreenControls) {
|
||||
const [ playerCountStr, setPlayerCount ] = useLocalStorage(PREF.playerCount, "");
|
||||
const [ playerCountStr, setPlayerCount ] = useLocalStorage(PREF.player_count, "");
|
||||
const playerCount = Number.parseInt(playerCountStr) || 0;
|
||||
|
||||
const [ nameScreen, setNameScreen ] = useState(0);
|
||||
|
||||
@@ -14,6 +14,7 @@ import RiddleHintPage from "../RiddleHintPage";
|
||||
import { Player } from "@/types/player";
|
||||
import { addCompletedRiddle } from "@/utils/completedRiddles";
|
||||
import ChargedButton from "../ChargedButton";
|
||||
import { isDemoMode } from "@/utils/demoMode";
|
||||
|
||||
export const TOPIC_PREFIX = (process.env.NODE_ENV === "development") ? "staging/outdoor/king-arthur/sword" : "outdoor/king-arthur/sword";
|
||||
|
||||
@@ -69,6 +70,9 @@ export default function Riddle_2({
|
||||
const [ playersStr, ] = useLocalStorage(PREF.players, "");
|
||||
const [ tourCode, ] = useLocalStorage(PREF.code, "");
|
||||
|
||||
const [ demoModeStr, ] = useLocalStorage(PREF.demo_mode, "");
|
||||
const demoMode = useMemo(() => isDemoMode(demoModeStr), [demoModeStr]);
|
||||
|
||||
const [ playerIndex, setPlayerIndex ] = useState(0);
|
||||
const players = useMemo(() => getPlayers(), [playersStr]);
|
||||
const playerOrder = useMemo(() => {
|
||||
@@ -96,6 +100,7 @@ export default function Riddle_2({
|
||||
const [ showControls, setShowControls ] = useState(false);
|
||||
|
||||
const sendCommand = (topic: string, payload: string) => {
|
||||
if (demoMode) return true;
|
||||
if (wsRef.current && wsRef.current.readyState === WebSocket.OPEN) {
|
||||
wsRef.current.send(JSON.stringify({ topic, payload }));
|
||||
return true;
|
||||
@@ -105,6 +110,8 @@ export default function Riddle_2({
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (demoMode) return;
|
||||
|
||||
let isCancelled = false;
|
||||
let reconnectTimeout: NodeJS.Timeout;
|
||||
|
||||
@@ -281,8 +288,12 @@ export default function Riddle_2({
|
||||
setCanGoNext(false);
|
||||
setPlayerIndex(playerIndex+1);
|
||||
}
|
||||
}} disabled={!canGoNext}>{(playerIndex >= players.length-1) ? "PRÜFUNG BEENDEN" : "NÄCHSTER PRÜFLING"}</ChargedButton>
|
||||
}} disabled={!canGoNext && !demoMode}>{(playerIndex >= players.length-1) ? "PRÜFUNG BEENDEN" : "NÄCHSTER PRÜFLING"}</ChargedButton>
|
||||
{playerIndex < 1 ? <OldButton red={true} onAction={async () => {
|
||||
if (demoMode) {
|
||||
setPage(0);
|
||||
return;
|
||||
}
|
||||
awaitTryAbort = false;
|
||||
sendCommand(`${TOPIC_PREFIX}/set`, 'abortTry');
|
||||
await waitUntilTrue(() => {
|
||||
@@ -308,7 +319,7 @@ export default function Riddle_2({
|
||||
<p>Erst wenn euer Beweis für die Nachwelt geschaffen ist, steckt Excalibur zurück in den Stein. Denn aus der Ferne erreicht euch noch immer kein Jubel, sondern nur Schweigen. Offenbar genügt es nicht mehr, das Schwert zu ziehen.</p>
|
||||
</div>
|
||||
<div className={styles["buttons"]}>
|
||||
<OldButton red={false} disabled={!isSwordBackIn} onAction={() => exitFunction()}>ZURÜCK ZUR KARTE</OldButton>
|
||||
<OldButton red={false} disabled={!isSwordBackIn && !demoMode} onAction={() => exitFunction()}>ZURÜCK ZUR KARTE</OldButton>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ import { PREF } from "@/utils/const"
|
||||
import ChargedButton from "../ChargedButton";
|
||||
import { usePermissions } from "@/hooks/usePermission";
|
||||
import styles from "@/css/Intro.module.css";
|
||||
import { ChangeEvent, InputEvent, MouseEvent, MouseEventHandler, PointerEvent, useRef, useState } from "react";
|
||||
import { ChangeEvent, InputEvent, MouseEvent, MouseEventHandler, PointerEvent, useMemo, useRef, useState } from "react";
|
||||
import Image from "next/image";
|
||||
import PermissionCheck from "../PermissionCheck";
|
||||
import { PermissionStateResult } from "@/utils/permissions";
|
||||
@@ -12,23 +12,37 @@ import OldButton from "../OldButton";
|
||||
import OldTextInput from "../OldTextInput";
|
||||
import clsx from "clsx";
|
||||
import { MAX_PLAYERS, MIN_PLAYERS } from "@/utils/players";
|
||||
import { isDemoMode, setDemoMode } from "@/utils/demoMode";
|
||||
|
||||
export default function Intro() {
|
||||
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
const [ , setPoints ] = useLocalStorage(PREF.points, "0");
|
||||
const [ , setCompletedRiddles ] = useLocalStorage(PREF.completed_riddles, "");
|
||||
const [ , setPlayers ] = useLocalStorage(PREF.players, "");
|
||||
const [ , setWorthyWords ] = useLocalStorage(PREF.worthyWords, "");
|
||||
const [ , setWorthyWords ] = useLocalStorage(PREF.worthy_words, "");
|
||||
const [ rewatchScreen, setRewatchScreen ] = useState(false);
|
||||
const [ enterPlayerCount, setEnterPlayerCount ] = useState(false);
|
||||
const [ videoEnded, setVideoEnded ] = useState(false);
|
||||
const [ videoPaused, setVideoPaused ] = useState(false);
|
||||
const [ voiceOverState, setVoiceOverState ] = useLocalStorage(PREF.voiceover, "off");
|
||||
const [ boughtHintsStr, setBoughtHints ] = useLocalStorage(PREF.boughtHints, "");
|
||||
const [ voiceOverState, setVoiceOverState ] = useLocalStorage(PREF.voice_over, "off");
|
||||
const [ boughtHintsStr, setBoughtHints ] = useLocalStorage(PREF.bought_hints, "");
|
||||
const introVideoRef = useRef<HTMLVideoElement | null>(null);
|
||||
const [ granted, setGranted ] = useState(false);
|
||||
|
||||
const [ , setPlayerCount ] = useLocalStorage(PREF.playerCount, "");
|
||||
const [ demoModeStr, ] = useLocalStorage(PREF.demo_mode, "");
|
||||
const demoMode = useMemo(() => isDemoMode(demoModeStr), [demoModeStr]);
|
||||
|
||||
const goToTheMap = () => {
|
||||
setPoints("0");
|
||||
setCompletedRiddles("");
|
||||
setBoughtHints("");
|
||||
setPlayers("");
|
||||
setWorthyWords("");
|
||||
setVoiceOverState("on");
|
||||
setStep("2");
|
||||
};
|
||||
|
||||
const [ , setPlayerCount ] = useLocalStorage(PREF.player_count, "");
|
||||
const [ playerCountStr, setPlayerCountStr] = useState("");
|
||||
|
||||
const validPlayerCount = (number: number) => {
|
||||
@@ -137,6 +151,7 @@ export default function Intro() {
|
||||
>
|
||||
<source src="/res/intro/intro.mp4" type="video/mp4"/>
|
||||
</video>
|
||||
{ demoMode ? <ChargedButton onAction={() => { goToTheMap(); }}>DEMO SKIP</ChargedButton> : null }
|
||||
{ !videoEnded && videoPaused ?
|
||||
<div className={styles["pause-screen"]}>
|
||||
<Image src="/icons/pause.svg" alt="Pause Icon" width={48} height={48}/>
|
||||
@@ -154,13 +169,7 @@ export default function Intro() {
|
||||
}
|
||||
}} whiteText={true}>Video wiederholen?</ChargedButton>
|
||||
<ChargedButton holdDuration={500} onAction={() => {
|
||||
setPoints("0");
|
||||
setCompletedRiddles("");
|
||||
setBoughtHints("");
|
||||
setPlayers("");
|
||||
setWorthyWords("");
|
||||
setVoiceOverState("on");
|
||||
setStep("2");
|
||||
goToTheMap();
|
||||
}} whiteText={true}>Wir sind bereit!</ChargedButton>
|
||||
</div> : null }
|
||||
</div>
|
||||
|
||||
@@ -11,23 +11,27 @@ import clsx from "clsx";
|
||||
import { getPoints } from "@/utils/points";
|
||||
import VoiceOver from "../VoiceOver";
|
||||
import { VoiceOverMode } from "@/types/voiceOverMode";
|
||||
import { isDemoMode } from "@/utils/demoMode";
|
||||
|
||||
export default function Outro() {
|
||||
const [ resultPage, setResultPage ] = useState(0);
|
||||
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
const [ pointsStr, setPoints ] = useLocalStorage(PREF.points, "0");
|
||||
const [ playersStr, setPlayers ] = useLocalStorage(PREF.players, "");
|
||||
const [ worthyWordsStr, setWorthyWords ] = useLocalStorage(PREF.worthyWords, "");
|
||||
const [ worthyWordsStr, setWorthyWords ] = useLocalStorage(PREF.worthy_words, "");
|
||||
const [ rewatchScreen, setRewatchScreen ] = useState(false);
|
||||
const [ videoEnded, setVideoEnded ] = useState(false);
|
||||
const [ videoPaused, setVideoPaused ] = useState(false);
|
||||
const [ voiceOverState, setVoiceOverState ] = useLocalStorage(PREF.voiceover, "off");
|
||||
const [ boughtHintsStr, setBoughtHints ] = useLocalStorage(PREF.boughtHints, "");
|
||||
const [ voiceOverState, setVoiceOverState ] = useLocalStorage(PREF.voice_over, "off");
|
||||
const [ boughtHintsStr, setBoughtHints ] = useLocalStorage(PREF.bought_hints, "");
|
||||
const points = useMemo(() => {
|
||||
return getPoints();
|
||||
}, [pointsStr]);
|
||||
const outroVideoRef = useRef<HTMLVideoElement | null>(null);
|
||||
|
||||
const [ demoModeStr, ] = useLocalStorage(PREF.demo_mode, "");
|
||||
const demoMode = useMemo(() => isDemoMode(demoModeStr), [demoModeStr]);
|
||||
|
||||
const handleVideoClick = (e: PointerEvent<HTMLVideoElement>): boolean => {
|
||||
e.currentTarget.play();
|
||||
return true;
|
||||
@@ -57,6 +61,7 @@ export default function Outro() {
|
||||
>
|
||||
<source src="/res/outro/testoutro.webm" type="video/webm"/>
|
||||
</video>
|
||||
{ demoMode ? <ChargedButton onAction={() => { setResultPage(1); }}>DEMO SKIP</ChargedButton> : null }
|
||||
{ !videoEnded && videoPaused ?
|
||||
<div className={styles["pause-screen"]}>
|
||||
<Image src="/icons/pause.svg" alt="Pause Icon" width={48} height={48}/>
|
||||
@@ -130,6 +135,10 @@ export default function Outro() {
|
||||
<p>Ihr habt die Tour mit <b>{points}</b> Rufpunkten abgeschlossen.</p>
|
||||
</div>
|
||||
}
|
||||
{ demoMode ? <ChargedButton onAction={() => {
|
||||
localStorage.clear();
|
||||
setStep("0");
|
||||
}} style={{position: "absolute", scale: "0.75", top: "2%", left: "1%"}}>DEMO BEENDEN</ChargedButton> : null }
|
||||
</div>
|
||||
)
|
||||
];
|
||||
|
||||
@@ -16,11 +16,15 @@ import { MAX_POINTS, MIN_POINTS } from "@/utils/points";
|
||||
import { Riddle } from "@/types/riddle";
|
||||
import * as maplibregl from 'maplibre-gl';
|
||||
import { createStationName } from "@/utils/stringer";
|
||||
import { getRiddleData } from "@/utils/riddledata";
|
||||
import { fetchRiddleData, getRiddleData, setRiddleData } from "@/utils/riddledata";
|
||||
import { heartbeat } from "@/utils/sessionHandler";
|
||||
import { getCompletedRiddles } from "@/utils/completedRiddles";
|
||||
import { isDemoMode } from "@/utils/demoMode";
|
||||
|
||||
export default function Tour() {
|
||||
const [ demoModeStr, ] = useLocalStorage(PREF.demo_mode, "");
|
||||
const demoMode = useMemo(() => isDemoMode(demoModeStr), [demoModeStr]);
|
||||
|
||||
const [ showTooFar, setShowTooFar ] = useState(false);
|
||||
const [ completedRiddlesStr, ] = useLocalStorage(PREF.completed_riddles, "");
|
||||
const [ riddleDataStr, ] = useLocalStorage(PREF.riddle_data, "");
|
||||
@@ -28,10 +32,34 @@ export default function Tour() {
|
||||
return getRiddleData();
|
||||
}, [riddleDataStr]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchRiddleData().then((riddleData) => {
|
||||
if (riddleData === null) {
|
||||
alert("Could not update Riddle Data!");
|
||||
return;
|
||||
}
|
||||
setRiddleData(riddleData["riddles"]);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!riddleData) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (demoMode) {
|
||||
const markers = [];
|
||||
const riddles = riddleData.sort((a, b) => a.step - b.step)
|
||||
for (let i = 0; i < riddles.length; ++i) {
|
||||
markers.push({
|
||||
id: riddles[i].id,
|
||||
lng: riddles[i].longitude,
|
||||
lat: riddles[i].latitude
|
||||
});
|
||||
}
|
||||
setMarkers(markers);
|
||||
return;
|
||||
}
|
||||
|
||||
const completedRiddles = getCompletedRiddles();
|
||||
const nextStep = completedRiddles.length;
|
||||
@@ -46,7 +74,7 @@ export default function Tour() {
|
||||
});
|
||||
}
|
||||
setMarkers(markers);
|
||||
}, [riddleData, completedRiddlesStr]);
|
||||
}, [riddleData, completedRiddlesStr, demoMode]);
|
||||
|
||||
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
const [ activeRiddle, setActiveRiddle ] = useState<Riddle | null>(null);
|
||||
@@ -58,10 +86,10 @@ export default function Tour() {
|
||||
const [ markers, setMarkers ] = useState<PlaceMarker[]>([]);
|
||||
const { gpsStatus, cameraStatus } = usePermissions();
|
||||
const points = Number.parseInt(pointsStr);
|
||||
const [ worthyAnswersStr, ] = useLocalStorage(PREF.worthyWords, "");
|
||||
const [ boughtHintsStr, ] = useLocalStorage(PREF.boughtHints, "");
|
||||
const [ playerCountStr, ] = useLocalStorage(PREF.playerCount, "");
|
||||
const [ voiceOverStr, ] = useLocalStorage(PREF.voiceover, "");
|
||||
const [ worthyAnswersStr, ] = useLocalStorage(PREF.worthy_words, "");
|
||||
const [ boughtHintsStr, ] = useLocalStorage(PREF.bought_hints, "");
|
||||
const [ playerCountStr, ] = useLocalStorage(PREF.player_count, "");
|
||||
const [ voiceOverStr, ] = useLocalStorage(PREF.voice_over, "");
|
||||
|
||||
const permissionsGranted = gpsStatus === "granted" && cameraStatus === "granted";
|
||||
|
||||
@@ -78,10 +106,13 @@ export default function Tour() {
|
||||
const [ code, ] = useLocalStorage(PREF.code, "");
|
||||
|
||||
useEffect(() => {
|
||||
if (demoMode) return;
|
||||
|
||||
if (code.length === 0) {
|
||||
return;
|
||||
}
|
||||
const intervalId = setInterval(() => {
|
||||
|
||||
const doHeartbeat = () => {
|
||||
heartbeat({
|
||||
"player_count": playerCountStr,
|
||||
"players": players,
|
||||
@@ -91,7 +122,12 @@ export default function Tour() {
|
||||
"bought_hints": boughtHintsStr,
|
||||
"voice_over": voiceOverStr
|
||||
}, code);
|
||||
};
|
||||
|
||||
const intervalId = setInterval(() => {
|
||||
doHeartbeat();
|
||||
}, 50000);
|
||||
doHeartbeat();
|
||||
|
||||
return () => {
|
||||
clearInterval(intervalId);
|
||||
@@ -132,8 +168,11 @@ export default function Tour() {
|
||||
</div>
|
||||
<div className={styles["main-content"]}>
|
||||
<div className={styles["map"]}>
|
||||
<MapView markers={markers} onMarkerClick={(marker, position) => {
|
||||
console.log(marker, position);
|
||||
<MapView markers={markers} triggerGeolocation={!demoMode} onMarkerClick={(marker, position) => {
|
||||
if (demoMode) {
|
||||
setClickedMarker(marker.id);
|
||||
return;
|
||||
}
|
||||
if (!position) {
|
||||
return;
|
||||
}
|
||||
@@ -150,7 +189,7 @@ export default function Tour() {
|
||||
const distanceMeters = userLngLat.distanceTo(markerLngLat);
|
||||
const isNearby = distanceMeters <= r.requiredDistance;
|
||||
|
||||
if (isNearby) {
|
||||
if (isNearby || demoMode) {
|
||||
setClickedMarker(marker.id);
|
||||
} else {
|
||||
setShowTooFar(true);
|
||||
@@ -201,6 +240,15 @@ export default function Tour() {
|
||||
: null
|
||||
}
|
||||
</div>
|
||||
{ demoMode ? <ChargedButton style={{
|
||||
position: "absolute",
|
||||
bottom: "5%",
|
||||
left: "1%",
|
||||
zIndex: 4
|
||||
}} onAction={() => {
|
||||
localStorage.clear();
|
||||
setStep("0");
|
||||
}}>DEMO BEENDEN</ChargedButton> : null }
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -4,14 +4,16 @@ import { ChangeEvent, SyntheticEvent, useEffect, useRef, useState } from "react"
|
||||
import styles from "../../css/WelcomeScreen.module.css";
|
||||
import ChargedButton from "../ChargedButton";
|
||||
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
||||
import { PREF } from "@/utils/const";
|
||||
import { API_PREFIX, HTTP_SCHEME, PREF } from "@/utils/const";
|
||||
import StyledContainer from "../StyledContainer";
|
||||
import clsx from "clsx";
|
||||
import OldButton from "../OldButton";
|
||||
import OldTextInput from "../OldTextInput";
|
||||
import { checkCode } from "@/utils/codeChecker";
|
||||
import { setRiddleData } from "@/utils/riddledata";
|
||||
import { fetchRiddleData, setRiddleData } from "@/utils/riddledata";
|
||||
import { setSessionData } from "@/utils/sessionHandler";
|
||||
import { setDemoMode } from "@/utils/demoMode";
|
||||
import { Riddle } from "@/types/riddle";
|
||||
|
||||
const CODE_LENGTH = 9;
|
||||
const COOLDOWN_MS = 3000;
|
||||
@@ -27,12 +29,12 @@ export default function WelcomeScreen() {
|
||||
const [, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
|
||||
const [ , setPlayers ] = useLocalStorage(PREF.players, "");
|
||||
const [ , setPlayerCount ] = useLocalStorage(PREF.playerCount, "");
|
||||
const [ , setPlayerCount ] = useLocalStorage(PREF.player_count, "");
|
||||
const [ , setPoints ] = useLocalStorage(PREF.points, "");
|
||||
const [ , setCompletedRiddles ] = useLocalStorage(PREF.completed_riddles, "");
|
||||
const [ , setWorthyAnswers ] = useLocalStorage(PREF.worthyWords, "");
|
||||
const [ , setBoughtHints ] = useLocalStorage(PREF.boughtHints, "");
|
||||
const [ , setVoiceOver ] = useLocalStorage(PREF.voiceover, "");
|
||||
const [ , setWorthyAnswers ] = useLocalStorage(PREF.worthy_words, "");
|
||||
const [ , setBoughtHints ] = useLocalStorage(PREF.bought_hints, "");
|
||||
const [ , setVoiceOver ] = useLocalStorage(PREF.voice_over, "");
|
||||
|
||||
const checkCooldown = () => {
|
||||
if (cooldownRef.current === -1) return false;
|
||||
@@ -72,6 +74,20 @@ export default function WelcomeScreen() {
|
||||
setLastSubmitTs(cooldownRef.current);
|
||||
setCode(value);
|
||||
|
||||
if (value === "6MEGZDEI2") {
|
||||
const riddleData = await fetchRiddleData();
|
||||
|
||||
if (riddleData === null) {
|
||||
alert("Could not fetch RiddleData!");
|
||||
return;
|
||||
}
|
||||
|
||||
setRiddleData(riddleData["riddles"]);
|
||||
setDemoMode(true);
|
||||
setStep("1");
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await checkCode(value);
|
||||
|
||||
if (data === null || data["riddles"] === undefined || data["riddles"] === null || data["riddles"].length < 1) {
|
||||
@@ -80,6 +96,7 @@ export default function WelcomeScreen() {
|
||||
}
|
||||
|
||||
console.log(data);
|
||||
setDemoMode(false);
|
||||
setRiddleData(data["riddles"]);
|
||||
if (data["session"] !== undefined && data["session"] !== null) {
|
||||
const s = JSON.parse(data["session"]);
|
||||
|
||||
Reference in new issue
Block a user