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 */
|
/** Group species by evolution chain for visual display */
|
||||||
function groupByChain(): SpeciesId[][] {
|
function groupByChain(): SpeciesId[][] {
|
||||||
return [
|
const visited = new Set<SpeciesId>()
|
||||||
['bulbasaur', 'ivysaur', 'venusaur'],
|
const chains: SpeciesId[][] = []
|
||||||
['charmander', 'charmeleon', 'charizard'],
|
|
||||||
['squirtle', 'wartortle', 'blastoise'],
|
for (const id of ALL_SPECIES_IDS) {
|
||||||
['pikachu'],
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Box, Text, type Color } from '@anthropic/ink'
|
import { Box, Text, type Color } from '@anthropic/ink'
|
||||||
import type { SpeciesId, StatName } from '../types'
|
import type { SpeciesId, StatName } from '../types'
|
||||||
import { STAT_NAMES, STAT_LABELS } from '../types'
|
import { STAT_NAMES, STAT_LABELS, ALL_SPECIES_IDS } from '../types'
|
||||||
import { getSpeciesData } from '../data/species'
|
import { getSpeciesData } from '../data/species'
|
||||||
import { getNextEvolution } from '../data/evolution'
|
import { getNextEvolution } from '../data/evolution'
|
||||||
import { StatBar } from './StatBar'
|
import { StatBar } from './StatBar'
|
||||||
@@ -135,12 +135,12 @@ export function SpeciesDetail({ speciesId, caughtLevel, spriteLines }: SpeciesDe
|
|||||||
|
|
||||||
/** Render evolution chain arrow */
|
/** Render evolution chain arrow */
|
||||||
function EvolutionChain({ speciesId }: { speciesId: SpeciesId }) {
|
function EvolutionChain({ speciesId }: { speciesId: SpeciesId }) {
|
||||||
// Find the chain head
|
// Walk back to find chain head
|
||||||
const chainHeads: SpeciesId[] = ['bulbasaur', 'charmander', 'squirtle', 'pikachu']
|
|
||||||
let head: SpeciesId = speciesId
|
let head: SpeciesId = speciesId
|
||||||
for (const starter of chainHeads) {
|
for (const candidate of ALL_SPECIES_IDS) {
|
||||||
if (isInChain(speciesId, starter)) {
|
const evo = getNextEvolution(candidate)
|
||||||
head = starter
|
if (evo?.to === head) {
|
||||||
|
head = candidate
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,13 +174,3 @@ function EvolutionChain({ speciesId }: { speciesId: SpeciesId }) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isInChain(target: SpeciesId, head: SpeciesId): boolean {
|
|
||||||
let current: SpeciesId | undefined = head
|
|
||||||
while (current) {
|
|
||||||
if (current === target) return true
|
|
||||||
const next = getNextEvolution(current)
|
|
||||||
current = next ? next.to : undefined
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user