Add hierarchical route grouping for multi-area locations
Locations like Mt. Moon (with 1F, B1F, B2F floors) are now grouped so only one encounter can be logged per location group, enforcing Nuzlocke first-encounter rules correctly. - Add parent_route_id column with self-referential FK to routes table - Add parent/children relationships on Route model - Update games API to return hierarchical route structure - Add validation in encounters API to prevent parent route encounters and duplicate encounters within sibling routes (409 conflict) - Update frontend with collapsible RouteGroup component - Auto-derive route groups from PokeAPI location/location-area structure - Regenerate seed data with 70 parent routes and 315 child routes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -187,7 +187,11 @@ def aggregate_encounters(raw_encounters: list[dict]) -> list[dict]:
|
||||
|
||||
|
||||
def process_version(version_name: str, vg_info: dict) -> list[dict]:
|
||||
"""Process all locations for a specific game version."""
|
||||
"""Process all locations for a specific game version.
|
||||
|
||||
Creates hierarchical route structure where locations with multiple areas
|
||||
become parent routes with child routes for each area.
|
||||
"""
|
||||
print(f"\n--- Processing {version_name} ---")
|
||||
|
||||
region = load_resource("region", vg_info["region_id"])
|
||||
@@ -230,8 +234,38 @@ def process_version(version_name: str, vg_info: dict) -> list[dict]:
|
||||
else:
|
||||
all_encounters.extend(encounters)
|
||||
|
||||
# Area-specific encounters become separate routes
|
||||
if area_specific:
|
||||
# If we have multiple area-specific encounters, create a parent route
|
||||
# with child routes for each area (hierarchical grouping)
|
||||
if area_specific and len(area_specific) > 1:
|
||||
# Create parent route (no encounters - just a logical grouping)
|
||||
parent_order = order
|
||||
order += 1
|
||||
|
||||
child_routes = []
|
||||
for area_suffix, area_encs in area_specific.items():
|
||||
aggregated = aggregate_encounters(area_encs)
|
||||
if aggregated:
|
||||
route_name = f"{display_name} ({area_suffix})"
|
||||
for enc in aggregated:
|
||||
all_pokemon_dex.add(enc["national_dex"])
|
||||
child_routes.append({
|
||||
"name": route_name,
|
||||
"order": order,
|
||||
"encounters": aggregated,
|
||||
})
|
||||
order += 1
|
||||
|
||||
# Only add parent if we have child routes
|
||||
if child_routes:
|
||||
routes.append({
|
||||
"name": display_name,
|
||||
"order": parent_order,
|
||||
"encounters": [], # Parent routes have no encounters
|
||||
"children": child_routes,
|
||||
})
|
||||
|
||||
elif area_specific:
|
||||
# Only one area-specific route - don't create parent/child, just use suffix
|
||||
for area_suffix, area_encs in area_specific.items():
|
||||
aggregated = aggregate_encounters(area_encs)
|
||||
if aggregated:
|
||||
@@ -245,6 +279,7 @@ def process_version(version_name: str, vg_info: dict) -> list[dict]:
|
||||
})
|
||||
order += 1
|
||||
|
||||
# Non-area-specific encounters (or single area without suffix)
|
||||
if all_encounters:
|
||||
aggregated = aggregate_encounters(all_encounters)
|
||||
if aggregated:
|
||||
@@ -257,8 +292,13 @@ def process_version(version_name: str, vg_info: dict) -> list[dict]:
|
||||
})
|
||||
order += 1
|
||||
|
||||
print(f" Routes with encounters: {len(routes)}")
|
||||
total_enc = sum(len(r["encounters"]) for r in routes)
|
||||
# Count routes including children
|
||||
total_routes = sum(1 + len(r.get("children", [])) for r in routes)
|
||||
print(f" Routes with encounters: {total_routes}")
|
||||
total_enc = sum(
|
||||
len(r["encounters"]) + sum(len(c["encounters"]) for c in r.get("children", []))
|
||||
for r in routes
|
||||
)
|
||||
print(f" Total encounter entries: {total_enc}")
|
||||
|
||||
return routes
|
||||
|
||||
Reference in New Issue
Block a user