import { frameDataMap, cineRuntimeDataMap } from "../data/maps";
import { spawnFrameEntity } from "./entity/spawn-frame-entity";
import { refreshAllFrameEntities } from "./entity/refresh-all-frame-entities";
import { cinematicFramesDB } from "../cinematic";
import { clearOtherFrameEntities } from "./entity/clear-other-frame-entities";
import { notifyPlayer } from "./helpers/notify-player";
export function addCameraFrame(player, cinematicType) {
    const cineRuntimeData = cineRuntimeDataMap.get(player.id);
    if (cineRuntimeData?.isCameraInMotion) {
        notifyPlayer(player, "rc2.mes.cannot.add.frames.while.camera.is.in.motion", "note.bass");
        return;
    }
    refreshAllFrameEntities(player, cinematicType);
    const pos = player.getHeadLocation();
    const rot = player.getRotation();
    const frames = frameDataMap.get(cineRuntimeData.loadedCinematic) ?? [];
    // the new frame will be at index = frames.length
    if (cinematicType !== "path_placement") {
        clearOtherFrameEntities(player);
    }
    const entity = spawnFrameEntity(player, pos, rot, frames.length, cinematicType);
    const frame = {
        pos,
        rot,
        entityId: entity.id,
    };
    if (cinematicType === "panoramic" || cinematicType === "orbital") {
        frames[0] = frame;
    }
    else if (cinematicType === "path_placement") {
        frames.push(frame);
    }
    frameDataMap.set(cineRuntimeData.loadedCinematic, frames);
    cinematicFramesDB.set(cineRuntimeData.loadedCinematic, frames);
}
