This repository has been archived by the owner on Jul 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from mixer/feat/screen
feat(screen): support for screen controls
- Loading branch information
Showing
5 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters