Skip to content
This repository has been archived by the owner on Jul 31, 2020. It is now read-only.

Commit

Permalink
Merge pull request #98 from mixer/feat/screen
Browse files Browse the repository at this point in the history
feat(screen): support for screen controls
  • Loading branch information
AechDub committed Apr 30, 2018
2 parents abbe995 + e25c53c commit 88bf3ba
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/state/controls/Screen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { IScreenInput } from '../interfaces/controls/IInput';
import { IScreen, IScreenData, IScreenUpdate } from '../interfaces/controls/IScreen';
import { Control } from './Control';

/**
* Screen can be used to get mouse input
*/
export class Screen extends Control<IScreenData> implements IScreen {
/**
* Whether the control will send coordinates on mousemove
*/
public sendOnMove: boolean;
/**
* Whether the control will send coordinates on mousedown
*/
public sendMoveOnMouseDown: boolean;
/**
* The debounce rate for input sent
*/
public moveDeboune: number;

/**
* Update this control on the server.
*/
public update(controlUpdate: IScreenUpdate): Promise<void> {
// Clone to prevent mutations
// XXX: Typescript 2.4 is strict, let the compiler be clever.
const changedData = { ...controlUpdate };
return super.update(changedData);
}

/**
* Sends an input event from a participant to the server for consumption.
*/
public giveInput(input: IScreenInput): Promise<void> {
return this.sendInput(input);
}
}
1 change: 1 addition & 0 deletions src/state/controls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export { Control } from './Control';
export { Button } from './Button';
export { Joystick } from './Joystick';
export { Label } from './Label';
export { Screen } from './Screen';
export { Textbox } from './Textbox';
18 changes: 18 additions & 0 deletions src/state/interfaces/controls/IInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ export interface IJoystickInput extends IInput {
y: number;
}

/**
* Extends the base input to include screen specific data.
*/
export interface IScreenInput extends IInput {
/**
* Joysticks can only be moved.
*/
event: 'move' | 'mousedown' | 'mouseup';
/**
* The X coordinate of the input.
*/
x: number;
/**
* The Y coordinate of the input.
*/
y: number;
}

/**
* Extends the base input to include textbox specific data.
*/
Expand Down
45 changes: 45 additions & 0 deletions src/state/interfaces/controls/IScreen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { IControl, IControlData, IControlUpdate } from './IControl';
/**
* Extends the regular control data with additional properties for Textbox
*/
export interface IScreenData extends IControlData {
/**
* Whether the control will send coordinates on mousemove
*/
sendOnMove?: boolean;
/**
* Whether the control will send coordinates on mousedown
*/
sendMoveOnMouseDown?: boolean;
/**
* The debounce rate for input sent
*/
moveDeboune?: number;
}

/**
* Represents updatable components of a scren control which developers can
* update from game clients.
*/
export interface IScreenUpdate extends IControlUpdate {
/**
* Whether the control will send coordinates on mousemove
*/
sendOnMove?: boolean;
/**
* Whether the control will send coordinates on mousedown
*/
sendMoveOnMouseDown?: boolean;
/**
* The debounce rate for input sent
*/
moveDeboune?: number;
}

export interface IScreen extends IControl, IScreenData {
sendOnMove: boolean;
sendMoveOnMouseDown: boolean;
moveDeboune: number;
// GameClient
update(changedData: IScreen): Promise<void>;
}
1 change: 1 addition & 0 deletions src/state/interfaces/controls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export * from './IControl';
export * from './IInput';
export * from './IJoystick';
export * from './ILabel';
export * from './IScreen';
export * from './ITextbox';
export * from './IMeta';

0 comments on commit 88bf3ba

Please sign in to comment.