Hide Pinwheel Clause rule toggle for games without pinwheel zones

Fetches routes for the selected game during run creation and hides
the Pinwheel Clause option when no routes have pinwheel zone data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-08 10:40:18 +01:00
parent d50d189114
commit 8fbf658a27
3 changed files with 31 additions and 11 deletions

View File

@@ -1,10 +1,11 @@
--- ---
# nuzlocke-tracker-v04g # nuzlocke-tracker-v04g
title: Hide Pinwheel Clause when game has no pinwheel zones title: Hide Pinwheel Clause when game has no pinwheel zones
status: todo status: completed
type: bug type: bug
priority: normal
created_at: 2026-02-07T21:08:27Z created_at: 2026-02-07T21:08:27Z
updated_at: 2026-02-07T21:08:27Z updated_at: 2026-02-08T09:37:48Z
--- ---
The Pinwheel Clause rule option is currently shown for all games, even those that have no locations using pinwheel zones (i.e. no routes with pinwheel_zone IDs). It should only be displayed when the selected game actually has routes with pinwheel zone data. The Pinwheel Clause rule option is currently shown for all games, even those that have no locations using pinwheel zones (i.e. no routes with pinwheel_zone IDs). It should only be displayed when the selected game actually has routes with pinwheel zone data.

View File

@@ -6,15 +6,20 @@ interface RulesConfigurationProps {
rules: NuzlockeRules rules: NuzlockeRules
onChange: (rules: NuzlockeRules) => void onChange: (rules: NuzlockeRules) => void
onReset?: () => void onReset?: () => void
hiddenRules?: Set<keyof NuzlockeRules>
} }
export function RulesConfiguration({ export function RulesConfiguration({
rules, rules,
onChange, onChange,
onReset, onReset,
hiddenRules,
}: RulesConfigurationProps) { }: RulesConfigurationProps) {
const coreRules = RULE_DEFINITIONS.filter((r) => r.category === 'core') const visibleRules = hiddenRules
const difficultyRules = RULE_DEFINITIONS.filter( ? RULE_DEFINITIONS.filter((r) => !hiddenRules.has(r.key))
: RULE_DEFINITIONS
const coreRules = visibleRules.filter((r) => r.category === 'core')
const difficultyRules = visibleRules.filter(
(r) => r.category === 'difficulty' (r) => r.category === 'difficulty'
) )
@@ -27,8 +32,8 @@ export function RulesConfiguration({
onReset?.() onReset?.()
} }
const enabledCount = Object.values(rules).filter(Boolean).length const enabledCount = visibleRules.filter((r) => rules[r.key]).length
const totalCount = Object.keys(rules).length const totalCount = visibleRules.length
return ( return (
<div className="space-y-6"> <div className="space-y-6">

View File

@@ -1,10 +1,11 @@
import { useState } from 'react' import { useMemo, useState } from 'react'
import { useNavigate } from 'react-router-dom' import { useNavigate } from 'react-router-dom'
import { GameGrid, RulesConfiguration, StepIndicator } from '../components' import { GameGrid, RulesConfiguration, StepIndicator } from '../components'
import { useGames } from '../hooks/useGames' import { useGames, useGameRoutes } from '../hooks/useGames'
import { useCreateRun, useRuns } from '../hooks/useRuns' import { useCreateRun, useRuns } from '../hooks/useRuns'
import type { Game, NuzlockeRules } from '../types' import type { Game, NuzlockeRules } from '../types'
import { DEFAULT_RULES } from '../types' import { DEFAULT_RULES } from '../types'
import { RULE_DEFINITIONS } from '../types/rules'
const DEFAULT_COLOR = '#6366f1' const DEFAULT_COLOR = '#6366f1'
@@ -18,6 +19,16 @@ export function NewRun() {
const [selectedGame, setSelectedGame] = useState<Game | null>(null) const [selectedGame, setSelectedGame] = useState<Game | null>(null)
const [rules, setRules] = useState<NuzlockeRules>(DEFAULT_RULES) const [rules, setRules] = useState<NuzlockeRules>(DEFAULT_RULES)
const [runName, setRunName] = useState('') const [runName, setRunName] = useState('')
const { data: routes } = useGameRoutes(selectedGame?.id ?? null)
const hiddenRules = useMemo(() => {
const hidden = new Set<keyof NuzlockeRules>()
const hasPinwheelZones = routes?.some((r) => r.pinwheelZone != null)
if (!hasPinwheelZones) {
hidden.add('pinwheelClause')
}
return hidden.size > 0 ? hidden : undefined
}, [routes])
const handleGameSelect = (game: Game) => { const handleGameSelect = (game: Game) => {
if (selectedGame?.id === game.id) { if (selectedGame?.id === game.id) {
@@ -38,8 +49,11 @@ export function NewRun() {
) )
} }
const enabledRuleCount = Object.values(rules).filter(Boolean).length const visibleRuleKeys = RULE_DEFINITIONS
const totalRuleCount = Object.keys(rules).length .filter((r) => !hiddenRules?.has(r.key))
.map((r) => r.key)
const enabledRuleCount = visibleRuleKeys.filter((k) => rules[k]).length
const totalRuleCount = visibleRuleKeys.length
return ( return (
<div className="max-w-4xl mx-auto p-8"> <div className="max-w-4xl mx-auto p-8">
@@ -121,7 +135,7 @@ export function NewRun() {
{step === 2 && ( {step === 2 && (
<div> <div>
<RulesConfiguration rules={rules} onChange={setRules} /> <RulesConfiguration rules={rules} onChange={setRules} hiddenRules={hiddenRules} />
<div className="mt-6 flex justify-between"> <div className="mt-6 flex justify-between">
<button <button