xlsConfig.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 guide.excel
  13. export type xlsGuideInfo = {id:string,event:string,way:string,variable:number[],ytype:number,condition:number[],type:number,pram:any[],pram1:any[]}
  14. // type for help.excel
  15. // type for item.excel
  16. export type xlsItemKind = {kind:string,name:string}
  17. 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}
  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:int,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. xlsChapterInfo: xlsChapterInfo[]
  40. xlsChapterLayout: xlsChapterLayout[]
  41. xlsKaiqiInfo: xlsKaiqiInfo[]
  42. xlsEmitterInfo: xlsEmitterInfo[]
  43. xlsAttrAttr: xlsAttrAttr[]
  44. xlsAudioInfo: xlsAudioInfo[]
  45. xlsLanguageClientText: xlsLanguageClientText[]
  46. xlsGuideInfo: xlsGuideInfo[]
  47. xlsLanguageSeverHouduan: xlsLanguageSeverHouduan[]
  48. xlsPackageInfo: xlsPackageInfo[]
  49. xlsMergePropInfo: xlsMergePropInfo[]
  50. xlsMathInfo: xlsMathInfo[]
  51. xlsPingbiciInfo: xlsPingbiciInfo[]
  52. xlsNameName: xlsNameName[]
  53. xlsItemKind: xlsItemKind[]
  54. xlsItemMoney: xlsItemMoney[]
  55. xlsLanguageLang: xlsLanguageLang[]
  56. constructor(bundleName:string, callback: Function, progressCallback?: Function) {
  57. cc.assetManager.loadBundle(bundleName, (err, bundle) => {
  58. if (err) {
  59. GameController.clear()
  60. cc.game.restart()
  61. if (progressCallback) {
  62. progressCallback(0, 0.99);
  63. }
  64. return
  65. }
  66. if (gameMethod.isEmpty(bundle) && cc.sys.platform == cc.sys.WECHAT_GAME) {
  67. //小游戏平台,缓存过期,自动清理缓存,重启游戏
  68. console.error("加载配置表的bundle失败,清理缓存重新加载")
  69. cc.assetManager.cacheManager.clearCache()
  70. GameController.clear()
  71. cc.game.restart()
  72. if (progressCallback) {
  73. progressCallback(0, 0.99);
  74. }
  75. return
  76. }
  77. bundle.loadDir("",(finish: number, total: number, item: any)=>{
  78. if (progressCallback) {
  79. progressCallback(finish, total);
  80. }
  81. }, (err2, assets: cc.JsonAsset[]) => {
  82. if (err2) {
  83. GameController.clear()
  84. cc.game.restart()
  85. if (progressCallback) {
  86. progressCallback(0, 0.99);
  87. }
  88. return
  89. }
  90. let current = 0;
  91. assets.forEach(element => {
  92. this["xls" + this.firstUpCase(element.name)] = element.json;
  93. current++;
  94. });
  95. callback(this)
  96. })
  97. })
  98. }
  99. // 首字母大写
  100. private firstUpCase(str: string) {
  101. return str[0].toUpperCase() + str.substring(1)
  102. }
  103. }