import { _decorator, Component, game, Node} from 'cc';
import { config } from './config';
import { tools } from './tools';
import { uiManager } from './manager/uiManager';
import { home } from './ui/home/home';
import { loading_view } from './ui/loading_view';
import { SdkUtil } from './sdkUtil';
const { ccclass, property } = _decorator;

@ccclass('main')
export class main extends Component {
    @property(Node) home_node:Node = null;
    @property(Node) ui_parent = null;
    @property(Node) laoding_view_wait = null;
    @property(Node) send_msg_wait = null;
    protected start(): void {
        game.frameRate = 61;  //修复 iphone 15 抖动问题
        // PhysicsSystem2D.instance.fixedTimeStep = 1 / 60;
        SdkUtil.init()
        tools.init(this.node)
        this.home_node.removeAllChildren()
        uiManager.Instance().init(this.ui_parent,this.laoding_view_wait,this.send_msg_wait)

        this.showLoadingView()
    }

    showLoadingView() {
        uiManager.Instance().showUi(config.UI.loading_view, this.node, (node:Node)=>{
            node.getComponent(loading_view).startLoading(()=>{
                this.showHomeView()
            })
        })
    }

    showHomeView() {
        uiManager.Instance().showUi(config.UI.home,this.home_node,(node:Node)=>{
            node.getComponent(home).init()
            this.home_node.active = true
        })
    }
}


