Initial commit
This commit is contained in:
parent
19cae8ae63
commit
830d733f1b
1 changed files with 165 additions and 165 deletions
|
|
@ -3,7 +3,7 @@ import { addRoute, type RouteHandlerReturn } from "@app/routing";
|
||||||
import tttPage from "./ttt.html?raw";
|
import tttPage from "./ttt.html?raw";
|
||||||
import {showError, showInfo, showSuccess, showWarn} from "@app/toast";
|
import {showError, showInfo, showSuccess, showWarn} from "@app/toast";
|
||||||
import {io} from "socket.io-client";
|
import {io} from "socket.io-client";
|
||||||
import type { GameUpdate, CSocket as Socket } from "./socket";
|
import type {CSocket as Socket, GameUpdate} from "./socket";
|
||||||
import {updateUser} from "@app/auth";
|
import {updateUser} from "@app/auth";
|
||||||
import client from "@app/api";
|
import client from "@app/api";
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ enum QueueState {
|
||||||
InQueue = "In Queue",
|
InQueue = "In Queue",
|
||||||
InGame = "In Game",
|
InGame = "In Game",
|
||||||
Idle = "Join Queue",
|
Idle = "Join Queue",
|
||||||
};
|
}
|
||||||
|
|
||||||
document.addEventListener("ft:pageChange", () => {
|
document.addEventListener("ft:pageChange", () => {
|
||||||
if (window.__state.tttSock !== undefined) window.__state.tttSock.close();
|
if (window.__state.tttSock !== undefined) window.__state.tttSock.close();
|
||||||
|
|
@ -109,8 +109,7 @@ async function handleTTT(): Promise<RouteHandlerReturn> {
|
||||||
userOString.classList.remove('text-gray-800');
|
userOString.classList.remove('text-gray-800');
|
||||||
userXString.classList.remove('text-red-800');
|
userXString.classList.remove('text-red-800');
|
||||||
userXString.classList.add('text-gray-800');
|
userXString.classList.add('text-gray-800');
|
||||||
}
|
} else if (user.id === curGameX.id) {
|
||||||
else if (user.id === curGameX.id) {
|
|
||||||
userXString.classList.add('text-red-800');
|
userXString.classList.add('text-red-800');
|
||||||
userXString.classList.remove('text-gray-800');
|
userXString.classList.remove('text-gray-800');
|
||||||
userOString.classList.remove('text-red-800');
|
userOString.classList.remove('text-red-800');
|
||||||
|
|
@ -129,6 +128,7 @@ async function handleTTT(): Promise<RouteHandlerReturn> {
|
||||||
};
|
};
|
||||||
|
|
||||||
const makeEnd = (type: 'win' | 'conceded' | 'draw', player: 'X' | 'O') => {
|
const makeEnd = (type: 'win' | 'conceded' | 'draw', player: 'X' | 'O') => {
|
||||||
|
// TODO: Enhance the draw notification
|
||||||
if (type === 'draw') {
|
if (type === 'draw') {
|
||||||
showWarn('It\'s a draw !')
|
showWarn('It\'s a draw !')
|
||||||
}
|
}
|
||||||
|
|
@ -145,6 +145,7 @@ async function handleTTT(): Promise<RouteHandlerReturn> {
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// TODO: Enhance the win/loss notification
|
||||||
if (youWin)
|
if (youWin)
|
||||||
showSuccess('You won the game !');
|
showSuccess('You won the game !');
|
||||||
else
|
else
|
||||||
|
|
@ -165,8 +166,7 @@ async function handleTTT(): Promise<RouteHandlerReturn> {
|
||||||
|
|
||||||
curGame = {...u, lastState: curGame.lastState};
|
curGame = {...u, lastState: curGame.lastState};
|
||||||
|
|
||||||
if (curGame.currentPlayer === 'X')
|
if (curGame.currentPlayer === 'X') {
|
||||||
{
|
|
||||||
currentPlayerIndicator.innerText = "<";
|
currentPlayerIndicator.innerText = "<";
|
||||||
} else if (curGame.currentPlayer === 'O') {
|
} else if (curGame.currentPlayer === 'O') {
|
||||||
currentPlayerIndicator.innerText = ">";
|
currentPlayerIndicator.innerText = ">";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue