From 695e3343778ec01908356efc7283cb0a91fe9843 Mon Sep 17 00:00:00 2001 From: Metaa Date: Tue, 6 Jun 2017 20:52:34 +0200 Subject: [PATCH 1/2] Resolve GitHub issue #64 -> "Maintain a list of frontend grid sizes and export them" --- src/InteractiveConstants.ts | 29 +++++++++++++++++++++++ src/index.ts | 1 + src/state/interfaces/controls/IControl.ts | 6 +++++ 3 files changed, 36 insertions(+) create mode 100644 src/InteractiveConstants.ts diff --git a/src/InteractiveConstants.ts b/src/InteractiveConstants.ts new file mode 100644 index 0000000..8ec850f --- /dev/null +++ b/src/InteractiveConstants.ts @@ -0,0 +1,29 @@ +import { IGridLayout } from './state/interfaces/controls'; + +/** + * Offers constant information values to use in an application. + */ +export class InteractiveConstants { + private static readonly _gridLayoutSizes: IGridLayout[] = [ + { + size: 'large', + width: 80, + height: 20, + }, { + size: 'medium', + width: 45, + height: 25, + }, { + size: 'small', + width: 30, + height: 40, + }, + ]; + + /** + * @returns {{GridLayout[]}} a copy of the stored layout definitions to prevent users from breaking it. + */ + public static get gridLayoutSizes(): IGridLayout[] { + return {...InteractiveConstants._gridLayoutSizes}; + } +} diff --git a/src/index.ts b/src/index.ts index 78d796f..7231b47 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ export * from './state/Group'; export * from './IClient'; export * from './GameClient'; export * from './ParticipantClient'; +export * from './InteractiveConstants'; export * from './util'; export * from './errors'; diff --git a/src/state/interfaces/controls/IControl.ts b/src/state/interfaces/controls/IControl.ts index b1b9b7d..061f94e 100644 --- a/src/state/interfaces/controls/IControl.ts +++ b/src/state/interfaces/controls/IControl.ts @@ -8,6 +8,12 @@ import { IMeta } from './IMeta'; export type ControlKind = 'button' | 'joystick'; export type GridSize = 'large' | 'medium' | 'small'; +export interface IGridLayout { + readonly size: GridSize; + readonly width: number; + readonly height: number; +} + /** * Represents the raw data a control has when transmitted * and received over a socket connection. From d39fc37d88a870f91223feb09157cc232694bfd4 Mon Sep 17 00:00:00 2001 From: Metaa Date: Mon, 19 Jun 2017 20:19:13 +0200 Subject: [PATCH 2/2] Replace InteractiveConstants with a module, make gridLayoutSizes truly readonly (also sorted modules in index.ts by the alphabet) --- src/{InteractiveConstants.ts => constants.ts} | 13 +++---------- src/index.ts | 4 ++-- 2 files changed, 5 insertions(+), 12 deletions(-) rename src/{InteractiveConstants.ts => constants.ts} (53%) diff --git a/src/InteractiveConstants.ts b/src/constants.ts similarity index 53% rename from src/InteractiveConstants.ts rename to src/constants.ts index 8ec850f..558c1db 100644 --- a/src/InteractiveConstants.ts +++ b/src/constants.ts @@ -3,8 +3,8 @@ import { IGridLayout } from './state/interfaces/controls'; /** * Offers constant information values to use in an application. */ -export class InteractiveConstants { - private static readonly _gridLayoutSizes: IGridLayout[] = [ +export module InteractiveConstants { + export const gridLayoutSizes: IGridLayout[] = Object.freeze([ { size: 'large', width: 80, @@ -18,12 +18,5 @@ export class InteractiveConstants { width: 30, height: 40, }, - ]; - - /** - * @returns {{GridLayout[]}} a copy of the stored layout definitions to prevent users from breaking it. - */ - public static get gridLayoutSizes(): IGridLayout[] { - return {...InteractiveConstants._gridLayoutSizes}; - } + ]); } diff --git a/src/index.ts b/src/index.ts index 7231b47..e5ba2d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,9 +5,9 @@ export * from './state/Group'; export * from './IClient'; export * from './GameClient'; export * from './ParticipantClient'; -export * from './InteractiveConstants'; -export * from './util'; +export * from './constants'; export * from './errors'; +export * from './util'; /** * This allows you to specify which WebSocket implementation your