Add naming scheme support for genlockes with lineage-aware suggestions (#20)
Genlockes can now select a naming scheme at creation time, which is automatically applied to every leg's run. When catching a pokemon whose evolution family appeared in a previous leg, the system suggests the original nickname with a roman numeral suffix (e.g., "Heracles II"). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Reviewed-on: TheFurya/nuzlocke-tracker#20 Co-authored-by: Julian Tabel <juliantabel.jt@gmail.com> Co-committed-by: Julian Tabel <juliantabel.jt@gmail.com>
This commit was merged in pull request #20.
This commit is contained in:
@@ -33,6 +33,10 @@ export function getNamingCategories(): Promise<string[]> {
|
||||
return api.get('/runs/naming-categories')
|
||||
}
|
||||
|
||||
export function getNameSuggestions(runId: number, count = 10): Promise<string[]> {
|
||||
return api.get(`/runs/${runId}/name-suggestions?count=${count}`)
|
||||
export function getNameSuggestions(runId: number, count = 10, pokemonId?: number): Promise<string[]> {
|
||||
let url = `/runs/${runId}/name-suggestions?count=${count}`
|
||||
if (pokemonId != null) {
|
||||
url += `&pokemon_id=${pokemonId}`
|
||||
}
|
||||
return api.get(url)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ interface EncounterModalProps {
|
||||
gameId: number
|
||||
runId: number
|
||||
namingScheme?: string | null
|
||||
isGenlocke?: boolean
|
||||
existing?: EncounterDetail
|
||||
dupedPokemonIds?: Set<number>
|
||||
retiredPokemonIds?: Set<number>
|
||||
@@ -97,6 +98,7 @@ export function EncounterModal({
|
||||
gameId,
|
||||
runId,
|
||||
namingScheme,
|
||||
isGenlocke,
|
||||
existing,
|
||||
dupedPokemonIds,
|
||||
retiredPokemonIds,
|
||||
@@ -126,8 +128,9 @@ export function EncounterModal({
|
||||
const isEditing = !!existing
|
||||
|
||||
const showSuggestions = !!namingScheme && status === 'caught' && !isEditing
|
||||
const lineagePokemonId = isGenlocke && selectedPokemon ? selectedPokemon.pokemonId : null
|
||||
const { data: suggestions, refetch: regenerate, isFetching: loadingSuggestions } =
|
||||
useNameSuggestions(showSuggestions ? runId : null)
|
||||
useNameSuggestions(showSuggestions ? runId : null, lineagePokemonId)
|
||||
|
||||
// Pre-select pokemon when editing
|
||||
useEffect(() => {
|
||||
|
||||
@@ -60,10 +60,10 @@ export function useNamingCategories() {
|
||||
})
|
||||
}
|
||||
|
||||
export function useNameSuggestions(runId: number | null) {
|
||||
export function useNameSuggestions(runId: number | null, pokemonId?: number | null) {
|
||||
return useQuery({
|
||||
queryKey: ['name-suggestions', runId],
|
||||
queryFn: () => getNameSuggestions(runId!),
|
||||
queryKey: ['name-suggestions', runId, pokemonId ?? null],
|
||||
queryFn: () => getNameSuggestions(runId!, 10, pokemonId ?? undefined),
|
||||
enabled: runId !== null,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { RulesConfiguration, StepIndicator } from '../components'
|
||||
import { useRegions, useCreateGenlocke } from '../hooks/useGenlockes'
|
||||
import { useNamingCategories } from '../hooks/useRuns'
|
||||
import type { Game, GenlockeRules, Region } from '../types'
|
||||
import { DEFAULT_RULES } from '../types'
|
||||
import type { NuzlockeRules } from '../types/rules'
|
||||
@@ -46,6 +47,8 @@ export function NewGenlocke() {
|
||||
const [preset, setPreset] = useState<PresetType>(null)
|
||||
const [nuzlockeRules, setNuzlockeRules] = useState<NuzlockeRules>(DEFAULT_RULES)
|
||||
const [genlockeRules, setGenlockeRules] = useState<GenlockeRules>({ retireHoF: false })
|
||||
const [namingScheme, setNamingScheme] = useState<string | null>(null)
|
||||
const { data: namingCategories } = useNamingCategories()
|
||||
|
||||
const handlePresetSelect = (type: PresetType) => {
|
||||
setPreset(type)
|
||||
@@ -91,6 +94,7 @@ export function NewGenlocke() {
|
||||
gameIds: legs.map((l) => l.game.id),
|
||||
genlockeRules,
|
||||
nuzlockeRules,
|
||||
namingScheme,
|
||||
},
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
@@ -323,6 +327,32 @@ export function NewGenlocke() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Naming scheme */}
|
||||
<div className="mt-6 bg-white dark:bg-gray-800 rounded-lg shadow">
|
||||
<div className="px-4 py-3 border-b border-gray-200 dark:border-gray-700">
|
||||
<h3 className="text-lg font-medium text-gray-900 dark:text-gray-100">
|
||||
Naming Scheme
|
||||
</h3>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||
Get nickname suggestions from a themed word list when catching Pokemon. Applied to all legs.
|
||||
</p>
|
||||
</div>
|
||||
<div className="px-4 py-4">
|
||||
<select
|
||||
value={namingScheme ?? ''}
|
||||
onChange={(e) => setNamingScheme(e.target.value || null)}
|
||||
className="w-full max-w-xs px-3 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
<option value="">None (manual nicknames)</option>
|
||||
{namingCategories?.map((cat) => (
|
||||
<option key={cat} value={cat}>
|
||||
{cat.charAt(0).toUpperCase() + cat.slice(1)}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-6 flex justify-between">
|
||||
<button
|
||||
type="button"
|
||||
@@ -398,6 +428,14 @@ export function NewGenlocke() {
|
||||
{genlockeRules.retireHoF ? 'Retire' : 'Keep'}
|
||||
</dd>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<dt className="text-gray-600 dark:text-gray-400">Naming Scheme</dt>
|
||||
<dd className="text-gray-900 dark:text-gray-100 font-medium">
|
||||
{namingScheme
|
||||
? namingScheme.charAt(0).toUpperCase() + namingScheme.slice(1)
|
||||
: 'None'}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1437,6 +1437,7 @@ export function RunEncounters() {
|
||||
gameId={run!.gameId}
|
||||
runId={runIdNum}
|
||||
namingScheme={run!.namingScheme}
|
||||
isGenlocke={!!run!.genlocke}
|
||||
existing={editingEncounter ?? undefined}
|
||||
dupedPokemonIds={dupedPokemonIds}
|
||||
retiredPokemonIds={retiredPokemonIds}
|
||||
|
||||
@@ -230,6 +230,7 @@ export interface Genlocke {
|
||||
status: 'active' | 'completed' | 'failed'
|
||||
genlockeRules: GenlockeRules
|
||||
nuzlockeRules: NuzlockeRules
|
||||
namingScheme: string | null
|
||||
createdAt: string
|
||||
legs: GenlockeLeg[]
|
||||
}
|
||||
@@ -239,6 +240,7 @@ export interface CreateGenlockeInput {
|
||||
gameIds: number[]
|
||||
genlockeRules: GenlockeRules
|
||||
nuzlockeRules: NuzlockeRules
|
||||
namingScheme?: string | null
|
||||
}
|
||||
|
||||
// Genlocke list / detail types
|
||||
@@ -283,6 +285,7 @@ export interface GenlockeDetail {
|
||||
status: 'active' | 'completed' | 'failed'
|
||||
genlockeRules: GenlockeRules
|
||||
nuzlockeRules: NuzlockeRules
|
||||
namingScheme: string | null
|
||||
createdAt: string
|
||||
legs: GenlockeLegDetail[]
|
||||
stats: GenlockeStats
|
||||
|
||||
Reference in New Issue
Block a user