add clock screensaver, basic team ordering, connection error message
This commit is contained in:
parent
8a14be321e
commit
66186eb016
10
README.md
10
README.md
@ -7,8 +7,16 @@ Syncs in realtime between devices with sockets
|
|||||||
|
|
||||||
Add the players with the homepage, and view who's turn it is on the `/live` page
|
Add the players with the homepage, and view who's turn it is on the `/live` page
|
||||||
|
|
||||||
|

|
||||||
|
Idle Screensaver ()
|
||||||
|

|
||||||
|
No Connection Message
|
||||||
|
|
||||||
|

|
||||||
|
Root Menu
|
||||||
|

|
||||||
|
Live page
|
||||||
|
|
||||||
Tools used:
|
Tools used:
|
||||||
SVGs generated from https://www.svgrepo.com
|
SVGs generated from https://www.svgrepo.com
|
||||||
https://www.freetool.dev/emoji-picker/
|
https://www.freetool.dev/emoji-picker/http://localhost:3000/
|
@ -49,10 +49,27 @@ def reset():
|
|||||||
def status():
|
def status():
|
||||||
return jsonify(game_state)
|
return jsonify(game_state)
|
||||||
|
|
||||||
|
def orderplayers():
|
||||||
|
stripes = []
|
||||||
|
solids = []
|
||||||
|
for player in game_state["players"]:
|
||||||
|
if player["group"] == "stripes":
|
||||||
|
stripes.append(player)
|
||||||
|
else:
|
||||||
|
solids.append(player)
|
||||||
|
print(stripes)
|
||||||
|
print(solids)
|
||||||
|
|
||||||
|
combined = [player for pair in zip(stripes, solids) for player in pair]
|
||||||
|
print(combined)
|
||||||
|
|
||||||
|
game_state["players"] = combined
|
||||||
|
|
||||||
@app.route("/start", methods=["GET"])
|
@app.route("/start", methods=["GET"])
|
||||||
def start_game():
|
def start_game():
|
||||||
players = game_state["players"]
|
players = game_state["players"]
|
||||||
game_state["gameActive"] = True
|
game_state["gameActive"] = True
|
||||||
|
orderplayers()
|
||||||
current_player = players[game_state["playerTurn"]]
|
current_player = players[game_state["playerTurn"]]
|
||||||
socketio.emit("player_update", {"nextPlayer": current_player})
|
socketio.emit("player_update", {"nextPlayer": current_player})
|
||||||
return jsonify(game_state)
|
return jsonify(game_state)
|
||||||
|
@ -14,7 +14,7 @@ export default function HomePage() {
|
|||||||
const backendUrl = `${baseUrl}:${process.env.NEXT_PUBLIC_API_BASE}`;
|
const backendUrl = `${baseUrl}:${process.env.NEXT_PUBLIC_API_BASE}`;
|
||||||
const socket = io(`${backendUrl}`);
|
const socket = io(`${backendUrl}`);
|
||||||
|
|
||||||
const [time, setTime] = useState<Date>(new Date());
|
const [time, setTime] = useState(new Date());
|
||||||
|
|
||||||
const [currentPlayer, setCurrentPlayer] = useState<string | null>(null);
|
const [currentPlayer, setCurrentPlayer] = useState<string | null>(null);
|
||||||
|
|
||||||
@ -37,6 +37,30 @@ export default function HomePage() {
|
|||||||
socket.off('player_update');
|
socket.off('player_update');
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
// Idle clock stuff
|
||||||
|
useEffect(() => {
|
||||||
|
const interval = setInterval(() => setTime(new Date()), 1000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const timeString = time.toLocaleTimeString('en-US', {
|
||||||
|
hour: 'numeric',
|
||||||
|
minute: '2-digit',
|
||||||
|
});
|
||||||
|
|
||||||
|
const dateString = time.toLocaleDateString('en-US', {
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric',
|
||||||
|
year: 'numeric',
|
||||||
|
});
|
||||||
|
|
||||||
|
const day = time.getDate();
|
||||||
|
const suffix =
|
||||||
|
day % 10 === 1 && day !== 11 ? 'st' :
|
||||||
|
day % 10 === 2 && day !== 12 ? 'nd' :
|
||||||
|
day % 10 === 3 && day !== 13 ? 'rd' : 'th';
|
||||||
|
|
||||||
|
const formattedDate = `${time.toLocaleString('en-US', { month: 'long' })} ${day}${suffix}, ${time.getFullYear()}`;
|
||||||
|
|
||||||
const advanceTurn = async () => {
|
const advanceTurn = async () => {
|
||||||
await fetch(`${baseUrl}/next`); // triggers backend to emit event
|
await fetch(`${baseUrl}/next`); // triggers backend to emit event
|
||||||
@ -77,9 +101,14 @@ export default function HomePage() {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<main className="p-6">
|
<main>
|
||||||
{time.getTime()}
|
<div className="h-screen flex flex-col items-center justify-center text-center text-4xl font-semibold">
|
||||||
This will show the time
|
<div>{timeString}</div>
|
||||||
|
<div className="text-2xl mt-2">{formattedDate}</div>
|
||||||
|
</div>
|
||||||
|
<div className="w-full py-4 text-center text-gray-500">
|
||||||
|
<div className="text-xl mt-2">Go to {baseUrl} to start a game!</div>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
import { connect } from "http2";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import io from 'socket.io-client';
|
import io from 'socket.io-client';
|
||||||
@ -7,6 +8,7 @@ import io from 'socket.io-client';
|
|||||||
export default function Home() {
|
export default function Home() {
|
||||||
const nameInputRef = useRef<HTMLInputElement>(null);
|
const nameInputRef = useRef<HTMLInputElement>(null);
|
||||||
const currentPlayers = useState<string | null>(null);
|
const currentPlayers = useState<string | null>(null);
|
||||||
|
const [apiConnected, setAPIStatus] = useState<boolean>(false);
|
||||||
const [gameStatus, setGameStatus] = useState<{ gameActive: boolean, players: any[] }>({
|
const [gameStatus, setGameStatus] = useState<{ gameActive: boolean, players: any[] }>({
|
||||||
gameActive: false,
|
gameActive: false,
|
||||||
players: [],
|
players: [],
|
||||||
@ -20,13 +22,16 @@ export default function Home() {
|
|||||||
const backendUrl = `${baseUrl}:${process.env.NEXT_PUBLIC_API_BASE}`;
|
const backendUrl = `${baseUrl}:${process.env.NEXT_PUBLIC_API_BASE}`;
|
||||||
const socket = io(`${backendUrl}`);
|
const socket = io(`${backendUrl}`);
|
||||||
|
|
||||||
|
|
||||||
const fetchStatus = async () => {
|
const fetchStatus = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${backendUrl}/status`);
|
const res = await fetch(`${backendUrl}/status`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
setAPIStatus(true);
|
||||||
setGameStatus(data);
|
setGameStatus(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to fetch status", err);
|
console.error("Failed to fetch status", err);
|
||||||
|
setAPIStatus(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -40,6 +45,7 @@ export default function Home() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
socket.on('connect', () => {
|
socket.on('connect', () => {
|
||||||
console.log('Connected to Socket.IO server');
|
console.log('Connected to Socket.IO server');
|
||||||
|
setAPIStatus(true);
|
||||||
fetchStatus();
|
fetchStatus();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -93,8 +99,9 @@ export default function Home() {
|
|||||||
await fetch(`${backendUrl}/reset`); // triggers backend to emit event
|
await fetch(`${backendUrl}/reset`); // triggers backend to emit event
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log(apiConnected);
|
||||||
|
if (apiConnected) {
|
||||||
return (
|
return (
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div className="border rounded p-4 max-w-md m-5">
|
<div className="border rounded p-4 max-w-md m-5">
|
||||||
<h2 className="text-xl font-semibold mb-3">🎯 Game Info</h2>
|
<h2 className="text-xl font-semibold mb-3">🎯 Game Info</h2>
|
||||||
@ -114,8 +121,6 @@ export default function Home() {
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
|
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
|
||||||
|
|
||||||
|
|
||||||
<main className="flex flex-col gap-[32px] row-start-2 items-center sm:items-start">
|
<main className="flex flex-col gap-[32px] row-start-2 items-center sm:items-start">
|
||||||
<div className="flex gap-8 mb-4">
|
<div className="flex gap-8 mb-4">
|
||||||
<label className="flex items-center gap-2 cursor-pointer">
|
<label className="flex items-center gap-2 cursor-pointer">
|
||||||
@ -200,3 +205,29 @@ export default function Home() {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
|
||||||
|
<main className="flex flex-col gap-[32px] row-start-2 items-center sm:items-start">
|
||||||
|
<p>Not Connected to API {apiConnected}</p>
|
||||||
|
<div className="flex gap-4 items-center flex-col sm:flex-row">
|
||||||
|
<button
|
||||||
|
className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] font-medium text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:w-auto"
|
||||||
|
onClick={startGame}
|
||||||
|
>
|
||||||
|
<Image
|
||||||
|
className="dark:invert"
|
||||||
|
src="/play-button.svg"
|
||||||
|
alt="Vercel logomark"
|
||||||
|
width={20}
|
||||||
|
height={20}
|
||||||
|
/>
|
||||||
|
Try Reconnecting
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
BIN
image-1.png
Normal file
BIN
image-1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
BIN
image-2.png
Normal file
BIN
image-2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 80 KiB |
BIN
image-3.png
Normal file
BIN
image-3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
Loading…
x
Reference in New Issue
Block a user