Add docs and types for the game join event
This commit is contained in:
parent
81d9f0a5bf
commit
c93b903094
3 changed files with 60 additions and 1 deletions
20
common/src/types/PlayerData.ts
Normal file
20
common/src/types/PlayerData.ts
Normal file
|
|
@ -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;
|
||||||
|
}
|
||||||
26
common/src/types/events/game_create.ts
Normal file
26
common/src/types/events/game_create.ts
Normal file
|
|
@ -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[];
|
||||||
|
}
|
||||||
|
|
@ -26,4 +26,17 @@ Request Payload: N/A
|
||||||
|
|
||||||
Response Payload: `IServerInfoResponse`
|
Response Payload: `IServerInfoResponse`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## `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`
|
||||||
Loading…
Add table
Add a link
Reference in a new issue