import { _decorator, Component, Node, sys, find, CCString } from 'cc';
import { CarColorsGlobalInstance } from './CarColorsGlobalInstance';
import { ToastSysterm } from '../../UIFrame/ToastSysterm/ToastSysterm';
import { BundleCarColorsSysterm } from './Systerms/BundleCarColorsSysterm';
import { UICarColorsSysterm } from './Systerms/UICarColorsSysterm';
import { UINames } from './CarColorsGlobalTypes';
import { RoleCarColorsSysterm } from './Systerms/RoleCarColorsSysterm';
import { GlobalData, ConfigKeys } from '../../ScriptFrame/GlobalData';
import { CarCarColorsSysterm } from './Systerms/CarCarColorsSysterm';
import { PlatformManager } from '../../ScriptFrame/Frame/platformManager';
import { GlobalMgr } from '../../ScriptFrame/Frame/GlobalMgr';
import { AdvertMgr } from '../../ScriptFrame/Frame/AdvertMgr';
const { ccclass, property } = _decorator;

@ccclass('CarColorsGameEntry')
export class CarColorsGameEntry extends Component {
    @property(CCString)
    insADid: string = ""
    @property(CCString)
    rewardADid: string = ""
    @property(CCString)
    bannerADid: string = ""
    @property(CCString)
    bookId: string = ""

    async start() {

        PlatformManager.adsInsId = this.insADid
        PlatformManager.adsVideoId = this.rewardADid
        PlatformManager.adsBannerId = this.bannerADid
        if (sys.platform === sys.Platform.WECHAT_GAME) {
            wx.showShareMenu({
                withShareTicket: true,
                menus: ['shareAppMessage', 'shareTimeline']
            })
        }
        this.initData()
        // 挂载toast弹窗
        CarColorsGlobalInstance.instance.toastSysterm = find("UI/ToastSysterm").getComponent(ToastSysterm)

        // 挂载资源包管理系统
        CarColorsGlobalInstance.instance.bundleSysterm = this.node.addComponent(BundleCarColorsSysterm)
        await CarColorsGlobalInstance.instance.bundleSysterm.loadBundles()

        // 人物管理系统
        CarColorsGlobalInstance.instance.roleSysterm = this.node.addComponent(RoleCarColorsSysterm)
        await CarColorsGlobalInstance.instance.roleSysterm.loadRolePrefabs()

        // 汽车管理系统
        CarColorsGlobalInstance.instance.carSysterm = this.node.addComponent(CarCarColorsSysterm)

        // 挂载UI系统
        CarColorsGlobalInstance.instance.uiSysterm = this.node.addComponent(UICarColorsSysterm)
        await CarColorsGlobalInstance.instance.uiSysterm.loadUIPrefabs()

        CarColorsGlobalInstance.instance.uiSysterm.showUI(UINames.HomePage)
        find("UI/BundleLoading").active = false
    }

    initData() {
        let gameSaveData: { level: number } = GlobalData.instance.getConfigData(ConfigKeys.GameSaveData)
        if (gameSaveData === null) {
            gameSaveData = {
                level: 1
            }
        }
        GlobalData.instance.setConfigData(ConfigKeys.GameSaveData, gameSaveData)
    }
}


