import BehaviorTreeStatus from "../BehaviorTreeStatus" ; import BehaviorTreeError from "../Error/BehaviorTreeError" ; import Errors from "../Error/Errors" ; import StateData from "../StateData" ; import BehaviorTreeNodeInterface from "./BehaviorTreeNodeInterface" ; import ParentBehaviorTreeNodeInterface from "./ParentBehaviorTreeNodeInterface" ; property export default class InverterNode implements ParentBehaviorTreeNodeInterface { /**
     * The child to be inverted
     */ private childNode ? : BehaviorTreeNodeInterface ; public constructor ( public readonly name ) { } public async tick ( state ) { if ( ! this . childNode ) { throw new BehaviorTreeError ( Errors . INVERTER_NO_CHILDREN ) ; } const result = await this . childNode . tick ( state ) ; if ( result === BehaviorTreeStatus . Failure ) { return BehaviorTreeStatus . Success ; } else if ( result === BehaviorTreeStatus . Success ) { return BehaviorTreeStatus . Failure ; } return result ; } public addChild ( child ) { if ( ! ! this . childNode ) { throw new BehaviorTreeError ( Errors . INVERTER_MULTIPLE_CHILDREN ) ; } this . childNode = child ; } }