Skip to content

Commit

Permalink
Add stripBattletags option
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Mar 12, 2018
1 parent a9889dd commit f0a04d9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Support Shifting Blade
- Show Quests above hero portrait
- Add Download XML from settings (#210, @dzannotti)
- Add option to strip battletags from player names

### Changed
- Tweak art for legendary minions in hand
Expand Down
8 changes: 8 additions & 0 deletions ts/Launcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ export default class Launcher {
this.opts.scrubber.rewind();
}

public stripBattletags(strip?: boolean): Launcher {
if (typeof strip === "undefined") {
strip = true;
}
this.opts.stripBattletags = strip;
return this;
}

public get turn(): number {
return this.opts.scrubber.getCurrentTurn();
}
Expand Down
5 changes: 3 additions & 2 deletions ts/components/GameWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
KeybindingProps,
LocaleProps,
MulliganOracle,
StreamScrubber,
StreamScrubber, StripBattletagsProps,
} from "../interfaces";
import Scrubber from "./Scrubber";
import EventLog from "./EventLog";
Expand All @@ -22,7 +22,7 @@ import screenfull from "screenfull";
import GameStateSink from "../state/GameStateSink";
import { CardData } from "hearthstonejson-client";

export interface GameWidgetProps extends AssetDirectoryProps, CardArtDirectory, EventHandlerProps, LocaleProps, KeybindingProps, React.ClassAttributes<GameWidget> {
export interface GameWidgetProps extends AssetDirectoryProps, CardArtDirectory, EventHandlerProps, LocaleProps, KeybindingProps, StripBattletagsProps, React.ClassAttributes<GameWidget> {
sink: GameStateSink;
startupTime: number;
interaction?: InteractiveBackend;
Expand Down Expand Up @@ -293,6 +293,7 @@ export default class GameWidget extends React.Component<GameWidgetProps, GameWid
hideCards={!this.state.isRevealingCards}
playerNames={this.props.playerNames || null}
loadingError={this.props.loadingError}
stripBattletags={this.props.stripBattletags}
/>;
let log = <EventLog
key="log"
Expand Down
14 changes: 12 additions & 2 deletions ts/components/GameWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CardOracleProps,
AssetDirectoryProps,
CardArtDirectory,
MulliganOracleProps
MulliganOracleProps, StripBattletagsProps,
} from "../interfaces";
import GameState from "../state/GameState";
import TwoPlayerGame from "./game/TwoPlayerGame";
Expand All @@ -19,7 +19,7 @@ import LoadingScreen from "./LoadingScreen";
import * as bowser from "bowser";
import {cookie} from "cookie_js";

interface GameWrapperProps extends CardDataProps, CardOracleProps, MulliganOracleProps, AssetDirectoryProps, CardArtDirectory, HideCardsProps, React.ClassAttributes<GameWrapper> {
interface GameWrapperProps extends CardDataProps, CardOracleProps, MulliganOracleProps, AssetDirectoryProps, CardArtDirectory, HideCardsProps, StripBattletagsProps, React.ClassAttributes<GameWrapper> {
state: GameState;
interaction?: InteractiveBackend;
swapPlayers?: boolean;
Expand Down Expand Up @@ -153,13 +153,23 @@ export default class GameWrapper extends React.Component<GameWrapperProps, GameW
assetDirectory={this.props.assetDirectory}
cardArtDirectory={this.props.cardArtDirectory}
hideCards={this.props.hideCards}
stripBattletags={this.props.stripBattletags}
/>;
default:
return <div>Unsupported player count ({playerCount}).</div>
}
}

private renderLoadingScreen(players?: string[]) {
if (Array.isArray(players) && this.props.stripBattletags) {
players = players.map((playerName) => {
const match = /^(.*)#\d+$/.exec(playerName.trim());
if (match) {
return match[1];
}
return playerName;
});
}
return <LoadingScreen players={players} />;
}

Expand Down
16 changes: 12 additions & 4 deletions ts/components/game/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import {
CardArtDirectory,
GameStateDescriptorStackProps,
HideCardsProps,
MulliganOracleProps
MulliganOracleProps, StripBattletagsProps,
} from "../../interfaces";
import GameStateDescriptor from "../../state/GameStateDescriptor";

interface PlayerProps extends OptionCallbackProps, CardDataProps, CardOracleProps, MulliganOracleProps, AssetDirectoryProps,
CardArtDirectory,GameStateDescriptorStackProps, HideCardsProps, React.ClassAttributes<Player> {
CardArtDirectory,GameStateDescriptorStackProps, HideCardsProps, StripBattletagsProps, React.ClassAttributes<Player> {
player: PlayerEntity;
entities: Immutable.Map<number, Immutable.Map<number, Entity>>;
options: Immutable.Map<number, Immutable.Map<number, Option>>;
Expand Down Expand Up @@ -265,8 +265,16 @@ export default class Player extends React.Component<PlayerProps> {
/>;
}

let name = this.props.player.name ?
<div className="name" title={this.props.player.name}>{this.props.player.name}</div> : null;
let name = null;
if (this.props.player.name) {
let playerName = this.props.player.name.trim();
if (this.props.stripBattletags) {
const match = /^(.*)#\d+$/.exec(playerName);
playerName = match ? match[1] : playerName;
}
name = <div className="name" title={playerName}>{playerName}</div>;
}

let rank = <Rank
rank={this.props.player.rank }
legendRank={this.props.player.legendRank }
Expand Down
15 changes: 12 additions & 3 deletions ts/components/game/TwoPlayerGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import * as React from "react";
import * as Immutable from "immutable";

import {
EntityProps, OptionCallbackProps, CardDataProps, CardOracleProps, AssetDirectoryProps,
GameStateDescriptorStackProps, HideCardsProps, MulliganOracleProps
EntityProps,
OptionCallbackProps,
CardDataProps,
CardOracleProps,
AssetDirectoryProps,
GameStateDescriptorStackProps,
HideCardsProps,
MulliganOracleProps,
StripBattletagsProps,
} from "../../interfaces";
import Entity from "../../Entity";
import Player from "./Player";
Expand All @@ -15,7 +22,7 @@ import Choice from "../../Choice";
import Choices from "../../Choices";

interface TwoPlayerGameProps extends EntityProps, CardDataProps, CardOracleProps, MulliganOracleProps, OptionCallbackProps,
AssetDirectoryProps, GameStateDescriptorStackProps, HideCardsProps, React.ClassAttributes<TwoPlayerGame> {
AssetDirectoryProps, GameStateDescriptorStackProps, HideCardsProps, StripBattletagsProps, React.ClassAttributes<TwoPlayerGame> {
player1: PlayerEntity;
player2: PlayerEntity;
entities: Immutable.Map<number, Immutable.Map<number, Immutable.Map<number, Entity>>>;
Expand Down Expand Up @@ -50,6 +57,7 @@ export default class TwoPlayerGame extends React.Component<TwoPlayerGameProps> {
assetDirectory={this.props.assetDirectory}
cardArtDirectory={this.props.cardArtDirectory}
hideCards={this.props.hideCards}
stripBattletags={this.props.stripBattletags}
/>
{this.props.optionCallback && <EndTurnButton option={this.props.endTurnOption}
optionCallback={this.props.optionCallback} onlyOption={options.count() === 0}
Expand All @@ -67,6 +75,7 @@ export default class TwoPlayerGame extends React.Component<TwoPlayerGameProps> {
descriptors={this.props.descriptors}
assetDirectory={this.props.assetDirectory}
cardArtDirectory={this.props.cardArtDirectory}
stripBattletags={this.props.stripBattletags}
/>
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions ts/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ export interface KeybindingProps {
enableKeybindings?: boolean;
}

export interface StripBattletagsProps {
stripBattletags?: boolean;
}

export interface StreamScrubberInhibitor {
isInhibiting: () => boolean;
}
Expand Down

0 comments on commit f0a04d9

Please sign in to comment.