xlsConfig.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import GameController from "../GameController"
  2. import { gameMethod } from "./gameMethod"
  3. // type for audio.excel
  4. export type xlsAudioInfo = {id:string,name:string,vol:number}
  5. // type for guide.excel
  6. export type xlsGuideInfo = {id:string,event:string,way:string,variable:number[],ytype:number,condition:number[],type:number,pram:any[],pram1:any[]}
  7. // type for help.excel
  8. // type for item.excel
  9. export type xlsItemKind = {kind:string,name:string}
  10. 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}
  11. // type for kaiqi.excel
  12. // type for languageClient.excel
  13. export type xlsLanguageClientText = {key:string,cn:string,us:string,kr:string,tw:string,jp:string}
  14. // type for languageSever.excel
  15. export type xlsLanguageSeverHouduan = {}
  16. // type for language.excel
  17. export type xlsLanguageLang = {key:string,cn:string,kr:string,tw:string,jp:string}
  18. // type for math.excel
  19. export type xlsMathInfo = {key:string,pram:{"count"?:number,"count1"?:number,"str"?:string,"item"?:number[],"items"?:number[][],"kv"?:{[key:string]:number}}}
  20. // type for name.excel
  21. // type for package.excel
  22. export type xlsPackageInfo = {id:string,group:string,plat:string,wayhttp:string,cfgUrl:string,params:any[],logo:string,loadingTips1:string,loadingTips2:string}
  23. // type for pingbici.excel
  24. // type for shop.excel
  25. export class XlsConfig {
  26. xlsAudioInfo: xlsAudioInfo[]
  27. xlsGuideInfo: xlsGuideInfo[]
  28. xlsPackageInfo: xlsPackageInfo[]
  29. xlsLanguageSeverHouduan: xlsLanguageSeverHouduan[]
  30. xlsMathInfo: xlsMathInfo[]
  31. xlsLanguageClientText: xlsLanguageClientText[]
  32. xlsItemKind: xlsItemKind[]
  33. xlsItemMoney: xlsItemMoney[]
  34. xlsLanguageLang: xlsLanguageLang[]
  35. constructor(bundleName:string, callback: Function, progressCallback?: Function) {
  36. cc.assetManager.loadBundle(bundleName, (err, bundle) => {
  37. if (err) {
  38. GameController.clear()
  39. cc.game.restart()
  40. if (progressCallback) {
  41. progressCallback(0, 0.99);
  42. }
  43. return
  44. }
  45. if (gameMethod.isEmpty(bundle) && cc.sys.platform == cc.sys.WECHAT_GAME) {
  46. //小游戏平台,缓存过期,自动清理缓存,重启游戏
  47. console.error("加载配置表的bundle失败,清理缓存重新加载")
  48. cc.assetManager.cacheManager.clearCache()
  49. GameController.clear()
  50. cc.game.restart()
  51. if (progressCallback) {
  52. progressCallback(0, 0.99);
  53. }
  54. return
  55. }
  56. bundle.loadDir("",(finish: number, total: number, item: any)=>{
  57. if (progressCallback) {
  58. progressCallback(finish, total);
  59. }
  60. }, (err2, assets: cc.JsonAsset[]) => {
  61. if (err2) {
  62. GameController.clear()
  63. cc.game.restart()
  64. if (progressCallback) {
  65. progressCallback(0, 0.99);
  66. }
  67. return
  68. }
  69. let current = 0;
  70. assets.forEach(element => {
  71. this["xls" + this.firstUpCase(element.name)] = element.json;
  72. current++;
  73. });
  74. callback(this)
  75. })
  76. })
  77. }
  78. // 首字母大写
  79. private firstUpCase(str: string) {
  80. return str[0].toUpperCase() + str.substring(1)
  81. }
  82. }