/**
 * PlayABC渠道
 */

import { Singleton } from "../Common/Utils/Singleton";
import { DCGame } from "../DataCenter/DCGame";
import { defaultData } from "../DataCenter/DefaultData";


export class PlayABC extends Singleton {

	private callBack: Function;
	//获得表数据数据
	public InitData(cb: Function) {
		this.callBack = cb;
		console.log('初始化数据');
		if (window && (<any>window).courseware && (<any>window).courseware.getData) {
			(<any>window).courseware.getData((data) => {
				DCGame.getInstance().data = data || this.getDefaultData();
				this.preload();
			})
		} else {
			DCGame.getInstance().data = this.getDefaultData();
			this.preload();
		}
	}

	public getDefaultData() {
		return defaultData;
	}

	public preload() {
		if (window && window["air"]) {
			this.onLoadEnd();
			window["air"].hideAirClassLoading();
		} else {
			this.onLoadEnd();
		}

		cc.debug.setDisplayStats(false);
	}

	public onLoadEnd() {
		this.callBack && this.callBack();
	}
}