2019-03-11 21:42:32 -04:00

143 lines
6.2 KiB
TypeScript

import POGOProtos from 'pogo-protos';
import React from 'react';
import classNames from 'classnames';
import { IPokemon } from 'app/models/Pokemon';
import { formatDexNumber, formatForm, Forms } from 'app/utils/formatter';
import { StatDisplay } from './StatDisplay';
import { TypeIndicator } from './TypeIndicator';
import * as styles from 'app/styles/PokemonDisplay.scss';
export interface IPokemonDisplay {
leaguePokemon : IPokemon;
isHighlighted : boolean;
}
export class PokemonDisplay extends React.Component<IPokemonDisplay> {
public render() {
const {
leaguePokemon,
isHighlighted
} = this.props;
const dex = formatDexNumber(leaguePokemon.dex);
const pokemonInfoLeftColumnCss = classNames(
styles.pokemonInfoLeftColumn,
{
[styles.highlight]: isHighlighted
}
);
const containerCss = classNames(
'nes-container',
'with-title',
);
const containerTitleCss = classNames(
'title',
);
const baseStatsCss = classNames(
styles.pokemonBaseStats,
containerCss,
);
const pokemonIconCss = classNames(
'icon',
'pixel',
'sprite',
`pokemon-${dex}`,
{
normal: Forms.normal.indexOf(leaguePokemon.form) > -1,
alola: Forms.alola.indexOf(leaguePokemon.form) > -1,
plant: Forms.plant.indexOf(leaguePokemon.form) > -1,
sandy: Forms.sandy.indexOf(leaguePokemon.form) > -1,
trash: Forms.trash.indexOf(leaguePokemon.form) > -1,
'west-sea': Forms.westSea.indexOf(leaguePokemon.form) > -1,
'east-sea': Forms.eastSea.indexOf(leaguePokemon.form) > -1,
frost: Forms.frost.indexOf(leaguePokemon.form) > -1,
fan: Forms.fan.indexOf(leaguePokemon.form) > -1,
mow: Forms.mow.indexOf(leaguePokemon.form) > -1,
wash: Forms.wash.indexOf(leaguePokemon.form) > -1,
heat: Forms.heat.indexOf(leaguePokemon.form) > -1,
sky: Forms.sky.indexOf(leaguePokemon.form) > -1,
land: Forms.land.indexOf(leaguePokemon.form) > -1,
overcast: Forms.overcast.indexOf(leaguePokemon.form) > -1,
sunny: Forms.sunny.indexOf(leaguePokemon.form) > -1,
rainy: Forms.rainy.indexOf(leaguePokemon.form) > -1,
snowy: Forms.snowy.indexOf(leaguePokemon.form) > -1,
attack: Forms.attack.indexOf(leaguePokemon.form) > -1,
defense: Forms.defense.indexOf(leaguePokemon.form) > -1,
speed: Forms.speed.indexOf(leaguePokemon.form) > -1,
altered: Forms.altered.indexOf(leaguePokemon.form) > -1,
origin: Forms.origin.indexOf(leaguePokemon.form) > -1,
fighting: Forms.fighting.indexOf(leaguePokemon.form) > -1,
flying: Forms.flying.indexOf(leaguePokemon.form) > -1,
poison: Forms.poison.indexOf(leaguePokemon.form) > -1,
ground: Forms.ground.indexOf(leaguePokemon.form) > -1,
rock: Forms.rock.indexOf(leaguePokemon.form) > -1,
bug: Forms.bug.indexOf(leaguePokemon.form) > -1,
ghost: Forms.ghost.indexOf(leaguePokemon.form) > -1,
steel: Forms.steel.indexOf(leaguePokemon.form) > -1,
fire: Forms.fire.indexOf(leaguePokemon.form) > -1,
water: Forms.water.indexOf(leaguePokemon.form) > -1,
grass: Forms.grass.indexOf(leaguePokemon.form) > -1,
electric: Forms.electric.indexOf(leaguePokemon.form) > -1,
psychic: Forms.psychic.indexOf(leaguePokemon.form) > -1,
ice: Forms.ice.indexOf(leaguePokemon.form) > -1,
dragon: Forms.dragon.indexOf(leaguePokemon.form) > -1,
dark: Forms.dark.indexOf(leaguePokemon.form) > -1,
fairy: Forms.fairy.indexOf(leaguePokemon.form) > -1,
},
);
const type1 = <TypeIndicator type={ leaguePokemon.types.type1 } />;
let type2 : JSX.Element | null = null;
if (leaguePokemon.types.type2) {
type2 = <TypeIndicator type={ leaguePokemon.types.type2 } />;
}
return (
<div className={ styles.pokemonInfoWrapper }>
<div className={ pokemonInfoLeftColumnCss }>
<i className={ pokemonIconCss } />
<h4 className={ styles.dexHeader }>No.{ dex }</h4>
<div className={ styles.pokemonTypeWrapper }>
{ type1 }
{ type2 }
</div>
{ leaguePokemon.form !== POGOProtos.Enums.Form.FORM_UNSET &&
<h6 className={ styles.formHeader }>{ formatForm(leaguePokemon.form) } Form</h6>
}
</div>
<div className={ styles.pokemonInfoRightColumn }>
<h2 className={ styles.pokemonName }>{ leaguePokemon.name }</h2>
<h5>{ leaguePokemon.genus }</h5>
<section className={ baseStatsCss }>
<h3 className={ containerTitleCss }>Base Stats</h3>
<StatDisplay
statLabel={ `HP${ String.fromCharCode(160) }` }
statValue={ leaguePokemon.stats.baseStamina }
statRank={ leaguePokemon.statsRank.staminaRank }
/>
<StatDisplay
statLabel="ATK"
statValue={ leaguePokemon.stats.baseAttack }
statRank={ leaguePokemon.statsRank.attackRank }
/>
<StatDisplay
statLabel="DEF"
statValue={ leaguePokemon.stats.baseDefense }
statRank={ leaguePokemon.statsRank.defenseRank }
/>
</section>
</div>
</div>
);
}
}