import { WeChat } from "../Share/share";


const { ccclass, property } = cc._decorator;
@ccclass('GameConfig')
export class GameConfig  {
    //所有控制信息都通过GameAppStart内控制
    private static _instance : GameConfig = null;
    //用于盛放埋点数据上传，每次上传后清空
    static GM_INFO: {
        // isEnd: false,
        mean_Time: number; //平均放箭速度
        total: number; //总共对的个数
        currSeed: number; //用于随机数种子
        gameId: string; //游戏ID
        userId: number; //用户ID
        scode: string;  //用户code
        guide: boolean; //是否有引导
        url: string; //访问域名
        success: boolean; //用户游戏成功与否
        matchId: any; //用于埋点上传的ID
        custom: number; //用于测试跳关卡
    };
    static CLICK_DATA: {
        type: number; //上传数据类型
        success: boolean; //此局游戏胜负    
        round: number; //回合数
        totalSunCount: number; //太阳总数
        movedSunCount: number; //可移动太阳个数
        sunSpeed: number; //太阳移动速度
        overlapSunCount: number; //重叠太阳个数
        colorList: any[]; //太阳颜色数组
        duration: number; //每次点击的反应时间
        difficultyLevel: number; //此次难度
        sunList: any[]; //太阳数组，用于存放太阳类型 0:普通 1:移动 2:重叠
        stepTimeList: any[]; //每次点击间隔
        remainder: number; //游戏剩余时间
    };
    static LEVEL_INFO: { //第一难度
        number: number; //太阳总数 
        moveNumber: number; //太阳可移动个数
        moveSpeed: number; //太阳移动速度等级
        maxDistance: number; //布局后移动最大距离
        maxMove: number; //每个太阳之间距离最大间距
        repeat: number; //是否重叠，现在0 不重叠 1 重叠1个
    }[];
    static GAME_DATA: any[];


    static get Instance()
    {
        if (this._instance == null)
        {
            this._instance = new GameConfig();
        }
        return this._instance;
    }

    static getKey(key){
        var reg = new RegExp('(^|&)' + key + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return "";
    }

    static init(){
        this.GM_INFO_init();
        this.CLICK_init();
        this.LEVEL_INFO_init();
        
        var self = this;
        cc.resources.load('Json/GM_INFO', (err: any, res: cc.JsonAsset) => {
            if (err) {
                WeChat.setShare(location.href);
                self.Authentication();
                return;
            }
            let jsonData: object = res.json!;
            self.GM_INFO = jsonData["data"];
            self.setCode(self.getKey("scode"));
            WeChat.setShare(location.href);
            self.Authentication();

        })
        cc.resources.load('Json/CLICK_DATA', (err: any, res: cc.JsonAsset) => {
            if (err) {
            
                return;
            }
            let jsonData: object = res.json!;
            self.CLICK_DATA = jsonData["data"];
        })
        cc.resources.load('Json/LEVEL_INFO', (err: any, res: cc.JsonAsset) => {
            if (err) {
                return;
            }
            let jsonData: object = res.json!;
            self.LEVEL_INFO = jsonData["data"];
        })

        //GAME_DATA 废弃了，暂时不删除以防后面修改回 一整局传一次
        self.GAME_DATA = [
        ]
    }
    
    //数据备用
    static GM_INFO_init() {
        this.GM_INFO = {
            // isEnd: false,
            mean_Time: 0,                //平均放箭速度
            total: 0,                    //总共对的个数
            currSeed: 203213,           //用于随机数种子
            gameId: '100009',           //游戏ID
            userId: 0,                  //用户ID
            scode: "",                  //用户code,从网页后缀获取
            guide: true,                 //是否有引导
            url: "https://api.sparkus.cn",//访问域名
            success: false,             //用户游戏成功与否
            matchId: null,              //用于埋点上传的ID
            custom: 0                   //用于测试跳关卡
        };
        this.setCode(this.getKey("scode"));
    }
    static CLICK_init() {
        this.CLICK_DATA =
        {
            type: 1,            //上传数据类型
            success: false,     //此局游戏胜负    
            round: 0,           //回合数
            totalSunCount: 0,   //太阳总数
            movedSunCount: 0,   //可移动太阳个数
            sunSpeed: 0,        //太阳移动速度
            overlapSunCount: 0, //重叠太阳个数
            colorList: [],      //太阳颜色数组
            duration: 0,        //每次点击的反应时间
            difficultyLevel: 0, //此次难度
            sunList: [],        //太阳数组，用于存放太阳类型 0:普通 1:移动 2:重叠
            stepTimeList: [],   //每次点击间隔
            remainder: 120      //游戏剩余时间
        }
    }
    static LEVEL_INFO_init() {
        this.LEVEL_INFO = [
            {   //第一难度
                number: 3,       //太阳总数 
                moveNumber: 0,   //太阳可移动个数
                moveSpeed: 0,    //太阳移动速度等级
                maxDistance: 200, //布局后移动最大距离
                maxMove: 1200,    //每个太阳之间距离最大间距
                repeat: 0        //是否重叠，现在0 不重叠 1 重叠1个
            },
            {   //第二难度
                number: 4,
                moveNumber: 0,
                moveSpeed: 0,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 0
            },
            {   //第三难度
                number: 4,
                moveNumber: 0,
                moveSpeed: 0,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //第四难度
                number: 5,
                moveNumber: 1,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 0
            },
            {   //第五难度
                number: 5,
                moveNumber: 0,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //第六难度
                number: 6,
                moveNumber: 0,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //第七难度
                number: 6,
                moveNumber: 3,
                moveSpeed: 4,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 0
            },
            {   //第八难度
                number: 7,
                moveNumber: 0,
                moveSpeed: 4,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 0
            },
            {   //第九难度
                number: 7,
                moveNumber: 3,
                moveSpeed: 4,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 0
            },
            {   //第十难度
                number: 7,
                moveNumber: 3,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //第十一难度
                number: 8,
                moveNumber: 3,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 0
            },
            {   //第十二难度
                number: 8,
                moveNumber: 5,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //第十三难度
                number: 9,
                moveNumber: 3,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 0
            },
            {   //第十四难度
                number: 9,
                moveNumber: 5,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //第十五难度
                number: 10,
                moveNumber: 5,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //11 
                number: 3,
                moveNumber: 0,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 0
            },
            {   //12 
                number: 4,
                moveNumber: 0,
                moveSpeed: 0,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 0
            },
            {   //13 
                number: 4,
                moveNumber: 1,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 0
            },
            {   //14 
                number: 4,
                moveNumber: 0,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //15 
                number: 4,
                moveNumber: 1,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //16 
                number: 5,
                moveNumber: 1,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 0
            },
            {   //17 
                number: 5,
                moveNumber: 0,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //18 
                number: 5,
                moveNumber: 1,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //19 
                number: 5,
                moveNumber: 2,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            },
            {   //20 
                number: 5,
                moveNumber: 3,
                moveSpeed: 6,
                maxDistance: 200,
                maxMove: 1200,
                repeat: 1
            }

        ]
    }
    static Authentication(){
        cc.fx.GameTool.Authentication();
    }

    static setCode(code){
        this.GM_INFO.scode = code;
    }

}

