Skip to content

Commit

Permalink
Launcher: Add various methods to control playback
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Aug 16, 2016
1 parent f93940e commit c12d9d4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions ts/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface StreamScrubber extends EventEmitter {
rewind(): void;
fastForward(): void;
getCurrentTime(): number;
getCurrentTurn(): number;
getSpeed(): number;
canPlay(): boolean;
getHistory(): GameStateHistory;
Expand Down
29 changes: 26 additions & 3 deletions ts/run.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Launcher {
protected queryCardMetadata:QueryCardMetadata;
protected startFromTurn:number;
protected turnCb:(turn:number) => void;
protected pause:boolean;
protected shouldStartPaused:boolean;
protected ref:GameWidget;

constructor(target:any) {
Expand Down Expand Up @@ -108,7 +108,7 @@ class Launcher {
}

public startPaused(paused?:boolean):Launcher {
this.pause = typeof paused === "undefined" ? true : !!paused;
this.shouldStartPaused = typeof this.shouldStartPaused === "undefined" ? true : !!this.shouldStartPaused;
return this;
}

Expand Down Expand Up @@ -172,6 +172,29 @@ class Launcher {
return (this.opts.scrubber as GameStateScrubber).percentageWatched;
}

public play():void {
this.opts.scrubber.play();
}

public pause():void {
this.opts.scrubber.pause();
}

public toggle():void {
this.opts.scrubber.toggle();
}

public get turn():number {
return this.opts.scrubber.getCurrentTurn();
}

public set turn(turn:number) {
let turnState = this.opts.scrubber.getHistory().turnMap.get(turn);
if (turnState) {
this.opts.scrubber.seek(turnState.time);
}
}

public fromUrl(url:string):void {
var decoder = new HSReplayDecoder();
decoder.debug = this.opts.debug;
Expand Down Expand Up @@ -214,7 +237,7 @@ class Launcher {
}
], () => {
scrubber.play();
if (this.pause || (typeof this.pause === "undefined" && this.startFromTurn)) {
if (this.shouldStartPaused || (typeof this.shouldStartPaused === "undefined" && this.startFromTurn)) {
scrubber.pause();
}
});
Expand Down
4 changes: 4 additions & 0 deletions ts/state/GameStateScrubber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ export default class GameStateScrubber extends Stream.Duplex implements StreamSc
return this.inhibitor && this.inhibitor.isInhibiting();
}

public getCurrentTurn(): number {
return this.currentTurn;
}

get currentTurn(): number {
if(!this.lastState) {
return null;
Expand Down

0 comments on commit c12d9d4

Please sign in to comment.