Add version groups to share routes and boss battles across games

Routes and boss battles now belong to a version_group instead of
individual games, so paired versions (e.g. Red/Blue, Gold/Silver)
share the same route structure and boss battles. Route encounters
gain a game_id column to support game-specific encounter tables
within a shared route. Includes migration, updated seeds, API
changes, and frontend type updates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-08 12:07:42 +01:00
parent 979f57f184
commit 3e88ba50fa
22 changed files with 631 additions and 161 deletions

View File

@@ -19,6 +19,7 @@ export function getGameRoutes(gameId: number): Promise<Route[]> {
return api.get(`/games/${gameId}/routes?flat=true`)
}
export function getRoutePokemon(routeId: number): Promise<RouteEncounterDetail[]> {
return api.get(`/routes/${routeId}/pokemon`)
export function getRoutePokemon(routeId: number, gameId?: number): Promise<RouteEncounterDetail[]> {
const params = gameId != null ? `?game_id=${gameId}` : ''
return api.get(`/routes/${routeId}/pokemon${params}`)
}

View File

@@ -23,10 +23,10 @@ export function useGameRoutes(gameId: number | null) {
})
}
export function useRoutePokemon(routeId: number | null) {
export function useRoutePokemon(routeId: number | null, gameId?: number) {
return useQuery({
queryKey: ['routes', routeId, 'pokemon'],
queryFn: () => getRoutePokemon(routeId!),
queryKey: ['routes', routeId, 'pokemon', gameId],
queryFn: () => getRoutePokemon(routeId!, gameId),
enabled: routeId !== null,
})
}

View File

@@ -1093,9 +1093,9 @@ export function RunEncounters() {
.map((bp) => (
<div key={bp.id} className="flex items-center gap-1">
{bp.pokemon.spriteUrl ? (
<img src={bp.pokemon.spriteUrl} alt={bp.pokemon.name} className="w-10 h-10" />
<img src={bp.pokemon.spriteUrl} alt={bp.pokemon.name} className="w-20 h-20" />
) : (
<div className="w-10 h-10 bg-gray-200 dark:bg-gray-700 rounded-full" />
<div className="w-20 h-20 bg-gray-200 dark:bg-gray-700 rounded-full" />
)}
<span className="text-xs text-gray-500 dark:text-gray-400">
Lvl {bp.level}

View File

@@ -21,7 +21,7 @@ export function AdminRouteDetail() {
const rId = Number(routeId)
const { data: game } = useGame(gId)
const { data: encounters = [], isLoading } = useRoutePokemon(rId)
const { data: encounters = [], isLoading } = useRoutePokemon(rId, gId)
const addEncounter = useAddRouteEncounter(rId)
const updateEncounter = useUpdateRouteEncounter(rId)
@@ -114,7 +114,7 @@ export function AdminRouteDetail() {
{showCreate && (
<RouteEncounterFormModal
onSubmit={(data) =>
addEncounter.mutate(data as CreateRouteEncounterInput, {
addEncounter.mutate({ ...data, gameId: gId } as CreateRouteEncounterInput, {
onSuccess: () => setShowCreate(false),
})
}

View File

@@ -64,6 +64,7 @@ export interface PaginatedPokemon {
export interface CreateRouteEncounterInput {
pokemonId: number
gameId: number
encounterMethod: string
encounterRate: number
minLevel: number

View File

@@ -7,12 +7,13 @@ export interface Game {
boxArtUrl: string | null
releaseYear: number | null
color: string | null
versionGroupId: number | null
}
export interface Route {
id: number
name: string
gameId: number
versionGroupId: number
order: number
parentRouteId: number | null
pinwheelZone: number | null
@@ -36,6 +37,7 @@ export interface RouteEncounter {
id: number
routeId: number
pokemonId: number
gameId: number
encounterMethod: string
encounterRate: number
minLevel: number
@@ -140,7 +142,7 @@ export interface BossPokemon {
export interface BossBattle {
id: number
gameId: number
versionGroupId: number
name: string
bossType: BossType
badgeName: string | null