59 lines
967 B
TypeScript
59 lines
967 B
TypeScript
import { DataConnection } from "peerjs";
|
|
|
|
export interface NetworkPlayer {
|
|
name: string;
|
|
conn: DataConnection;
|
|
}
|
|
|
|
export interface Room {
|
|
info: RoomInfo;
|
|
players: Record<string, NetworkPlayer>;
|
|
}
|
|
|
|
export interface RoomInfo {
|
|
max_players: number;
|
|
password: string;
|
|
game: GameInfo;
|
|
}
|
|
|
|
type GameInfo = MatchInfo | DraftInfo;
|
|
|
|
interface MatchInfo {
|
|
game_type: "match";
|
|
player1: string;
|
|
player2: string;
|
|
}
|
|
|
|
interface SetDraftInfo {
|
|
draft_type: "set";
|
|
set: string;
|
|
}
|
|
|
|
interface BlockDraftInfo {
|
|
draft_type: "block";
|
|
block: string;
|
|
}
|
|
|
|
interface CubeDraftInfo {
|
|
draft_type: "cube";
|
|
url: string;
|
|
seeded: boolean;
|
|
}
|
|
|
|
type DraftInfo = {
|
|
game_type: "draft";
|
|
} & (SetDraftInfo | BlockDraftInfo | CubeDraftInfo);
|
|
|
|
// Message schemas
|
|
|
|
export type NetworkMessage = PasswordRequest | PasswordResponse;
|
|
|
|
export interface PasswordRequest {
|
|
kind: "password-req";
|
|
}
|
|
|
|
export interface PasswordResponse {
|
|
kind: "password-resp";
|
|
password: string;
|
|
}
|