Skip to content

Commit

Permalink
Launcher: Add .addPlayerName(playerName: string)
Browse files Browse the repository at this point in the history
Refs #167.
  • Loading branch information
beheh committed Nov 20, 2016
1 parent fb377b8 commit fc990ec
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Add `Launcher.addPlayerName(playerName: string)`

## [0.9.1] - 2016-11-19
### Fixed
Expand Down
8 changes: 8 additions & 0 deletions ts/Launcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ export default class Launcher {
return this;
}

public addPlayerName(playerName: string): Launcher {
if (!this.opts.playerNames) {
this.opts.playerNames = [];
}
this.opts.playerNames[this.opts.playerNames.length] = playerName;
return this;
}

public fromUrl(url: string): void {
let decoder = new HSReplayDecoder();
decoder.debug = this.opts.debug;
Expand Down
7 changes: 5 additions & 2 deletions ts/components/GameWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,17 @@ export default class GameWidget extends React.Component<GameWidgetProps, GameWid
hasStarted={this.props.scrubber.canInteract()}
cardOracle={this.state.cardOracle}
mulliganOracle={this.state.mulliganOracle}
hideCards={!this.state.isRevealingCards} />;
hideCards={!this.state.isRevealingCards}
playerNames={this.props.playerNames || null}
/>;
let log = <EventLog key="log"
state={this.state.gameState}
cards={this.state.cards}
cardOracle={this.state.cardOracle}
tail={this.props.scrubber.getHistory().tail}
currentTime={this.props.scrubber.getCurrentTime()}
isHidden={!this.state.isLogVisible} />;
isHidden={!this.state.isLogVisible}
/>;

parts.push(
<div key="game-wrapper" className="game-wrapper">
Expand Down
9 changes: 5 additions & 4 deletions ts/components/GameWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface GameWrapperProps extends CardDataProps, CardOracleProps, MulliganOracl
interaction?: InteractiveBackend;
swapPlayers?: boolean;
hasStarted?: boolean;
playerNames?: string[]|null;
}

interface GameWrapperState {
Expand Down Expand Up @@ -75,7 +76,7 @@ export default class GameWrapper extends React.Component<GameWrapperProps, GameW
// check if we even have a game state
let gameState = this.props.state;
if (!gameState) {
return this.renderLoadingScreen();
return this.renderLoadingScreen(this.props.playerNames);
}

let entityTree = gameState.entityTree;
Expand All @@ -84,18 +85,18 @@ export default class GameWrapper extends React.Component<GameWrapperProps, GameW
// check if any entities are present
let allEntities = gameState.entities;
if (!allEntities) {
return this.renderLoadingScreen();
return this.renderLoadingScreen(this.props.playerNames);
}

// find the game entity
let game = gameState.game;
if (!game) {
return this.renderLoadingScreen();
return this.renderLoadingScreen(this.props.playerNames);
}

// find the players
if (gameState.getPlayerCount() === 0) {
return this.renderLoadingScreen();
return this.renderLoadingScreen(this.props.playerNames);
}
let players = allEntities.filter(GameWrapper.filterByCardType(CardType.PLAYER)) as Immutable.Map<number, PlayerEntity>;

Expand Down
2 changes: 1 addition & 1 deletion ts/components/LoadingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class LoadingScreen extends React.Component<LoadingScreenProps, v
public render() {
let players = String.fromCharCode(160); // &nbsp;

if(this.props.players) {
if(this.props.players && this.props.players.length) {
switch(this.props.players.length) {
case 1:
players = this.props.players[0];
Expand Down
1 change: 1 addition & 0 deletions ts/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export interface GameWidgetProps extends AssetDirectoryProps, CardArtDirectory,
onToggleSwap?: (swap: boolean) => void;
onFullscreen?: (fullscreen: boolean) => void;
onReady?: () => void;
playerNames?: string[];
}

export interface StreamScrubberInhibitor {
Expand Down

0 comments on commit fc990ec

Please sign in to comment.