FillGlobalConfig.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // FillGlobalConfig.hpp
  3. // Test
  4. //
  5. // Created by 高慕白 on 2024/12/3.
  6. //
  7. #ifndef FillGlobalConfig_hpp
  8. #define FillGlobalConfig_hpp
  9. #include <stdio.h>
  10. #include <stdio.h>
  11. #include "contourdata.h"
  12. #include <string>
  13. using std::string;
  14. #include "ajson5.h"
  15. #include <unordered_map>
  16. using std::unordered_map;
  17. #include <vector>
  18. using std::vector;
  19. #define FILLGLOBALCONFIG_JEWELSIZE_SM 0
  20. #define FILLGLOBALCONFIG_JEWELSIZE_MD 1
  21. #define FILLGLOBALCONFIG_JEWELSIZE_LG 2
  22. #define FILLGLOBALCONFIG_DIFFCULTY_NORM 0
  23. #define FILLGLOBALCONFIG_DIFFCULTY_HARD1 1
  24. #define FILLGLOBALCONFIG_DIFFCULTY_HARD2 2
  25. #define FILLGLOBALCONFIG_PLATESIZE_SM 1
  26. #define FILLGLOBALCONFIG_PLATESIZE_MD 2
  27. #define FILLGLOBALCONFIG_PLATESIZE_LG 3
  28. struct FillGlobalConfig {
  29. //这个结构体似乎不用了
  30. struct ContourConfig {
  31. string _name;
  32. ContourData _contour ;
  33. } ;
  34. bool init(string filename) ;
  35. bool initJewelItems( string filename ) ;
  36. bool initLevelDatas( string filename ) ;
  37. bool initPlateItems( string filename ) ;
  38. //静态全局单例
  39. static FillGlobalConfig* getInstance() ;
  40. vector<ContourConfig> _plateContours ;
  41. vector<ContourConfig> _jewelContours ;
  42. ContourData* getContourDataByPngName(string& pngname) ;
  43. //宝石基本信息
  44. struct JewelItem {
  45. int _id ;
  46. string _category;
  47. string _jewelName;
  48. string _code1;
  49. string _code2;
  50. int _size ; // 0-SM 1-MD 2-LG
  51. float _scale;// 0.0-1.0
  52. string _pngName;
  53. string _yzName;
  54. string _contourName;
  55. float _bbWidth;
  56. float _bbHeight;
  57. string _etc; //备注信息
  58. };
  59. JewelItem* getJewelItemById(int jid){ return _mapJewelItems.find(jid)!=_mapJewelItems.end()?(&_mapJewelItems[jid]):nullptr; }
  60. int getJewelItemCount() { return _mapJewelItems.size() ; }
  61. //关卡组成数据
  62. struct LevelData {
  63. int _id ;
  64. int _subId ;
  65. int _difficulty;//难度 0-普通, 1-难 , 2-极难
  66. vector<int> _jewelIds ;
  67. vector<int> _cnts ;//宝石个数,读取的时候要把组数乘以3计算出宝石个数。
  68. } ;
  69. //levelId 是关卡主编号值, subIndex是子关卡的索引值(从0开始)
  70. LevelData* getLevelData(int levelId,int subIndex) { return (_mapLevelDatas.find(levelId)!=_mapLevelDatas.end())?(&_mapLevelDatas[levelId][subIndex]):nullptr; }
  71. int getSubLevelCount(int levelId) { return (_mapLevelDatas.find(levelId)!=_mapLevelDatas.end())?(_mapLevelDatas[levelId].size()):0; }
  72. //盘子基本信息
  73. struct PlateItem {
  74. int _id ;
  75. string _name;
  76. int _size ;// 0-MINI 1-SM 2-MD 3-LG
  77. string _pngName ;
  78. string _contourName;
  79. float _blx,_bly,_trx,_try ;// bl for bottom-left, tr for top-right.
  80. int _bigJewCap ;//大宝石容量
  81. float _bbwid,_bbhei ;//精灵图片尺寸
  82. string _etc ;
  83. } ;
  84. PlateItem* getPlateItemById(int pid){ return _mapPlateItems.find(pid)!=_mapPlateItems.end()?(&_mapPlateItems[pid]):nullptr; }
  85. int getPlateItemCount( int plateSzId ) { return (_mapPlateIdArray.find(plateSzId)!=_mapPlateIdArray.end())?(_mapPlateIdArray[plateSzId].size()):0; }
  86. PlateItem* getPlateItemBySzNIndex(int plateSzId,int index){ return (_mapPlateIdArray.find(plateSzId)!=_mapPlateIdArray.end())?( getPlateItemById(_mapPlateIdArray[plateSzId][index])):nullptr; }
  87. private:
  88. static FillGlobalConfig* _s_instance ;
  89. unordered_map<int, JewelItem> _mapJewelItems ;
  90. unordered_map<int, vector<LevelData> > _mapLevelDatas ;// key 为主关卡编号, vector<LevelData> 为子关卡数组
  91. unordered_map<int, PlateItem> _mapPlateItems ;
  92. unordered_map<int, vector<int> > _mapPlateIdArray; // key为小、中、大的整数编码值, value为该类型下面的盘子ID数组
  93. } ;
  94. #endif /* FillGlobalConfig_hpp */