import BehaviorTreeStatus from "../BehaviorTreeStatus" ; import NodeEnumerator from "../NodeEnumerator" ; import StateData from "../StateData" ; import BehaviorTreeNodeInterface from "./BehaviorTreeNodeInterface" ; import ParentBehaviorTreeNodeInterface from "./ParentBehaviorTreeNodeInterface" ; property export default class SelectorNode implements ParentBehaviorTreeNodeInterface { type { BehaviorTreeNodeInterface [ ] } private children : BehaviorTreeNodeInterface [ ] = [ ] ; /**
     * Enumerator to keep state
     */ private enumerator ? : NodeEnumerator ; public constructor ( public readonly name , private readonly keepState = false ) { } public init ( ) { this . enumerator = new NodeEnumerator ( this . children ) ; } public async tick ( state ) { if ( ! this . enumerator || ! this . keepState ) { this . init ( ) ; } if ( ! this . enumerator . current ) { return BehaviorTreeStatus . Running ; } do { const status = await this . enumerator . current . tick ( state ) ; if ( status !== BehaviorTreeStatus . Failure ) { if ( status === BehaviorTreeStatus . Success ) { this . enumerator . reset ( ) ; } return status ; } } while ( this . enumerator . next ( ) ) ; this . enumerator . reset ( ) ; return BehaviorTreeStatus . Failure ; } public addChild ( child ) { this . children . push ( child ) ; } }