From 4c957cce071e04fbb9ad73485cd3504d160a4992 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Tue, 28 Dec 2021 20:08:42 -0700 Subject: [PATCH] Put types and enums that both the server and web need into a common area --- common/enums/Status.ts | 7 +++++++ common/types/Colour.ts | 4 ++++ common/types/ServerResponse.ts | 8 ++++++++ common/types/events/SaveShip.ts | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 common/enums/Status.ts create mode 100644 common/types/Colour.ts create mode 100644 common/types/ServerResponse.ts create mode 100644 common/types/events/SaveShip.ts diff --git a/common/enums/Status.ts b/common/enums/Status.ts new file mode 100644 index 0000000..81df131 --- /dev/null +++ b/common/enums/Status.ts @@ -0,0 +1,7 @@ +export const Status = { + Success: 200, + UnknownError: 400, + OutOfDate: 401, + NotFound: 404, + Teapot: 418, +} \ No newline at end of file diff --git a/common/types/Colour.ts b/common/types/Colour.ts new file mode 100644 index 0000000..1820756 --- /dev/null +++ b/common/types/Colour.ts @@ -0,0 +1,4 @@ +interface Colour { + name: string; + hex: string; +} \ No newline at end of file diff --git a/common/types/ServerResponse.ts b/common/types/ServerResponse.ts new file mode 100644 index 0000000..235d2bd --- /dev/null +++ b/common/types/ServerResponse.ts @@ -0,0 +1,8 @@ +interface ServerResponse { + + /** The state indicator for responses from the server */ + status: number; + + /** Additional information that is provided by the server */ + message?: string; +} \ No newline at end of file diff --git a/common/types/events/SaveShip.ts b/common/types/events/SaveShip.ts new file mode 100644 index 0000000..2841946 --- /dev/null +++ b/common/types/events/SaveShip.ts @@ -0,0 +1,18 @@ +/** The data the client must provide in the `SaveShip` event. */ +interface SaveShip { + colour: string; + ship: string; +} + +/** + * The event that get's sent out to all the other players on a successful + * `SaveShip` event + */ +interface DesignUpdate { + player: string; + ship: string; + colour: string; +} + +/** The response to the client that triggered the `SaveShip` event. */ +interface SaveShipResponse extends ServerResponse {} \ No newline at end of file