From 98284a59082bb35390f710293f285715c0e91fbd Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Wed, 22 Apr 2026 01:58:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=8F=90=E5=8F=96=E5=85=B1?= =?UTF-8?q?=E4=BA=AB=20getStatColor=E3=80=81=E7=A7=BB=E9=99=A4=20deprecate?= =?UTF-8?q?d=20EVOLUTION=5FCHAINS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 ui/shared.ts 统一 getStatColor 函数 - CompanionCard/SpeciesDetail 改用共享函数,消除重复 - 移除 data/evolution.ts 中已废弃的 EVOLUTION_CHAINS 常量 - 清理 index.ts 导出 Co-Authored-By: Claude Opus 4.6 --- packages/pokemon/src/data/evolution.ts | 12 ++---------- packages/pokemon/src/index.ts | 2 +- packages/pokemon/src/ui/CompanionCard.tsx | 13 +------------ packages/pokemon/src/ui/SpeciesDetail.tsx | 8 +------- packages/pokemon/src/ui/shared.ts | 14 ++++++++++++++ 5 files changed, 19 insertions(+), 30 deletions(-) create mode 100644 packages/pokemon/src/ui/shared.ts diff --git a/packages/pokemon/src/data/evolution.ts b/packages/pokemon/src/data/evolution.ts index 6da728a61..754f0e0a6 100644 --- a/packages/pokemon/src/data/evolution.ts +++ b/packages/pokemon/src/data/evolution.ts @@ -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 -})() diff --git a/packages/pokemon/src/index.ts b/packages/pokemon/src/index.ts index 4debb21e0..6ee0e7f6c 100644 --- a/packages/pokemon/src/index.ts +++ b/packages/pokemon/src/index.ts @@ -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' diff --git a/packages/pokemon/src/ui/CompanionCard.tsx b/packages/pokemon/src/ui/CompanionCard.tsx index cc1e02453..d37a7b840 100644 --- a/packages/pokemon/src/ui/CompanionCard.tsx +++ b/packages/pokemon/src/ui/CompanionCard.tsx @@ -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 ) } - -function getStatColor(stat: string): Color { - const colors: Record = { - hp: 'ansi:green', - attack: 'ansi:red', - defense: 'ansi:yellow', - spAtk: 'ansi:blue', - spDef: 'ansi:magenta', - speed: 'ansi:cyan', - } - return colors[stat] ?? 'ansi:white' -} diff --git a/packages/pokemon/src/ui/SpeciesDetail.tsx b/packages/pokemon/src/ui/SpeciesDetail.tsx index a05022884..9fe158c72 100644 --- a/packages/pokemon/src/ui/SpeciesDetail.tsx +++ b/packages/pokemon/src/ui/SpeciesDetail.tsx @@ -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 = { - hp: 'ansi:green', attack: 'ansi:red', defense: 'ansi:yellow', - spAtk: 'ansi:blue', spDef: 'ansi:magenta', speed: 'ansi:cyan', - } - return colors[stat] ?? 'ansi:white' -} diff --git a/packages/pokemon/src/ui/shared.ts b/packages/pokemon/src/ui/shared.ts new file mode 100644 index 000000000..a20803cab --- /dev/null +++ b/packages/pokemon/src/ui/shared.ts @@ -0,0 +1,14 @@ +import type { Color } from '@anthropic/ink' + +const STAT_COLORS: Record = { + 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' +}