mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 08:45:50 +00:00
refactor: 进化链动态生成替代硬编码
- PokedexView.tsx: groupByChain() 改用 ALL_SPECIES_IDS + getNextEvolution 动态构建 - SpeciesDetail.tsx: EvolutionChain 用相同方式找链头 - 删除未使用的 isInChain 函数 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -154,10 +154,33 @@ function getTypeColor(type: string): Color {
|
||||
|
||||
/** Group species by evolution chain for visual display */
|
||||
function groupByChain(): SpeciesId[][] {
|
||||
return [
|
||||
['bulbasaur', 'ivysaur', 'venusaur'],
|
||||
['charmander', 'charmeleon', 'charizard'],
|
||||
['squirtle', 'wartortle', 'blastoise'],
|
||||
['pikachu'],
|
||||
]
|
||||
const visited = new Set<SpeciesId>()
|
||||
const chains: SpeciesId[][] = []
|
||||
|
||||
for (const id of ALL_SPECIES_IDS) {
|
||||
if (visited.has(id)) continue
|
||||
|
||||
// Walk back to find chain head
|
||||
let head: SpeciesId = id
|
||||
for (const candidate of ALL_SPECIES_IDS) {
|
||||
const evo = getNextEvolution(candidate)
|
||||
if (evo?.to === head) {
|
||||
head = candidate
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Walk forward to build chain
|
||||
const chain: SpeciesId[] = []
|
||||
let current: SpeciesId | undefined = head
|
||||
while (current && !visited.has(current)) {
|
||||
chain.push(current)
|
||||
visited.add(current)
|
||||
current = getNextEvolution(current)?.to
|
||||
}
|
||||
|
||||
if (chain.length > 0) chains.push(chain)
|
||||
}
|
||||
|
||||
return chains
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user