import { clamp01 } from "../../../core/math/clamp01.js";
import { makeCubicCurve } from "../../../core/math/spline/makeCubicCurve.js";
import { Behavior } from "../../intelligence/behavior/Behavior.js";
import { BehaviorStatus } from "../../intelligence/behavior/BehaviorStatus.js";

export class CameraShakeTraumaBehavior extends Behavior {

    /**
     *
     * @param {CameraShakeBehavior} shakeBehavior
     * @param {number} decay amount by which trauma decays per second
     */
    constructor({
                    shakeBehavior,
                    decay = 1,
                }) {
        super();


        this.decay = decay;
        this.trauma = 0;

        this.shakeBehavior = shakeBehavior;

        this.formula = makeCubicCurve(0, 0.1, 0.1, 1);
    }

    tick(timeDelta) {
        const shake = this.formula(clamp01(this.trauma));

        this.trauma = clamp01(this.trauma - timeDelta * this.decay);


        this.shakeBehavior.strength = shake;

        return BehaviorStatus.Running;
    }
}