refactor: 提取共享 getStatColor、移除 deprecated EVOLUTION_CHAINS

- 新增 ui/shared.ts 统一 getStatColor 函数
- CompanionCard/SpeciesDetail 改用共享函数,消除重复
- 移除 data/evolution.ts 中已废弃的 EVOLUTION_CHAINS 常量
- 清理 index.ts 导出

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-22 01:58:33 +08:00
parent fae96c3e7f
commit 98284a5908
5 changed files with 19 additions and 30 deletions

View File

@@ -2,6 +2,8 @@ import { Dex } from '@pkmn/sim'
import type { SpeciesId } from '../types'
import { ALL_SPECIES_IDS } from '../types'
export interface EvolutionChainStep {
from: SpeciesId
to: SpeciesId
@@ -33,13 +35,3 @@ export function getNextEvolution(speciesId: SpeciesId): EvolutionChainStep | und
minLevel: targetDex.evoLevel ?? undefined,
}
}
/** @deprecated Use getNextEvolution() instead. Kept for backward compat. */
export const EVOLUTION_CHAINS: EvolutionChainStep[] = (() => {
const chains: EvolutionChainStep[] = []
for (const id of ALL_SPECIES_IDS) {
const evo = getNextEvolution(id)
if (evo) chains.push(evo)
}
return chains
})()

View File

@@ -32,7 +32,7 @@ export { DEFAULT_EV_MAPPING, getEVForTool, MAX_EV_PER_STAT, MAX_EV_TOTAL } from
export { xpForLevel, levelFromXp, xpToNextLevel } from './data/xpTable'
export { SPECIES_NAMES, SPECIES_I18N, SPECIES_PERSONALITY } from './data/names'
export { getAllNatureNames, randomNature, getNatureEffect } from './data/nature'
export { getNextEvolution, EVOLUTION_CHAINS } from './data/evolution'
export { getNextEvolution } from './data/evolution'
export { getDefaultMoveset, getDefaultAbility, getNewLearnableMoves } from './data/learnsets'
export { FROM_DEX_STAT, TO_DEX_STAT } from './data/pkmn'

View File

@@ -8,6 +8,7 @@ import { calculateStats, getCreatureName, getTotalEV } from '../core/creature'
import { getXpProgress } from '../core/experience'
import { getEVSummary } from '../core/effort'
import { getGenderSymbol } from '../core/gender'
import { getStatColor } from './shared'
import { getNextEvolution } from '../data/evolution'
import { StatBar } from './StatBar'
@@ -156,15 +157,3 @@ export function CompanionCard({ creature, buddyData, spriteLines }: CompanionCar
</Box>
)
}
function getStatColor(stat: string): Color {
const colors: Record<string, Color> = {
hp: 'ansi:green',
attack: 'ansi:red',
defense: 'ansi:yellow',
spAtk: 'ansi:blue',
spDef: 'ansi:magenta',
speed: 'ansi:cyan',
}
return colors[stat] ?? 'ansi:white'
}

View File

@@ -6,6 +6,7 @@ import { getSpeciesData } from '../data/species'
import { SPECIES_PERSONALITY } from '../data/names'
import { getNextEvolution } from '../data/evolution'
import { StatBar } from './StatBar'
import { getStatColor } from './shared'
const CYAN: Color = 'ansi:cyan'
const GRAY: Color = 'ansi:white'
@@ -184,10 +185,3 @@ function isInChain(target: SpeciesId, head: SpeciesId): boolean {
return false
}
function getStatColor(stat: string): Color {
const colors: Record<string, Color> = {
hp: 'ansi:green', attack: 'ansi:red', defense: 'ansi:yellow',
spAtk: 'ansi:blue', spDef: 'ansi:magenta', speed: 'ansi:cyan',
}
return colors[stat] ?? 'ansi:white'
}

View File

@@ -0,0 +1,14 @@
import type { Color } from '@anthropic/ink'
const STAT_COLORS: Record<string, Color> = {
hp: 'ansi:green',
attack: 'ansi:red',
defense: 'ansi:yellow',
spAtk: 'ansi:blue',
spDef: 'ansi:magenta',
speed: 'ansi:cyan',
}
export function getStatColor(stat: string): Color {
return STAT_COLORS[stat] ?? 'ansi:white'
}