Skip to content

Commit

Permalink
Show Quests above hero portrait (with temporary art)
Browse files Browse the repository at this point in the history
  • Loading branch information
beheh committed Apr 11, 2017
1 parent c44f41c commit c817844
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- HSReplay: Add warning if tag is missing required entity id
- Add Quest frame art
- Support Shifting Blade
- Show Quests above hero portrait

### Changed
- Tweak art for legendary minions in hand
Expand Down
47 changes: 28 additions & 19 deletions ts/components/game/Hero.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import * as React from "react";
import * as Immutable from "immutable";
import EntityInPlay from "./EntityInPlay";
import {EntityInPlayProps, CardOracleProps} from "../../interfaces";
import {CardOracleProps, EntityInPlayProps} from "../../interfaces";
import Entity from "../../Entity";
import Attack from "./stats/Attack";
import Damage from "./stats/Damage";
import Healing from "./stats/Healing";
import Health from "./stats/Health";
import Armor from "./stats/Armor";
import SecretText from "./stats/SecretText"
import SecretText from "./stats/SecretText";
import HeroArt from "./visuals/HeroArt";
import {MetaDataType} from "../../enums";
import {GameTag, MetaDataType} from "../../enums";
import MetaData from "../../MetaData";
import GameStateDescriptor from "../../state/GameStateDescriptor";

Expand All @@ -26,22 +26,30 @@ export default class Hero extends EntityInPlay<HeroProps> {
protected jsx() {
let entity = this.props.entity;

let secretCount = this.props.secrets.count();
let secretText = secretCount > 1 ? secretCount.toString() : "?";
let secrets = this.props.secrets;
let quests = [];

let hasQuest = secrets.some((potentialQuest: Entity) => !!potentialQuest.getTag(GameTag.QUEST));
let secretCount = secrets.count();

// build text in icon
let secretText = hasQuest ? "!" : (secretCount > 1 ? "" + secretCount : "?");

// build title
let secretTitle = this.props.secrets.reduce((title, entity: Entity): string => {
let name = entity.cardId;
if(!entity.revealed) {
if(this.props.cardOracle && this.props.cardOracle.has(entity.id)) {
if (!entity.revealed) {
if (this.props.cardOracle && this.props.cardOracle.has(entity.id)) {
name = this.props.cardOracle.get(entity.id);
}
else {
return title;
}
}
if(title) {
if (title) {
title += ", ";
}
if(this.props.cards && this.props.cards.has(name)) {
if (this.props.cards && this.props.cards.has(name)) {
name = this.props.cards.get(name).name || name;
}
return title += name;
Expand All @@ -54,7 +62,7 @@ export default class Hero extends EntityInPlay<HeroProps> {
this.props.descriptors.forEach((descriptor: GameStateDescriptor) => {
descriptor.metaData.forEach((metaData: MetaData) => {
if (metaData.entities.has(entity.id)) {
switch(metaData.type) {
switch (metaData.type) {
case MetaDataType.DAMAGE:
damage += metaData.data;
break;
Expand All @@ -68,23 +76,24 @@ export default class Hero extends EntityInPlay<HeroProps> {
}

return [
<HeroArt key="art"
<HeroArt
key="art"
entity={entity}
secrets={this.props.secrets}
cards={this.props.cards}
assetDirectory={this.props.assetDirectory}
cardArtDirectory={this.props.cardArtDirectory}
damage={damage}
healing={healing}
/>,
/>,
<div key="stats" className="stats">
{entity.getAtk() ? <Attack attack={entity.getAtk()}/> : null}
<Health health={entity.getHealth() } damage={entity.getDamage()}/>
{entity.getArmor() ? <Armor armor={entity.getArmor()}/> : null}
{secretCount > 0 ? <SecretText text={secretText} title={secretTitle}/> : null}
{damage != 0 ? <Damage damage={damage}/> : null}
{healing != 0 ? <Healing healing={healing}/> : null}
</div>
{entity.getAtk() ? <Attack attack={entity.getAtk()} /> : null}
<Health health={entity.getHealth() } damage={entity.getDamage()} />
{entity.getArmor() ? <Armor armor={entity.getArmor()} /> : null}
{(hasQuest || secretCount > 0) ? <SecretText text={secretText} title={secretTitle} /> : null}
{damage != 0 ? <Damage damage={damage} /> : null}
{healing != 0 ? <Healing healing={healing} /> : null}
</div>,
];
}
}
9 changes: 8 additions & 1 deletion ts/components/game/stats/SecretText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ interface SecretTextProps extends React.ClassAttributes<SecretText> {

export default class SecretText extends React.Component<SecretTextProps, void> {
public render(): JSX.Element {
return <div className="secret-text" title={this.props.title}>{this.props.text}</div>;
return (
<div
className={"secret-text"}
title={this.props.title}
>
{this.props.text}
</div>
);
}
}
48 changes: 29 additions & 19 deletions ts/components/game/visuals/HeroArt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import CardArt from "./CardArt";
import {EntityProps} from "../../../interfaces";

interface HeroArtProps extends EntityProps {
secrets:Immutable.Map<number, Entity>;
secrets: Immutable.Map<number, Entity>;
}

export default class HeroArt extends React.Component<HeroArtProps, void> {


shouldComponentUpdate(nextProps:HeroArtProps, nextState:{}, nextContext:any):boolean {
shouldComponentUpdate(nextProps: HeroArtProps, nextState: {}, nextContext: any): boolean {
return (
nextProps.entity !== this.props.entity ||
nextProps.damage !== this.props.damage ||
Expand All @@ -24,51 +23,58 @@ export default class HeroArt extends React.Component<HeroArtProps, void> {
);
}

public render():JSX.Element {
public render(): JSX.Element {
let images = [];
let entity = this.props.entity;

images.push({
image: entity.cardId,
isArt: true,
classes: ["hero-portrait"]
classes: ["hero-portrait"],
});

images.push({
image: "hero_frame.png",
classes: ["hero-frame"]
classes: ["hero-frame"],
});

if (entity.isFrozen()) {
images.push({
image: "inplay_hero_frozen.png",
classes: ["hero-frozen"]
classes: ["hero-frozen"],
});
}

if (entity.isImmune()) {
images.push({
image: "inplay_hero_immune.png",
classes: ["hero-immune"]
classes: ["hero-immune"],
});
}

if (entity.getAtk() > 0) {
images.push({
image: "hero_attack.png",
classes: ["hero-attack"]
classes: ["hero-attack"],
});
}

if (entity.getArmor() > 0) {
images.push({
image: "hero_armor.png",
classes: ["hero-armor"]
classes: ["hero-armor"],
});
}

let secretCount = this.props.secrets.count();
if (secretCount > 0) {
let hasQuest = this.props.secrets.some((potentialQuest: Entity) => !!potentialQuest.getTag(GameTag.QUEST));

if (hasQuest) {
images.push({
image: "secret_paladin.png",
classes: ["secret"],
});
}
else if (this.props.secrets.count() > 0) {
let image = "secret_sheathed.png";
let secret = this.props.secrets.first();
if (!secret.getTag(GameTag.EXHAUSTED)) {
Expand All @@ -86,34 +92,38 @@ export default class HeroArt extends React.Component<HeroArtProps, void> {
}
images.push({
image: image,
classes: ["secret"]
classes: ["secret"],
});
}

if (entity.getTag(GameTag.HEALTH) - entity.getTag(GameTag.DAMAGE) <= 0 || entity.getTag(GameTag.ZONE) != Zone.PLAY) {
images.push({
image: "skull.png",
classes: ["skull"]
classes: ["skull"],
});
}

if (this.props.damage && this.props.damage > 0) {
images.push({
image: "damage.png",
classes: ["dmg"]
classes: ["dmg"],
});
}
else if (this.props.healing && this.props.healing > 0) {
images.push({
image: "healing.png",
classes: ["heal"]
classes: ["heal"],
});
}

return (
<CardArt layers={images} scale={1} square={true} margin={false}
assetDirectory={this.props.assetDirectory}
cardArtDirectory={this.props.cardArtDirectory}
<CardArt
layers={images}
scale={1}
square={true}
margin={false}
assetDirectory={this.props.assetDirectory}
cardArtDirectory={this.props.cardArtDirectory}
/>
);
}
Expand Down

0 comments on commit c817844

Please sign in to comment.