/**
 * 游戏数据中心
 */

import { Store } from "./Store";


export class GameDataCenter {

    /** 事件枚举 */
    static EEventName = {
        UPDATE_DATA_COIN: 'UPDATE_DATA_COIN',
        UPDATE_DATA_GAME_LEVEL: 'UPDATE_DATA_GAME_LEVEL',
        UPDATE_DATA_GAME_COUNT: 'UPDATE_DATA_GAME_COUNT',
    };


    private static _gameCount: number = 0;      // 游戏局数
    private static _bubbles: cc.Node[][] = [] //泡泡数组
    private static _rewarded: string[] = []    //奖励数组['type:num']
    private static _tipType: number = 0;    //提示面板类型

    private static _gameLevel: number = 1;      // 关卡
    private static _coin: number = 0;           // 金币
    private static _star: number = 0;           // 星星数
    private static _specialBubbles: number[] = [];  // 特殊球的数量,0:炸弹  1:激光  2:七彩  3:闪电
    private static _isSignIn: boolean = null;   //当前是否第一次登陆
    private static _signIn: number = 0;         //累计签到天数
    private static _ingot: number = 0;          //元宝数量
    private static _ingotGet: object[] = [];      //元宝获得信息
    private static _isInitSpecial: boolean = false;     //初始化特殊球数量

    /** 游戏局数 */
    public static set gameCount(v) {
        GameDataCenter._gameCount = v;
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_COUNT, GameDataCenter._gameCount);
    }
    public static get gameCount() { return GameDataCenter._gameCount; }

    /** 泡泡数组 */
    public static set bubbles(v) {
        GameDataCenter._bubbles = v;
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_COUNT, GameDataCenter._bubbles);
    }
    public static get bubbles() { return GameDataCenter._bubbles; }

    /** 奖励数组 */
    public static set rewarded(v) {
        GameDataCenter._rewarded = v;
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_COUNT, GameDataCenter._rewarded);
    }
    public static get rewarded() { return GameDataCenter._rewarded; }

    /** 提示面板类型 */
    public static set tipType(v) {
        GameDataCenter._tipType = v;
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_COUNT, GameDataCenter._tipType);
    }
    public static get tipType() { return GameDataCenter._tipType; }


    /** 关卡 */
    public static set gameLevel(v) {
        GameDataCenter._gameLevel = v;
        Store.set('gameLevel', GameDataCenter._gameLevel);
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_LEVEL, GameDataCenter._gameLevel);
    }
    public static get gameLevel() {
        GameDataCenter._gameLevel = Store.get('gameLevel', 1);
        return GameDataCenter._gameLevel;
    }

    /** 金币 */
    public static set coin(v) {
        GameDataCenter._coin = v;
        Store.set('coin', GameDataCenter._coin);
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_COIN, GameDataCenter._coin);
    }
    public static get coin() {
        GameDataCenter._coin = Store.get('coin', 0);
        return GameDataCenter._coin;
    }

    /** 星星数 */
    public static set star(v) {
        GameDataCenter._star = v;
        Store.set('star', GameDataCenter._star);
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_LEVEL, GameDataCenter._star);
    }
    public static get star() {
        GameDataCenter._star = Store.get('star', 0);
        return GameDataCenter._star;
    }

    /** 特殊球数量 */
    public static set specialBubbles(v) {
        GameDataCenter._specialBubbles = v;
        Store.set('specialBubbles', GameDataCenter._specialBubbles);
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_LEVEL, GameDataCenter._specialBubbles);
    }
    public static get specialBubbles() {
        GameDataCenter._specialBubbles = Store.get('specialBubbles', [0, 0, 0, 0]);
        return GameDataCenter._specialBubbles;
    }

    /** 当前是否第一次登陆 */
    public static set isSignIn(v) {
        GameDataCenter._isSignIn = v;
        Store.setTodayValue('isSignIn', GameDataCenter._isSignIn);
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_COUNT, GameDataCenter._isSignIn);
    }
    public static get isSignIn() {
        GameDataCenter._isSignIn = Store.getTodayValue('isSignIn', false);
        return GameDataCenter._isSignIn;
    }

    /** 签到天数 */
    public static set signIn(v) {
        GameDataCenter._signIn = v;
        Store.set('signIn', GameDataCenter._signIn);
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_COUNT, GameDataCenter._signIn);
    }
    public static get signIn() {
        GameDataCenter._signIn = Store.get('signIn', 0);
        return GameDataCenter._signIn;
    }

    /** 元宝数量 */
    public static set ingot(v) {
        GameDataCenter._ingot = v;
        Store.set('ingot', GameDataCenter._ingot);
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_COUNT, GameDataCenter._ingot);
    }
    public static get ingot() {
        GameDataCenter._ingot = Store.get('ingot', 300000);
        return GameDataCenter._ingot;
    }

    /** 元宝获得信息 */
    public static set ingotGet(v) {
        GameDataCenter._ingotGet = v;
        Store.set('ingotGet', GameDataCenter._ingotGet);
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_COUNT, GameDataCenter._ingotGet);
    }
    public static get ingotGet() {
        GameDataCenter._ingotGet = Store.get('ingotGet', []);
        return GameDataCenter._ingotGet;
    }

    /** 是否初始化特殊球数量 */
    public static set isInitSpecial(v) {
        GameDataCenter._isInitSpecial = v;
        Store.set('isInitSpecial', GameDataCenter._isInitSpecial);
        cc.systemEvent.emit(GameDataCenter.EEventName.UPDATE_DATA_GAME_COUNT, GameDataCenter._isInitSpecial);
    }
    public static get isInitSpecial() {
        GameDataCenter._isInitSpecial = Store.get('isInitSpecial', false);
        return GameDataCenter._isInitSpecial;
    }

}

(window as any).GameDataCenter = GameDataCenter;