import { BinaryClassSerializationAdapter } from "../../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
import TopDownCameraController from "./TopDownCameraController.js";

export class TopDownCameraControllerSerializationAdapter extends BinaryClassSerializationAdapter {

    klass = TopDownCameraController;
    version = 1;

    /**
     *
     * @param {BinaryBuffer} buffer
     * @param {TopDownCameraController} value
     */
    serialize(buffer, value) {

        buffer.writeFloat64(value.target.x);
        buffer.writeFloat64(value.target.y);
        buffer.writeFloat64(value.target.z);

        buffer.writeFloat64(value.pitch);
        buffer.writeFloat64(value.yaw);
        buffer.writeFloat64(value.roll);

        buffer.writeFloat64(value.distance);
        buffer.writeFloat64(value.distanceMin);
        buffer.writeFloat64(value.distanceMax);
    }

    /**
     *
     * @param {BinaryBuffer} buffer
     * @param {TopDownCameraController} value
     */
    deserialize(buffer, value) {
        const target_x = buffer.readFloat64();
        const target_y = buffer.readFloat64();
        const target_z = buffer.readFloat64();

        value.target.set(target_x, target_y, target_z);

        value.pitch = buffer.readFloat64();
        value.yaw = buffer.readFloat64();
        value.roll = buffer.readFloat64();

        value.distance = buffer.readFloat64();
        value.distanceMin = buffer.readFloat64();
        value.distanceMax = buffer.readFloat64();
    }
}
