feat(tournament): allow the creation of a tournament
A tournament can be created (by the "owner") Any other players can join said tournament. The information is currently not displayed in the frontend, but does exists and is passed to the frontend using a socket.io event
This commit is contained in:
parent
272c6f319c
commit
2195207297
9 changed files with 558 additions and 170 deletions
|
|
@ -1,56 +1,80 @@
|
|||
import { Socket } from 'socket.io-client';
|
||||
|
||||
export type UpdateInfo = {
|
||||
inQueue: number,
|
||||
totalUser: number,
|
||||
totalGames : number
|
||||
}
|
||||
inQueue: number;
|
||||
totalUser: number;
|
||||
totalGames: number;
|
||||
};
|
||||
|
||||
export type PaddleData = {
|
||||
x: number,
|
||||
y: number,
|
||||
x: number;
|
||||
y: number;
|
||||
|
||||
width: number,
|
||||
height: number,
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
export type GameUpdate = {
|
||||
gameId: string;
|
||||
|
||||
left: { id: string, paddle: PaddleData, score: number };
|
||||
right: { id: string, paddle: PaddleData, score: number };
|
||||
left: { id: string; paddle: PaddleData; score: number };
|
||||
right: { id: string; paddle: PaddleData; score: number };
|
||||
|
||||
ball: { x: number, y: number, size: number };
|
||||
local: boolean,
|
||||
}
|
||||
ball: { x: number; y: number; size: number };
|
||||
local: boolean;
|
||||
};
|
||||
|
||||
export type GameMove = {
|
||||
move: 'up' | 'down' | null,
|
||||
move: 'up' | 'down' | null;
|
||||
// only used in local games
|
||||
moveRight: 'up' | 'down' | null,
|
||||
}
|
||||
moveRight: 'up' | 'down' | null;
|
||||
};
|
||||
|
||||
export type TourInfo = {
|
||||
ownerId: string;
|
||||
state: 'prestart' | 'playing' | 'ended';
|
||||
players: { id: string; name: string; score: number }[];
|
||||
currentGameInfo: GameUpdate | null;
|
||||
};
|
||||
|
||||
// TODO: add new evt such as "local play", "ready-up" see: ./pong.ts
|
||||
export interface ClientToServer {
|
||||
enqueue: () => void;
|
||||
dequeue: () => void;
|
||||
readyUp: () => void;
|
||||
readyDown:() => void;
|
||||
readyDown: () => void;
|
||||
debugInfo: () => void;
|
||||
gameMove: (up: GameMove) => void;
|
||||
connectedToGame: (gameId: string) => void;
|
||||
localGame: () => void,
|
||||
};
|
||||
localGame: () => void;
|
||||
|
||||
// TOURNAMENT
|
||||
|
||||
tourRegister: () => void;
|
||||
tourUnregister: () => void;
|
||||
|
||||
tourCreate: () => void;
|
||||
}
|
||||
|
||||
export interface ServerToClient {
|
||||
forceDisconnect: (reason: string) => void;
|
||||
queueEvent: (msg: 'registered' | 'unregistered') => void;
|
||||
rdyEnd:() => void,
|
||||
updateInformation: (info: UpdateInfo) => void,
|
||||
newGame: (initState: GameUpdate) => void, // <- consider this the gameProc eg not start of game but wait for client to "ready up"
|
||||
gameUpdate: (state: GameUpdate) => void,
|
||||
rdyEnd: () => void;
|
||||
updateInformation: (info: UpdateInfo) => void;
|
||||
newGame: (initState: GameUpdate) => void;
|
||||
gameUpdate: (state: GameUpdate) => void;
|
||||
gameEnd: (winner: 'left' | 'right') => void;
|
||||
};
|
||||
|
||||
// TOURNAMENT
|
||||
tournamentRegister: (res: {
|
||||
kind: 'success' | 'failure';
|
||||
msg?: string;
|
||||
}) => void;
|
||||
tournamentCreateMsg: (res: {
|
||||
kind: 'success' | 'failure';
|
||||
msg?: string;
|
||||
}) => void;
|
||||
tournamentInfo: (info: TourInfo | null) => void;
|
||||
}
|
||||
|
||||
export type SSocket = Socket<ClientToServer, ServerToClient>;
|
||||
export type CSocket = Socket<ServerToClient, ClientToServer>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue