diff --git a/README.md b/README.md new file mode 100644 index 0000000..11d0a2f --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Pool Tracker +Simple web app the keeps track of who's turn it is in pool. + +Add the players with the homepage, and view who's turn it is on the `/live` page \ No newline at end of file diff --git a/backend/server.py b/backend/server.py index 387ebcd..4258bb2 100644 --- a/backend/server.py +++ b/backend/server.py @@ -2,7 +2,7 @@ import eventlet eventlet.monkey_patch() -from flask import Flask, jsonify +from flask import Flask, jsonify, request from flask_cors import CORS from flask_socketio import SocketIO @@ -12,11 +12,40 @@ socketio = SocketIO(app, cors_allowed_origins="*") game_state = { - "gameActive": True, - "players": ["Alice", "Bob", "Charlie"], + "gameActive": False, + "players": [], "playerTurn": 0 } +@app.route("/add", methods=["POST"]) +def add_player(): + data = request.get_json() + if not data: + return jsonify({"error": "No JSON body received"}), 400 + + name = data.get("name") + group = data.get("group") + + if not name or group not in ["stripes", "solids"]: + return jsonify({"error": "Invalid data"}), 400 + + game_state["players"].append({"name": name, "group": group}) + + # emit socket update + socketio.emit("player_update", {"players": game_state["players"]}) + + return jsonify({"message": f"Player {name} added to {group} group"}) + +@app.route("/reset", methods=["GET"]) +def reset(): + game_state = { + "gameActive": False, + "players": [""], + "playerTurn": 0 + } + return jsonify(game_state) + + @app.route("/status", methods=["GET"]) def status(): return jsonify(game_state) diff --git a/frontend/app/live/page.tsx b/frontend/app/live/page.tsx index cf77c69..67cc78e 100644 --- a/frontend/app/live/page.tsx +++ b/frontend/app/live/page.tsx @@ -36,7 +36,7 @@ export default function HomePage() {
{currentPlayer ? (

- 🎯 Current Player: {currentPlayer} + 🎯 Current Player: {currentPlayer.name} ({currentPlayer.group})

) : (

Waiting for turn to start…

diff --git a/frontend/app/page.tsx b/frontend/app/page.tsx index 6cb71a8..c331ee7 100644 --- a/frontend/app/page.tsx +++ b/frontend/app/page.tsx @@ -32,6 +32,14 @@ const addPlayer = async () => { } }; const [selectedGroup, setSelectedGroup] = useState<"stripes" | "solids">("stripes"); + + const advanceTurn = async () => { + await fetch('http://localhost:8080/next'); // triggers backend to emit event + }; + + const resetGame = async () => { + await fetch('http://localhost:8080/reset'); // triggers backend to emit event + }; return (
@@ -85,14 +93,14 @@ const addPlayer = async () => { /> Start Game - - Reset Game - + Reset Game +