Skip to content

Commit

Permalink
Fix previously hidden entities with 0/0 stats
Browse files Browse the repository at this point in the history
Introduced with 6e77e6a.
  • Loading branch information
beheh committed Oct 11, 2016
1 parent 17e71f7 commit b4924e2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Add several character states (#7, @azeier)

### Fixed
- Fix previously hidden entities with 0/0 stats (e.g. Prince Malchezaar)

## [0.8.0] - 2016-10-10
### Added
- Show Prince Malchezaar at game start (#142, @azeier)
Expand Down
6 changes: 5 additions & 1 deletion ts/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ export default class Entity {
return this._cardId;
}

get hidden():boolean {
return !this.cardId;
}

get revealed():boolean {
return !!this.cardId;
return !this.hidden;
}

public getResourcesUsed():number {
Expand Down
22 changes: 21 additions & 1 deletion ts/components/game/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ interface CardProps extends EntityProps, OptionProps, React.ClassAttributes<Card
isHidden?: boolean;
defaultStats?: boolean;
mulligan?: boolean;
customHealth?: number;
customAtk?: number;
customCost?: number;
}

export default class Card extends React.Component<CardProps, void> {
Expand Down Expand Up @@ -218,8 +221,25 @@ export default class Card extends React.Component<CardProps, void> {
}

private getStatValue(tag: GameTag, defaultValue: number): number {
switch(tag) {
case GameTag.HEALTH:
if (typeof this.props.customHealth !== "undefined") {
return this.props.customHealth;
}
break;
case GameTag.ATK:
if (typeof this.props.customAtk !== "undefined") {
return this.props.customAtk;
}
break;
case GameTag.COST:
if (typeof this.props.customCost !== "undefined") {
return this.props.customCost;
}
break;
}
let value = this.props.entity.getTag(tag);
if (this.props.defaultStats || this.props.isHidden && !value) {
if (this.props.defaultStats || this.props.isHidden) {
return defaultValue;
}
return value;
Expand Down
17 changes: 12 additions & 5 deletions ts/components/game/Hand.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import * as React from "react";

import EntityList from "./EntityList";
import Entity from "../../Entity";
import Option from "../../Option";
import Card from "./Card";
import {GameTag} from "../../enums";
import {CardType} from "../../enums";
import {EntityListProps} from "../../interfaces";

interface HandProps extends EntityListProps {
Expand Down Expand Up @@ -45,6 +43,10 @@ export default class Hand extends EntityList<HandProps> {

let wasHidden = false;

let customHealth = undefined;
let customAtk = undefined;
let customCost = undefined;

if (this.props.hideCards) {
entity = new Entity(entity.id, entity.getTags());
}
Expand All @@ -55,13 +57,15 @@ export default class Hand extends EntityList<HandProps> {
let proxyId = this.props.cardOracle.findKey(x => x === "OG_279");
let proxy = proxyId && this.props.setAside.get(proxyId);
if (proxy) {
entity = entity.setTag(GameTag.ATK, proxy.getAtk()).setTag(GameTag.HEALTH, proxy.getHealth());
customHealth = proxy.getHealth();
customAtk = proxy.getAtk();
}
}
wasHidden = true;
}

return (<Card entity={entity}
return <Card
entity={entity}
option={option}
style={style}
optionCallback={this.props.optionCallback}
Expand All @@ -70,6 +74,9 @@ export default class Hand extends EntityList<HandProps> {
isHidden={wasHidden}
controller={this.props.controller}
cardArtDirectory={this.props.cardArtDirectory}
/>);
customHealth={customHealth}
customAtk={customAtk}
customCost={customCost}
/>;
}
}
3 changes: 0 additions & 3 deletions ts/state/mutators/HideEntityMutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export default class HideEntityMutator implements GameStateMutator {
// reset various tags
let tags = oldEntity.getTags();
tags = tags.set("" + GameTag.ZONE, this.zone);
tags = tags.remove("" + GameTag.ATK);
tags = tags.remove("" + GameTag.HEALTH);
tags = tags.remove("" + GameTag.DAMAGE);
let newEntity = oldEntity.replaceTags(tags).setCardId(null);

return state.apply(new ReplaceEntityMutator(newEntity));
Expand Down

0 comments on commit b4924e2

Please sign in to comment.