GoldConfigData.ts 1.4 KB
import Util from "../../uitl/Util";
import AppSdk from "../AppSdk";

export class GoldConfigData {
    ad: Object;
    adnet: string;
    app_name: string;
    coin_config: string = '';
    gameUrl: string;
    kuai_app_name: string;
    pangolin: string;
    tTurboAgent: string;
    teaAgent: number;
    tracking: string;
    ttAppLog: string;
    umid: string;
    gameConfig: any;

    code: number = -3;
    private static instance: GoldConfigData = null;

    public static get I(): GoldConfigData {
        if (!this.instance)
            this.instance = new GoldConfigData();
        return this.instance;
    }
    initData(data) {
        this.code = data.code;
        if (!data.code) {
            data = data.data;
            for (const key in data) {
                if (data.hasOwnProperty(key)) {
                    const ele = data[key];
                    this[key] = ele;
                }
            }
        }
    }

    async getGoldConfig() {
        return new Promise<any>(async (resolve, reject) => {
            let result = AppSdk.I.gameConfig;
            if (result) {
                let configJson = await this.loadGoldCfg(result['coin_config'][0]);
                resolve(configJson);
            }
        });
    }

    async loadGoldCfg(res: string) {
        let configJson = await Util.I.load(res);
        return configJson;
    }
}