From 94d263993d6ecaacdea0b17756234502919da960 Mon Sep 17 00:00:00 2001 From: bgoulard Date: Mon, 5 Jan 2026 17:11:23 +0100 Subject: [PATCH] wip --- frontend/src/pages/pong/pong.html | 2 ++ frontend/src/pages/pong/pong.ts | 30 +++++++++++++++++++++++++++--- frontend/src/pages/pong/socket.ts | 1 + src/pong/src/socket.ts | 1 + src/pong/src/state.ts | 1 + 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/pong/pong.html b/frontend/src/pages/pong/pong.html index e239863..163e144 100644 --- a/frontend/src/pages/pong/pong.html +++ b/frontend/src/pages/pong/pong.html @@ -1,6 +1,8 @@
+ + ?👤 ?⏳ ?▮•▮

Pong Box diff --git a/frontend/src/pages/pong/pong.ts b/frontend/src/pages/pong/pong.ts index 7646c60..c06c940 100644 --- a/frontend/src/pages/pong/pong.ts +++ b/frontend/src/pages/pong/pong.ts @@ -20,6 +20,7 @@ enum QueueState { InQueu = "In Queue", InGame = "In Game", Iddle = "Queue Up", + In_local = "In Local", }; document.addEventListener("ft:pageChange", (newUrl) => { @@ -54,7 +55,9 @@ function pongClient(_url: string, _args: RouteHandlerParams): RouteHandlerReturn const playerL = document.querySelector('#player-left'); const playerR = document.querySelector('#player-right'); const queueBtn = document.querySelector("#QueueBtn"); + const LocalGameBtn = document.querySelector("#LocalBtn"); const gameBoard = document.querySelector("#pongbox"); + const queue_infos = document.querySelector("#queue-info"); let socket = getSocket(); @@ -62,7 +65,7 @@ function pongClient(_url: string, _args: RouteHandlerParams): RouteHandlerReturn navigateTo("/app"); return ; } - if (!batLeft || !batRight || !ball || !score || !queueBtn || !playerL || !playerR || !gameBoard) // sanity check + if (!batLeft || !batRight || !ball || !score || !queueBtn || !playerL || !playerR || !gameBoard || !queue_infos || !LocalGameBtn) // sanity check return showError('fatal error'); // --- @@ -151,6 +154,18 @@ function pongClient(_url: string, _args: RouteHandlerParams): RouteHandlerReturn queueBtn.innerText = QueueState.InQueu; socket.emit('enqueue'); }); + + LocalGameBtn.addEventListener("click", () => { + if (queueBtn.innerText !== QueueState.Iddle || currentGame !== null) { + showError("cant launch a local game while in queue/in game"); + return ; + } + socket.emit("localGame"); + queueBtn.innerText = QueueState.In_local; + LocalGameBtn.innerText = "playing"; + }); + + async function get_opponent(opponent_id : string) { let t = await client.getUser({user:opponent_id}); @@ -194,10 +209,13 @@ function pongClient(_url: string, _args: RouteHandlerParams): RouteHandlerReturn new_div.innerText = 'you ' + end_txt; new_div.className = "pong-end-screen"; gameBoard.appendChild(new_div); - setTimeout(() => { new_div.remove(); }, 3 * 1000); + + if (currentGame.local) { + LocalGameBtn.innerText = "Local Game" + } } render(DEFAULT_POSITIONS); batLeft.style.backgroundColor = DEFAULT_COLOR; @@ -212,11 +230,17 @@ function pongClient(_url: string, _args: RouteHandlerParams): RouteHandlerReturn // --- // queue evt end // --- + + queueBtn.innerText = QueueState.Iddle; + currentGame = null; render(DEFAULT_POSITIONS); batLeft.style.backgroundColor = DEFAULT_COLOR; batRight.style.backgroundColor = DEFAULT_COLOR; - socket.on('updateInformation', (e) => showInfo(`UpdateInformation: t=${e.totalUser};q=${e.inQueue}`)); + socket.on('updateInformation', (e) => { + showInfo(`UpdateInformation: t=${e.totalUser};q=${e.inQueue};g=${e.totalGames}`); + queue_infos.innerText = `${e.totalUser}👤 ${e.inQueue}⏳ ${e.totalGames}▮•▮`; + }); socket.on('queueEvent', (e) => showInfo(`QueueEvent: ${e}`)); showInfo("butter"); showInfo("butter-toast"); diff --git a/frontend/src/pages/pong/socket.ts b/frontend/src/pages/pong/socket.ts index 8eb14ec..62291c9 100644 --- a/frontend/src/pages/pong/socket.ts +++ b/frontend/src/pages/pong/socket.ts @@ -3,6 +3,7 @@ import { Socket } from 'socket.io-client'; export type UpdateInfo = { inQueue: number, totalUser: number, + totalGames : number } export type PaddleData = { diff --git a/src/pong/src/socket.ts b/src/pong/src/socket.ts index 417c58c..4af97e8 100644 --- a/src/pong/src/socket.ts +++ b/src/pong/src/socket.ts @@ -3,6 +3,7 @@ import { Socket } from 'socket.io'; export type UpdateInfo = { inQueue: number, totalUser: number, + totalGames : number } export type PaddleData = { diff --git a/src/pong/src/state.ts b/src/pong/src/state.ts index 2fa8c0f..80381fb 100644 --- a/src/pong/src/state.ts +++ b/src/pong/src/state.ts @@ -159,6 +159,7 @@ class StateI { socket.emit('updateInformation', { inQueue: this.queue.size, totalUser: this.users.size, + totalGames: this.games.size, }); }