xlsConfig.ts 4.3 KB

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