More things for web
This commit is contained in:
1 parent
78b1058276
commit
a1ab487084
8 files changed
+87
-8
No files matched your search
+19
-6
@@ -1,16 +1,24 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { ReactElement, useEffect, useState } from "react";
|
||||
import Image from "next/image";
|
||||
import styles from "./page.module.css";
|
||||
import ChargedButton from "@/components/ChargedButton";
|
||||
import MapView from "@/components/MapView";
|
||||
import WelcomeScreen from "@/components/screens/WelcomeScreen";
|
||||
import Intro from "@/components/screens/Intro";
|
||||
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
||||
import { PREF } from "@/utils/const";
|
||||
import { Player } from "@/types/player";
|
||||
import { formatPlayerData, parsePlayerData } from "@/utils/dataparser";
|
||||
import { parse } from "path";
|
||||
import Tour from "@/components/screens/Tour";
|
||||
|
||||
export default function Main() {
|
||||
const [ step, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
const [ players, setPlayers ] = useLocalStorage(PREF.players, "");
|
||||
const [ tourCode, setTourCode ] = useLocalStorage(PREF.code, "");
|
||||
const step = Number.parseInt(stepStr) || 0;
|
||||
/*const [doTest, setDoTest] = useState(false);
|
||||
<ChargedButton
|
||||
onAction={() => {
|
||||
@@ -24,14 +32,19 @@ export default function Main() {
|
||||
{doTest && <MapView></MapView>}*/
|
||||
|
||||
console.log("STEP", step);
|
||||
/*useEffect(() => {
|
||||
setValue("1");
|
||||
}, []);*/
|
||||
console.log("PLAYERS", players, parsePlayerData(players));
|
||||
console.log("TourCode", tourCode);
|
||||
|
||||
const content = [
|
||||
(<WelcomeScreen key={0}/>),
|
||||
(<Intro key={1} />),
|
||||
(<Tour key={2} />)
|
||||
];
|
||||
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<main className={styles.main}>
|
||||
<WelcomeScreen />
|
||||
{content[step]}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { useLocalStorage } from "@/hooks/useLocalStorage"
|
||||
import { PREF } from "@/utils/const"
|
||||
|
||||
export default function Intro() {
|
||||
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
|
||||
return (
|
||||
<div className="screen-container">
|
||||
Intro or smth
|
||||
<br></br>
|
||||
<button onClick={() => {
|
||||
setStep("2");
|
||||
}}>Ok</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { useLocalStorage } from "@/hooks/useLocalStorage"
|
||||
import { PREF } from "@/utils/const"
|
||||
import { parsePlayerData } from "@/utils/dataparser";
|
||||
|
||||
export default function Tour() {
|
||||
const [ stepStr, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
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 step = Number.parseInt(stepStr) || 0;
|
||||
const points = Number.parseInt(pointsStr) || 0;
|
||||
const players = parsePlayerData(playersStr);
|
||||
|
||||
return (
|
||||
<div className="screen-container">
|
||||
<div>
|
||||
{"Points: " + points}
|
||||
{"Players: " + playersStr}
|
||||
</div>
|
||||
<div>
|
||||
Contains both
|
||||
<div>
|
||||
Map
|
||||
</div>
|
||||
<div>
|
||||
Riddle Overlay
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
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";
|
||||
|
||||
const CODE_LENGTH = 9;
|
||||
const COOLDOWN_MS = 3000;
|
||||
@@ -13,6 +15,8 @@ export default function WelcomeScreen() {
|
||||
const [isCooldown, setIsCooldown] = useState(false);
|
||||
const tourCodeRef = useRef("");
|
||||
const cooldownRef = useRef(-1);
|
||||
const [, setCode ] = useLocalStorage(PREF.code, "");
|
||||
const [, setStep ] = useLocalStorage(PREF.step, "0");
|
||||
|
||||
const checkCooldown = () => {
|
||||
if (cooldownRef.current === -1) return false;
|
||||
@@ -47,6 +51,8 @@ export default function WelcomeScreen() {
|
||||
setLastSubmitTs(cooldownRef.current);
|
||||
|
||||
console.log("submitted", value);
|
||||
setCode(value);
|
||||
setStep("1");
|
||||
};
|
||||
|
||||
const handleChange = (event: ChangeEvent<HTMLInputElement>): boolean => {
|
||||
|
||||
File renamed without changes.
Whitespace-only changes.
Whitespace-only changes.
+14
-2
@@ -1,9 +1,21 @@
|
||||
import { Player } from "@/types/player";
|
||||
|
||||
export function parsePlayerData(raw: string): Array<Player> {
|
||||
return [];
|
||||
const tokens: string[] = raw.match(/\{([^}]+)\}/g) || [];
|
||||
const players: Player[] = [];
|
||||
for (const token of tokens) {
|
||||
players.push(JSON.parse(token));
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
export function formatPlayerData(arr: Array<Player>): string {
|
||||
return "";
|
||||
let s = "";
|
||||
for (const player of arr) {
|
||||
if (s.length > 0) {
|
||||
s += ",";
|
||||
}
|
||||
s += JSON.stringify(player);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
Reference in new issue
Block a user