import { BinaryClassUpgrader } from "../../../ecs/storage/binary/BinaryClassUpgrader.js";
import { InterpolationType } from "./InterpolationType.js";

export class PathSerializationUpgrader_0_1 extends BinaryClassUpgrader {
    constructor() {
        super();

        this.__startVersion = 0;
        this.__targetVersion = 1;
    }

    upgrade(source, target) {
        //write interpolation type
        target.writeUint8(InterpolationType.Linear);

        target.writeUintVar(0);
        target.writeFloat32(0);

        const numPoints = source.readUint32();

        target.writeUintVar(numPoints);

        for (let i = 0; i < numPoints; i++) {
            for (let j = 0; j < 3; j++) {
                const v = source.readFloat64();

                target.writeFloat32(v);
            }
        }
    }
}
