JsonManager.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { IBenzAsset } from "../asset/IBenzAsset";
  2. import { BenzAssetManager } from "../asset/BenzAssetManager";
  3. import AccountModel from "../../data/Account/AccountModel";
  4. import { AssetsHelper } from "../asset/AssetsHelper";
  5. export default class JsonManager {
  6. static singleInstance: JsonManager = null;
  7. static getInstance(): JsonManager {
  8. if (JsonManager.singleInstance == null) {
  9. JsonManager.singleInstance = new JsonManager();
  10. }
  11. return JsonManager.singleInstance;
  12. }
  13. //所有json文件路径
  14. _josnPathList = [
  15. "json/buff",
  16. "json/Item",
  17. "json/Model",
  18. "json/npc",
  19. "json/airdrop_reward",
  20. "json/searchMarket_reward",
  21. "json/survivor_reward",
  22. "json/sign",
  23. ];
  24. _staticData = {}; //表格数据保存
  25. constructor() {
  26. }
  27. concatJosnPathList(assetList: IBenzAsset[]) {
  28. for (const key in this._josnPathList) {
  29. if (this._josnPathList.hasOwnProperty(key)) {
  30. const element = this._josnPathList[key];
  31. let asset =
  32. {
  33. fileName: element,
  34. type: cc.JsonAsset,
  35. isAutoRelease: false
  36. }
  37. assetList.push(asset);
  38. }
  39. }
  40. }
  41. /**
  42. * 提前加载静态数据
  43. */
  44. loadJsonData() {
  45. for (let index = 0; index < this._josnPathList.length; index++) {
  46. const element = this._josnPathList[index];
  47. let data: cc.JsonAsset = <cc.JsonAsset>BenzAssetManager.getInstance().getAsset(element);
  48. //cc.log("sdfa", JSON.stringify(data.json));
  49. this._staticData[element] = data.json;
  50. }
  51. this.dealWithSpecialData();
  52. }
  53. /**
  54. * 获得运用需要加载json路径列表
  55. */
  56. getJosnPathList() {
  57. return this._josnPathList;
  58. }
  59. /**
  60. * 加载资源完成之后 一些特殊处理
  61. */
  62. dealWithSpecialData() {
  63. //ToDo
  64. }
  65. /**
  66. * 根据表名获得数据
  67. * @param key
  68. */
  69. GetDataByName(key: string) {
  70. return this._staticData[key];
  71. }
  72. getSkinDtByID(curUseSKin: number) {
  73. let skinJson = this.GetDataByName(AssetsHelper.SKIN_JSON);
  74. let skinIdx = skinJson[curUseSKin];
  75. return skinIdx;
  76. }
  77. }