import * as nodes from './nodes'
import {BaseNode, Tick, State, Tree, Blackboard} from './BaseNode'

export function buildNode(data: IDataBehaviorNode) {
    var type = data.nodeType
    var node: BaseNode = new nodes[type]()
    node.config = data.config
    if (data.children.length > 0) {
            var childNode = buildNode(data.children[0])
            node.addChild(childNode)
        } else if (node instanceof nodes.Composite) {
            for (var i = 0; i < data.children.length; i++) {
                var childNode = buildNode(data.children[i])
                node.addChild(childNode)
            }
        }
    }
    return node
}

export function registerNodeType(name: string, func: Function) {
    if (nodes[name]) throw new Error('nodeType already exist:' + name)
    nodes[name] = func
}

export {BaseNode, Tick, State, Tree, Blackboard, nodes}
        if (node instanceof nodes.Decorator) {