From c5449f115343c74ba6404176ddca7a385b0049ba Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Thu, 6 Jan 2022 16:25:38 -0700 Subject: [PATCH] Update the type structure, and rename the "game.*" events to "lobby.*" --- common/src/index.ts | 23 +++++++++++-------- .../{game_create.ts => lobby/create.ts} | 12 ++++++---- .../events/{game_join.ts => lobby/join.ts} | 8 +++---- common/src/types/events/players/update.ts | 10 ++++++++ 4 files changed, 35 insertions(+), 18 deletions(-) rename common/src/types/events/{game_create.ts => lobby/create.ts} (62%) rename common/src/types/events/{game_join.ts => lobby/join.ts} (50%) create mode 100644 common/src/types/events/players/update.ts diff --git a/common/src/index.ts b/common/src/index.ts index 24fc633..68206e3 100644 --- a/common/src/index.ts +++ b/common/src/index.ts @@ -1,14 +1,19 @@ // Enums -export { Status } from "./enums/Status"; + export { Status } from "./enums/Status"; // Data Structures -export * from "./types/Colour"; -export * from "./types/Spaceship"; -export * from "./types/PlayerData"; + export * from "./types/Colour"; + export * from "./types/Spaceship"; + export * from "./types/PlayerData"; // Server-Client Communications -export * from "./types/ServerResponse"; -export * from "./types/events/SaveShip"; -export * from "./types/events/game_join"; -export * from "./types/events/server_info"; -export * from "./types/events/game_create"; \ No newline at end of file + export * from "./types/ServerResponse"; + export * from "./types/events/SaveShip"; + export * from "./types/events/server_info"; + + // Lobby events + export * from "./types/events/lobby/join"; + export * from "./types/events/lobby/create"; + + // Player events + export * from "./types/events/players/update"; \ No newline at end of file diff --git a/common/src/types/events/game_create.ts b/common/src/types/events/lobby/create.ts similarity index 62% rename from common/src/types/events/game_create.ts rename to common/src/types/events/lobby/create.ts index 29652ad..42ebe6f 100644 --- a/common/src/types/events/game_create.ts +++ b/common/src/types/events/lobby/create.ts @@ -1,15 +1,17 @@ -import { ServerResponse } from "../ServerResponse"; -import { PlayerData } from "../PlayerData"; +import { ServerResponse } from "../../ServerResponse"; +import { PlayerData } from "../../PlayerData"; /** * The data that must be supplied to the server in order to create a game. */ -export interface IGameCreateRequest { +export interface LobbyCreateRequest { username: string; } -/** The data that is given to the client when they attempt to join a lobby. */ -export interface IGameCreateResponse extends ServerResponse { +/** + * The data that is given to the client when they attempt to create a lobby. + */ +export interface LobbyCreateResponse extends ServerResponse { /** * The ID of the lobby, this is used so that other players may join the diff --git a/common/src/types/events/game_join.ts b/common/src/types/events/lobby/join.ts similarity index 50% rename from common/src/types/events/game_join.ts rename to common/src/types/events/lobby/join.ts index 6a5039c..6383fd7 100644 --- a/common/src/types/events/game_join.ts +++ b/common/src/types/events/lobby/join.ts @@ -1,13 +1,13 @@ -import { ServerResponse } from "../ServerResponse"; -import { PlayerData } from "../PlayerData"; +import { ServerResponse } from "../../ServerResponse"; +import { PlayerData } from "../../PlayerData"; /** The data required by the server to be able to join a game */ -export interface IGameJoinRequest { +export interface LobbyJoinRequest { id: string; name: string; } /** The response that the player receives upon succesfully joining a game. */ -export interface IGameJoinResponse extends ServerResponse { +export interface LobbyJoinResponse extends ServerResponse { players?: PlayerData[]; } \ No newline at end of file diff --git a/common/src/types/events/players/update.ts b/common/src/types/events/players/update.ts new file mode 100644 index 0000000..dff5eab --- /dev/null +++ b/common/src/types/events/players/update.ts @@ -0,0 +1,10 @@ +import { ServerResponse } from "../../ServerResponse"; +import { PlayerData } from "../../PlayerData"; + +/** + * The data that the server is requesting connected clients use while updating + * their lobby information. + */ +export interface PlayerUpdateResponse extends ServerResponse { + players?: PlayerData[]; +} \ No newline at end of file