clean up
This commit is contained in:
parent
fa83e7ce82
commit
2e035d57fa
@ -4,7 +4,7 @@ import React from 'react';
|
|||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
import { ILeaguePokemon, League } from 'app/models/League';
|
import { IBestWorstStats, ILeaguePokemon, League } from 'app/models/League';
|
||||||
import { Grade, IStats, } from 'app/models/Pokemon';
|
import { Grade, IStats, } from 'app/models/Pokemon';
|
||||||
import { calculateCp, calculateStatAtLevel } from 'app/utils/calculator';
|
import { calculateCp, calculateStatAtLevel } from 'app/utils/calculator';
|
||||||
import { alolanForms, formatDexNumber, formatForm, formatType } from 'app/utils/formatter';
|
import { alolanForms, formatDexNumber, formatForm, formatType } from 'app/utils/formatter';
|
||||||
@ -35,6 +35,29 @@ interface IState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PokemonExplorer extends React.Component<IPokemonExplorerProps, IState> {
|
export class PokemonExplorer extends React.Component<IPokemonExplorerProps, IState> {
|
||||||
|
|
||||||
|
private static calculateStatRanks(rankedPokemon : IStats | null, stats : IBestWorstStats) {
|
||||||
|
const rankedHp = rankedPokemon !== null ? rankedPokemon.hp : 0;
|
||||||
|
const rankedAtk = rankedPokemon !== null ? rankedPokemon.atk : 0;
|
||||||
|
const rankedDef = rankedPokemon !== null ? rankedPokemon.def : 0;
|
||||||
|
|
||||||
|
const maxStamina = stats.stamina;
|
||||||
|
const staminaStatRank = Math.floor(((rankedHp - maxStamina.worst) / (maxStamina.best - maxStamina.worst)) * 100);
|
||||||
|
const maxAttack = stats.attack;
|
||||||
|
const attackStatRank = Math.floor(((rankedAtk - maxAttack.worst) / (maxAttack.best - maxAttack.worst)) * 100);
|
||||||
|
const maxDefense = stats.defense;
|
||||||
|
const defenseStatRank = Math.floor(((rankedDef - maxDefense.worst) / (maxDefense.best - maxDefense.worst)) * 100);
|
||||||
|
|
||||||
|
return {
|
||||||
|
rankedHp,
|
||||||
|
rankedAtk,
|
||||||
|
rankedDef,
|
||||||
|
staminaStatRank,
|
||||||
|
attackStatRank,
|
||||||
|
defenseStatRank,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private readonly MIN_LEVEL = 1;
|
private readonly MIN_LEVEL = 1;
|
||||||
private readonly MAX_LEVEL = 40;
|
private readonly MAX_LEVEL = 40;
|
||||||
private readonly MIN_IV = 0;
|
private readonly MIN_IV = 0;
|
||||||
@ -125,9 +148,14 @@ export class PokemonExplorer extends React.Component<IPokemonExplorerProps, ISta
|
|||||||
|
|
||||||
const rankedGrade = rankedPokemon !== null ? Grade[rankedPokemon.speciesGrade] : '-';
|
const rankedGrade = rankedPokemon !== null ? Grade[rankedPokemon.speciesGrade] : '-';
|
||||||
const rankedCp = rankedPokemon !== null ? rankedPokemon.cp : '-';
|
const rankedCp = rankedPokemon !== null ? rankedPokemon.cp : '-';
|
||||||
const rankedHp = rankedPokemon !== null ? rankedPokemon.hp : 0;
|
const {
|
||||||
const rankedAtk = rankedPokemon !== null ? rankedPokemon.atk : 0;
|
rankedHp,
|
||||||
const rankedDef = rankedPokemon !== null ? rankedPokemon.def : 0;
|
rankedAtk,
|
||||||
|
rankedDef,
|
||||||
|
staminaStatRank,
|
||||||
|
attackStatRank,
|
||||||
|
defenseStatRank,
|
||||||
|
} = PokemonExplorer.calculateStatRanks(rankedPokemon, leaguePokemon.statMax[activeLeague]);
|
||||||
|
|
||||||
const idIvLevelInput = 'iv-level-input';
|
const idIvLevelInput = 'iv-level-input';
|
||||||
const idIvHpInput = 'iv-hp-input';
|
const idIvHpInput = 'iv-hp-input';
|
||||||
@ -200,13 +228,6 @@ export class PokemonExplorer extends React.Component<IPokemonExplorerProps, ISta
|
|||||||
type2 = <div className={ `${pokemonType} ${formatType(leaguePokemon.types.type2)}` }>{ formatType(leaguePokemon.types.type2) }</div>;
|
type2 = <div className={ `${pokemonType} ${formatType(leaguePokemon.types.type2)}` }>{ formatType(leaguePokemon.types.type2) }</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const maxStamina = leaguePokemon.statMax[activeLeague].stamina;
|
|
||||||
const staminaStatRank = Math.floor(((rankedHp - maxStamina.worst) / (maxStamina.best - maxStamina.worst)) * 100);
|
|
||||||
const maxAttack = leaguePokemon.statMax[activeLeague].attack;
|
|
||||||
const attackStatRank = Math.floor(((rankedAtk - maxAttack.worst) / (maxAttack.best - maxAttack.worst)) * 100);
|
|
||||||
const maxDefense = leaguePokemon.statMax[activeLeague].defense;
|
|
||||||
const defenseStatRank = Math.floor(((rankedDef - maxDefense.worst) / (maxDefense.best - maxDefense.worst)) * 100);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={ styles.wrapper }>
|
<div className={ styles.wrapper }>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@ -34,7 +34,7 @@ interface IBestWorstStatSpread {
|
|||||||
best : number;
|
best : number;
|
||||||
worst : number;
|
worst : number;
|
||||||
}
|
}
|
||||||
interface IBestWorstStats {
|
export interface IBestWorstStats {
|
||||||
stamina : IBestWorstStatSpread;
|
stamina : IBestWorstStatSpread;
|
||||||
attack : IBestWorstStatSpread;
|
attack : IBestWorstStatSpread;
|
||||||
defense : IBestWorstStatSpread;
|
defense : IBestWorstStatSpread;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user