
import GameDefined from "./script/GameLogic/GameDefined";
import { SceneController } from "./script/GameLogic/SceneController";
import OimoHelper from "./script/Oimo/OimoHelper";
import ViewManager, { ViewType } from "./script/GameLogic/ViewManager";

export default class AssetController {
    private static instance: AssetController;
    public static get Instance(): AssetController {
        return this.instance || (this.instance = new AssetController());
    }

    public GameStart() {
        Laya.loader.create(GameDefined.main_path, new Laya.Handler(this, (res) => {
            var _scene = res as Laya.Scene3D;
            OimoHelper.Inst.createWolrd();
            SceneController.Instance.Init(_scene);
            ViewManager.Instance.OpenView(ViewType.game_ui);
        }));
    }

    // private CreateBody() {
    //     var panel = this.panel.addComponent(StandBehaviour) as StandBehaviour;
    //     var data = new OimoBodyData();
    //     data.move = false;
    //     data.type = "box";
    //     panel.init(data);
    //     for (let index = 0; index < this.move._children.length; index++) {
    //         const element = this.move._children[index];
    //         var shell = element.addComponent(ShellBehaviour) as ShellBehaviour;
    //         var data1 = new OimoBodyData();
    //         data1.move = true;
    //         data1.type = "box";
    //         data1.friction=3;
    //         shell.init(data1);
    //     }
    //     var player = this.cube1.addComponent(PlayerBehaviour) as PlayerBehaviour;
    //     var data2 = new OimoBodyData();
    //     data2.move = true;
    //     data2.type = "box";
    //     data2.kinematic = true;
    //     data2.name = 1000;
    //     player.init(data2);
    // }

    private MouseContr() {
        Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.OnClickDown);
        Laya.stage.on(Laya.Event.MOUSE_UP, this, this.OnClickUp);
        Laya.stage.on(Laya.Event.MOUSE_OUT, this, this.OnClickUp);
    }

    OnClickDown(e: Laya.Event) {


        Laya.stage.on(Laya.Event.MOUSE_MOVE, this, this.OnSlider);
        this.curMousePos = new Laya.Vector3(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
        console.log(this.curMousePos)
    }
    OnClickUp() {

        Laya.stage.off(Laya.Event.MOUSE_MOVE, this, this.OnSlider);
        var MousePos = new Laya.Vector3(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
        console.log(MousePos)
    }

    curMousePos: Laya.Vector3;
    OnSlider() {
        var MousePos = new Laya.Vector3(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);
        var offestX = MousePos.x - this.curMousePos.x;
        var offestZ = MousePos.y - this.curMousePos.y;
        if (offestX > 0) offestX = offestX < 0.1 ? offestX : 0.1;
        if (offestX < 0) offestX = offestX > -0.1 ? offestX : -0.1;
        if (offestZ > 0) offestZ = offestZ < 0.1 ? offestZ : 0.1;
        if (offestZ < 0) offestZ = offestZ > -0.1 ? offestZ : -0.1;
        console.log(offestX);
        // this.cube1.transform.localPositionX += offestX;
        // this.cube1.transform.localPositionZ += offestZ;
        this.curMousePos = new Laya.Vector3(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY);;
    }
}