diff --git a/common/src/types/PlayerData.ts b/common/src/types/PlayerData.ts new file mode 100644 index 0000000..ba1d673 --- /dev/null +++ b/common/src/types/PlayerData.ts @@ -0,0 +1,20 @@ +import { IColour } from "./Colour"; +import { ISpaceship } from "./Spaceship"; + +/** + * The data structure that represents a Player in the game + */ +export interface PlayerData { + + /** The name the player chose while joining the lobby */ + name: string; + + /** + * The colour that the player's spaceship will be in the game. This must be + * unique among all players, this uniqueness is enforced by the server. + */ + colour: IColour; + + /** The spaceship icon that the player will appear as in-game. */ + ship: ISpaceship; +} \ No newline at end of file diff --git a/common/src/types/events/game_create.ts b/common/src/types/events/game_create.ts new file mode 100644 index 0000000..29652ad --- /dev/null +++ b/common/src/types/events/game_create.ts @@ -0,0 +1,26 @@ +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 { + username: string; +} + +/** The data that is given to the client when they attempt to join a lobby. */ +export interface IGameCreateResponse extends ServerResponse { + + /** + * The ID of the lobby, this is used so that other players may join the + * game lobby. + */ + game_id?: string; + + /** + * The data for all of the players currently in the lobby. When this event + * is sent out, it will only contain the player who created the lobby since + * no other players have had a chance to connect to the lobby yet. + */ + players?: PlayerData[]; +} \ No newline at end of file diff --git a/docs/events.md b/docs/events.md index 70eb191..f9653e7 100644 --- a/docs/events.md +++ b/docs/events.md @@ -26,4 +26,17 @@ Request Payload: N/A Response Payload: `IServerInfoResponse` ---- \ No newline at end of file +--- + +## `game.create` +Creates a new game lobby for players to be able to join. + +### Supported Event Types +| Request | Response | Broadcasted +| ------- | -------- | ----------- +| Yes | Yes | No + +### Payload Types: +Request Payload: `IGameCreateRequest` + +Response Payload: `IGameCreateResponse` \ No newline at end of file