import { FlyControls as ThreeFlyControls } from "three/examples/jsm/controls/FlyControls.js";

import { Camera } from "./Camera.js";
import { Behaviour, GameObject } from "./Component.js";

/**
 * @deprecated The FlyControls component is deprecated and will be removed in the future.
 */
export class FlyControls extends Behaviour {
    private _controls: ThreeFlyControls | null = null;

    onEnable(): void {
        const cam = GameObject.getComponent(this.gameObject, Camera)?.threeCamera;
        if (!cam) {
            console.warn("FlyControls: Requires a Camera component on the same object as this component.");
            return;
        }
        
        this._controls = new ThreeFlyControls(cam, this.context.renderer.domElement);
        this._controls.rollSpeed = .5;
        this._controls.movementSpeed = 3;
        this._controls.dragToLook = true;
        
    }

    onDisable(): void {
        this._controls?.dispose();
        this._controls = null;
    }

    update(): void {
        if (this._controls)
            this._controls.update(this.context.time.deltaTime);
    }

}