import { ChoiceNode, ChoiceOption } from '../../../types/dialogue'; import { useDialogueStore } from '../../../store/dialogueStore'; import { SpeakerField } from '../shared/SpeakerField'; import { useValidation } from '../../../hooks/useValidation'; import styles from '../RightPanel.module.css'; interface Props { node: ChoiceNode; dialogueId: string; } export function ChoiceInspector({ node, dialogueId }: Props) { const { updateNode, deleteNode, file } = useDialogueStore(); const { issuesByNodeId } = useValidation(); const issues = issuesByNodeId[node.id] ?? []; const dialogue = file?.dialogues.find(d => d.id === dialogueId); const nodeIds = dialogue?.nodes.map(n => n.id) ?? []; function updateChoice(idx: number, patch: Partial) { const choices = node.choices.map((c, i) => i === idx ? { ...c, ...patch } : c); updateNode(dialogueId, node.id, { choices }); } function addChoice() { const newId = `choice_${Date.now()}`; const choices: ChoiceOption[] = [...node.choices, { id: newId, kind: 'Optional', text: '', next: '' }]; updateNode(dialogueId, node.id, { choices }); } function removeChoice(idx: number) { const choices = node.choices.filter((_, i) => i !== idx); updateNode(dialogueId, node.id, { choices }); } return (
Choice {node.id}
{issues.length > 0 && (
{issues.map((issue, i) => (
{issue.severity === 'error' ? 'âš ' : '!'} {issue.message}
))}
)}
updateNode(dialogueId, node.id, { speaker: s, portrait: p })} />
Choices
{node.choices.map((choice, idx) => (
#{idx + 1}
updateChoice(idx, { text: e.target.value })} /> updateChoice(idx, { next: e.target.value })} list={`nodelist-choice-${choice.id}`} /> {nodeIds.map(id =>
))} {node.choices.length === 0 && (
No choices yet. Click "+ Add".
)}
); }