import GameController from "../GameController" import { gameMethod } from "./gameMethod" // type for audio.excel export type xlsAudioInfo = {id:string,name:string,vol:number} // type for guide.excel export type xlsGuideInfo = {id:string,event:string,way:string,variable:number[],ytype:number,condition:number[],type:number,pram:any[],pram1:any[]} // type for help.excel // type for item.excel export type xlsItemKind = {kind:string,name:string} export type xlsItemMoney = {id:string,name:string,icon:string,pinzhi:number,desc:string,iconshowtype:number,from:number[],produce:string,type:string,detailType:string,param:{"items"?:number[][],"nums"?:number[],"kv"?:{[key:string]:number},"count"?:number},beibao:number,isUse:number,isShowRed:number,openType:string,price:number} // type for kaiqi.excel // type for languageClient.excel export type xlsLanguageClientText = {key:string,cn:string,us:string,kr:string,tw:string,jp:string} // type for languageSever.excel export type xlsLanguageSeverHouduan = {} // type for language.excel export type xlsLanguageLang = {key:string,cn:string,kr:string,tw:string,jp:string} // type for math.excel export type xlsMathInfo = {key:string,pram:{"count"?:number,"count1"?:number,"str"?:string,"item"?:number[],"items"?:number[][],"kv"?:{[key:string]:number}}} // type for name.excel // type for package.excel export type xlsPackageInfo = {id:string,group:string,plat:string,wayhttp:string,cfgUrl:string,params:any[],logo:string,loadingTips1:string,loadingTips2:string} // type for pingbici.excel // type for shop.excel export class XlsConfig { xlsAudioInfo: xlsAudioInfo[] xlsLanguageSeverHouduan: xlsLanguageSeverHouduan[] xlsMathInfo: xlsMathInfo[] xlsPackageInfo: xlsPackageInfo[] xlsGuideInfo: xlsGuideInfo[] xlsLanguageClientText: xlsLanguageClientText[] xlsItemKind: xlsItemKind[] xlsItemMoney: xlsItemMoney[] xlsLanguageLang: xlsLanguageLang[] constructor(bundleName:string, callback: Function, progressCallback?: Function) { cc.assetManager.loadBundle(bundleName, (err, bundle) => { if (err) { GameController.clear() cc.game.restart() if (progressCallback) { progressCallback(0, 0.99); } return } if (gameMethod.isEmpty(bundle) && cc.sys.platform == cc.sys.WECHAT_GAME) { //小游戏平台,缓存过期,自动清理缓存,重启游戏 console.error("加载配置表的bundle失败,清理缓存重新加载") cc.assetManager.cacheManager.clearCache() GameController.clear() cc.game.restart() if (progressCallback) { progressCallback(0, 0.99); } return } bundle.loadDir("",(finish: number, total: number, item: any)=>{ if (progressCallback) { progressCallback(finish, total); } }, (err2, assets: cc.JsonAsset[]) => { if (err2) { GameController.clear() cc.game.restart() if (progressCallback) { progressCallback(0, 0.99); } return } let current = 0; assets.forEach(element => { this["xls" + this.firstUpCase(element.name)] = element.json; current++; }); callback(this) }) }) } // 首字母大写 private firstUpCase(str: string) { return str[0].toUpperCase() + str.substring(1) } }