import { Behavior } from "../../../intelligence/behavior/Behavior.js";
import { BehaviorStatus } from "../../../intelligence/behavior/BehaviorStatus.js";

export class AnimationBehavior extends Behavior {
    /**
     *
     * @param {AnimationTrackPlayback} animation
     */
    constructor(animation) {
        super();
        /**
         *
         * @type {AnimationTrackPlayback}
         */
        this.animation = animation;
    }


    /**
     *
     * @param {number} timeDelta
     * @returns {BehaviorStatus}
     */
    tick(timeDelta) {
        const animation = this.animation;

        animation.advance(timeDelta);

        if (animation.position >= animation.track.timeEnd && !animation.loop) {
            return BehaviorStatus.Succeeded;
        }

        return BehaviorStatus.Running;
    }

    initialize(_ignore_) {
        this.animation.setPosition(this.animation.track.timeStart);
    }
}
