1
0
mirror of https://github.com/thib8956/tic-tac-toe-ws.git synced 2025-02-22 08:48:15 +00:00

fix: spectator message on game reset

This commit is contained in:
Thibaud Gasser 2025-01-30 09:50:55 +01:00
parent f35a75b593
commit c24a5b4d85

View File

@ -28,7 +28,7 @@ interface Shape {
let grid: Cell[] = new Array(9); let grid: Cell[] = new Array(9);
let pendingEvts: Point[] = []; let pendingEvts: Point[] = [];
let spectate = false; // is this client in spectator mode? let isSpectator = false; // is this client in spectator mode?
let myId: number | null = null; let myId: number | null = null;
let mySymbol: "x" | "o" | null = null; let mySymbol: "x" | "o" | null = null;
let canvasMsg: string = "Offline..."; let canvasMsg: string = "Offline...";
@ -181,7 +181,7 @@ function init() {
resizeCanvas(ctx); // Init canvas resizeCanvas(ctx); // Init canvas
canvas.addEventListener("click", (evt) => { canvas.addEventListener("click", (evt) => {
if (spectate) { if (isSpectator) {
console.debug("ignoring click in spectator mode"); console.debug("ignoring click in spectator mode");
return; return;
} }
@ -206,7 +206,7 @@ function init() {
break; break;
} }
case "spectate": { case "spectate": {
spectate = true; isSpectator = true;
canvasMsg = "connected as spectator"; canvasMsg = "connected as spectator";
// Initialize grid state // Initialize grid state
for (const [index, sym] of (msg.data as Spectate).grid.entries()) { for (const [index, sym] of (msg.data as Spectate).grid.entries()) {
@ -243,7 +243,9 @@ function init() {
break; break;
} }
case "reset": { case "reset": {
if (!isSpectator) {
canvasMsg = `Game reset... Id #${myId}, playing as ${mySymbol}`; canvasMsg = `Game reset... Id #${myId}, playing as ${mySymbol}`;
}
grid = new Array(9); grid = new Array(9);
pendingEvts = []; pendingEvts = [];
resizeCanvas(ctx); resizeCanvas(ctx);