File size: 1,572 Bytes
a07d36d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import type { Integratable } from "pocket-physics";

export const ballsPositionsUpdatesPerSecond = 8;

export const ballRadius = 14;

export const squareCanvasSizeInPixels = 680;

export type Ball = Integratable & {
  id: number;
  radius: number;
  mass: number;
  value: number;
  label: string;
  color: string;
  lastTouchedTimestamp: number;
  lastTouchedBySocketId?: string;
  ownerSocketId?: string;
};

export type BallsPositions = [objectId: number, x: number, y: number][];

export type Scoreboard = [nick: string, score: number, tableId: number][];

export enum ServerToClientEventName {
  Message = "A",
  Objects = "B",
  Creation = "C",
  Deletion = "D",
  Scored = "E",
  Positions = "F",
  Scoreboard = "G",
}

export enum ClientToServerEventName {
  Message = "A",
  Click = "B",
}

export interface ServerToClientEvents {
  [ServerToClientEventName.Message]: (message: string) => void;
  [ServerToClientEventName.Objects]: (objects: Ball[]) => void;
  [ServerToClientEventName.Creation]: (object: Ball) => void;
  [ServerToClientEventName.Deletion]: (id: number) => void;
  [ServerToClientEventName.Scored]: (value: number, positionX: number, positionY: number) => void;
  [ServerToClientEventName.Positions]: (ballsPositions: BallsPositions) => void;
  [ServerToClientEventName.Scoreboard]: (overallScoreboard: Scoreboard, tableScoreboard: Scoreboard) => void;
}

export interface ClientToServerEvents {
  [ClientToServerEventName.Message]: (message: string) => void;
  [ClientToServerEventName.Click]: (positionX: number, positionY: number) => void;
}