xlsConfig.ts 3.6 KB

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