diff --git a/src/components/nodes/VariablesNode.tsx b/src/components/nodes/VariablesNode.tsx new file mode 100644 index 0000000..a13f2c0 --- /dev/null +++ b/src/components/nodes/VariablesNode.tsx @@ -0,0 +1,211 @@ +import { memo, useState } from 'react'; +import { Handle, Position } from '@xyflow/react'; +import type { NodeProps } from '@xyflow/react'; +import { Code, Plus, Trash2, ChevronDown, ChevronUp } from 'lucide-react'; +import type { VariablesNodeData } from '../../types/nodes'; +import type { MoLangConfigVariable } from '../../types/npc'; + +export const VariablesNode = memo(({ data }: NodeProps) => { + const [isExpanded, setIsExpanded] = useState(true); + const nodeData = data as VariablesNodeData; + + const handleChange = (variables: MoLangConfigVariable[]) => { + Object.assign(nodeData, { configVariables: variables }); + }; + + const addVariable = () => { + const newVariable: MoLangConfigVariable = { + variableName: `var_${Date.now()}`, + displayName: 'New Variable', + description: 'Description', + type: 'NUMBER', + defaultValue: 0, + }; + handleChange([...(nodeData.configVariables || []), newVariable]); + }; + + const removeVariable = (index: number) => { + const newVariables = [...(nodeData.configVariables || [])]; + newVariables.splice(index, 1); + handleChange(newVariables); + }; + + const updateVariable = ( + index: number, + field: keyof MoLangConfigVariable, + value: string | number | boolean + ) => { + const newVariables = [...(nodeData.configVariables || [])]; + newVariables[index] = { ...newVariables[index], [field]: value }; + handleChange(newVariables); + }; + + return ( +
+ Config Variables
+