import { Vec2 } from "cc";
import GObject from "./base/GObject";
import { v3 } from "cc";
import { JNFrameInfo } from "../../../extensions/ngame/assets/ngame/sync/frame/JNSyncFrame";
import { Node } from "cc";
import { Vec3 } from "cc";
import { Camera } from "cc";
import GBattleModeManager from "./GBattleModeManager";


export default class GBaseMode<T,DT> extends GObject<T> {

    //场景相机
    camera:Camera;
    //模式数据
    data:DT;

    get scene():Node{
        return this.node;
    }

    //添加对象到场景中
    addGObject(obj: GObject<{}>,pos?:Vec2 | Vec3){
        obj.mode = this;
        this.scene.addChild(obj.node);
        if(pos){
            obj.node.setWorldPosition(v3(pos.x,pos.y,0));
        }
    }

    //添加Node到场景中
    addGNode(obj:Node,pos?:Vec2 | Vec3){
        this.scene.addChild(obj);
        if(pos){
            obj.setWorldPosition(v3(pos.x,pos.y,0));
        }
    }

    //结束场景
    Close(data?:any){
        GBattleModeManager.getIns().Close(data);
    }

    onSyncUpdate(dt: number,frame:JNFrameInfo, input?: T) { 

        //重置 场景中的层级
        [...this.scene.children].sort((node1,node2) => node2.worldPosition.y - node1.worldPosition.y).forEach((node,index) => {
            node.setSiblingIndex(index);
        })
        
    }

}

