xlsConfig.ts 4.5 KB

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