import {useEffect, useRef, useState} from 'react'; import {postExpand} from './api.ts'; import {DistInput} from './DistInput.tsx'; import {observerBodies, unimplementedMotion, QUOTA_FIELDS, changeQuotaType, setOptional, batchTotal, castKinds, configRow, label, unfilledHints, setSceneCount} from './np-batch.ts'; import type {BatchSettings, Dist, ExpandedConfig, ExpandResult, GenSchema, Group, Quota} from './np-batch.ts'; import './batch.css'; // 不填就按生成器默认;填了才写进配置 function OptionalDist({name, value, onChange, kind = 'number', options, initial = 0.5}: {name: string; value: Dist | undefined; onChange: (value: Dist | undefined) => void; kind?: 'number' | 'enum'; options?: string[]; initial?: Dist}) { return
{name}{value === undefined ? <>按生成器默认 : <> }
; } function QuotaDetails({schema, quota, onChange}: {schema: GenSchema; quota: Quota; onChange: (quota: Quota) => void}) { const num = (key: 'dwell_s', step: string) => ; const fields = schema.arrangement_fields[quota.type] || {}; const invalid = Object.entries(quota).filter(([key, value]) => { if (['type', 'count', 'strength', 'when', 'decoy'].includes(key)) return false; const field = fields[key]; return !field || (field.type === 'enum' && !field.values!.includes(String(value))) || (field.type === 'fixed' && value !== field.value); }); const when = Array.isArray(quota.when) ? quota.when : null; const setWhen = (i: 0 | 1, value: number) => onChange({...quota, when: (i ? [when![0], value] : [value, when![1]]) as [number, number]}); return
{Object.keys(quota).filter(k => !['type', 'count', 'strength'].includes(k)).map(label).join('、') || '按默认'} {!schema.arrangements[quota.type] &&

type: {quota.type} 不可用

} {invalid.map(([key, value]) =>

{key}: {JSON.stringify(value)} 不符合当前安排约束

)} {(QUOTA_FIELDS[quota.type] || []).map(key => {const field = fields[key]; return key === 'where' ? : field?.type === 'enum' ? : field?.type === 'fixed' ? {label(key)}:{field.value} : num(key as 'dwell_s', 'any');})} {when && <>从 setWhen(0, Number(e.target.value))}/> 到 setWhen(1, Number(e.target.value))}/> s}
; } export function BatchDesigner({schema, batch, onChange, segmentsNeeded, onSelect}: { schema: GenSchema; batch: BatchSettings; onChange: (batch: BatchSettings) => void; segmentsNeeded: number | null; onSelect?: (row: ExpandedConfig | null) => void; }) { const [result, setResult] = useState<{value: ExpandResult; settings: string} | null>(null); const [selected, setSelected] = useState(null), [busy, setBusy] = useState(false), [error, setError] = useState(''); const request = useRef(null); useEffect(() => () => request.current?.abort(), []); const total = batchTotal(batch), fingerprint = JSON.stringify(batch), stale = !!result && result.settings !== fingerprint; function groupChange(index: number, group: Group) { onChange({...batch, template: {groups: batch.template.groups.map((old, i) => i === index ? group : old)}}); } async function expand() { if (request.current) return; const controller = new AbortController(); request.current = controller; setBusy(true); setError(''); setSelected(null); onSelect?.(null); try { const value = await postExpand(batch, controller.signal); if (!controller.signal.aborted) setResult({value, settings: fingerprint}); } catch (e) {if (!controller.signal.aborted) setError(e instanceof Error ? e.message : String(e));} finally {if (!controller.signal.aborted) {setBusy(false); request.current = null;}} } function download() { const url = URL.createObjectURL(new Blob([JSON.stringify(batch, null, 2) + '\n'], {type: 'application/json'})); const link = document.createElement('a'); link.href = url; link.download = 'batch-settings.json'; link.click(); URL.revokeObjectURL(url); } const kinds = castKinds(schema); return

这批共 {total} 段(各场景段数 × 组数){segmentsNeeded !== null && <> · 题目配额估算需 {segmentsNeeded} 段{total < segmentsNeeded && · 段数不够}}

生成器版本 {schema.generator_revision}
{batch.scenes.map(scene => )}
场景段数
场景每组段数
{scene.scene} onChange(setSceneCount(batch, scene.scene, Number(e.target.value)))}/>
{!batch.scenes.length &&

请在上面的场景卡中选择场景。

} {batch.template.groups.map((group, index) =>
组 {index + 1}
{label('duration')} groupChange(index, {...group, duration})}/>
{label('cast_mix')}{kinds.map(kind =>
{label(kind)} groupChange(index, {...group, cast_mix: {...group.cast_mix, [kind]: value}})}/>
)}
{label('profile_mix')}{kinds.map(kind => { const scriptKind = String(schema.bodies[kind]?.script_kind ?? kind); const value = group.profile_mix?.[kind] ?? schema.default_profile[scriptKind]; return
{label(kind)}{value === undefined &&

按生成器默认

} groupChange(index, {...group, profile_mix: {...group.profile_mix, [kind]: profile}})}/>
; })}
{label('observer_mix')}
数量 groupChange(index, {...group, observer_mix: {...group.observer_mix, count}})}/>
种类 groupChange(index, {...group, observer_mix: setOptional({...group.observer_mix, kind}, 'body', undefined)})}/>
移动方式 groupChange(index, {...group, observer_mix: {...group.observer_mix, motion_mode}})}/>
视角{group.observer_mix.view === undefined &&

按种类默认(实体朝前进方向,虚拟自动)

} groupChange(index, {...group, observer_mix: {...group.observer_mix, view}})}/>
{(() => {const om = group.observer_mix, bodies = observerBodies(schema, om.kind), set = (key: K, value: (typeof om)[K] | undefined) => groupChange(index, {...group, observer_mix: setOptional(om, key, value)}); return <> set('body', v)}/> set('profile', v)}/> set('eye_height_m', v)}/>
{label('calibration')}
;})()}
{label('flavor_mix')} !schema.implemented_flavors.includes(f))} value={group.flavor_mix} onChange={flavor_mix => groupChange(index, {...group, flavor_mix})}/>
{label('recording')}{schema.recording_keys.map(key => {const recording = setOptional(group.recording || {}, key, value); groupChange(index, setOptional(group, 'recording', Object.keys(recording).length ? recording : undefined));}}/>)}
{label('arrangement_quota')}

同类外观可区分:生成器保证,不用安排——同类主体的公开外观各不相同(gen/appearance.py require_unique_bodies)。

{group.arrangement_quota.map((arr, ai) => { const update = (next: typeof arr) => groupChange(index, {...group, arrangement_quota: group.arrangement_quota.map((old, i) => ai === i ? next : old)}); return ; })}
类型次数强度细节操作
update({...arr, count})}/>
)}
{total > 500 &&

每批最多展开 500 段,请减少段数。

} {error &&

{error}

} {result && <>

{stale ? '设定已改,重新展开' : `已展开 ${result.value.count} 段`} · 生成器版本 {result.value.generator_revision}

{['#', '场景', '时长', '主体', '观察者', '情形安排', '问题'].map(title => )}{result.value.configs.map((entry, i) => { const row = configRow(entry.config); return {if (!stale) {setSelected(i); onSelect?.(entry);}}}>; })}
{title}
{row.scene}{row.duration} s{row.cast}{row.observers}{row.arrangements}{entry.errors.join(';') || (unfilledHints(entry.config).length ? '' : '无')}{unfilledHints(entry.config).map((h, j) => {h.text})}
}
; }