import {resolveEasing} from "../vfx-utils.mjs";

const vfxFollowPathAnimation = {
  setup: (state, params) => {
    state.lastPathIndex = 0;
    params.ease = resolveEasing(params.easing ?? "linear", params.easingParams);
  },
  animate: (t, state, params) => {
    const target = params.target || state.projectile?.container;
    if (!target) return;
    const w = params.ease(t);
    const point = state.flightPath.interpolatedPoint(w, state.lastPathIndex);
    state.lastPathIndex = point.index;
    target.x = point.x;
    target.y = point.y;
    target.rotation = point.rotation;
    target.elevation = point.elevation;
    target.sort = point.sort;
    target.sprites.mesh.anchor.x = Math.mix(1.25, 0.5, w);
  }
};

export default vfxFollowPathAnimation;
