
import OimoRigidBody from "../Oimo/OimoRigibody";
import OimoBodyData from "../Oimo/OimoBodyData";
import GameDefined from "../GameLogic/GameDefined";

export default class PlayerBehaviour extends OimoRigidBody {

    public constructor() {
        super();
    }

    private bodyVc3: OIMO.Vec3 = new OIMO.Vec3(0, 0, 0);
    private bodyQut: OIMO.Quat = new OIMO.Quat(0, 0, 0, 1);
    public init(data?: OimoBodyData) {
        if(!data)data=new OimoBodyData();
        data.move = true;
        data.kinematic = true;
        data.name=GameDefined.playerbodyname;
        super.init(data);
    }

    public onAwake(): void {

    }

    public onStart(): void {
    }

    public onUpdate(): void {
        let transPos = this.transform.position;
        let transQut = this.transform.rotation;
        this.bodyVc3.set(transPos.x, transPos.y, transPos.z);
        this.bodyQut.set(transQut.x, transQut.y, transQut.z, transQut.w);
        this.body.setPosition(this.bodyVc3);
        this.body.setQuaternion(this.bodyQut);
    }

    public checkContact(name) {
        return false;
    }

    public onDisable(): void {
        if (this.body && this.body.parent) this.body.dispose();
        this.body = null;
    }
    public get name() {
        if (this.body) return this.body.name;
        return -1;
    }
}