FillGlobalConfig.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // FillGlobalConfig.hpp
  3. // auto_fill_jewel_v3
  4. //
  5. // Created by Red on 2024/11/25.
  6. // 从 config.json 读取全局盘子和宝石配置数据
  7. #ifndef FillGlobalConfig_hpp
  8. #define FillGlobalConfig_hpp
  9. #include <stdio.h>
  10. #include "contourdata.h"
  11. #include <string>
  12. using std::string;
  13. #include "ajson5.hpp"
  14. #include <unordered_map>
  15. using std::unordered_map;
  16. #include <vector>
  17. using std::vector;
  18. #define FILLGLOBALCONFIG_JEWELSIZE_SM 0
  19. #define FILLGLOBALCONFIG_JEWELSIZE_MD 1
  20. #define FILLGLOBALCONFIG_JEWELSIZE_LG 2
  21. #define FILLGLOBALCONFIG_DIFFCULTY_NORM 0
  22. #define FILLGLOBALCONFIG_DIFFCULTY_HARD1 1
  23. #define FILLGLOBALCONFIG_DIFFCULTY_HARD2 2
  24. //#define FILLGLOBALCONFIG_PLATESIZE_SM 1
  25. #define FILLGLOBALCONFIG_PLATESIZE_MD 2
  26. #define FILLGLOBALCONFIG_PLATESIZE_LG 3
  27. struct FillGlobalConfig {
  28. //这个结构体似乎不用了
  29. struct ContourConfig {
  30. string _name;
  31. ContourData _contour ;
  32. } ;
  33. bool init(string filename) ;
  34. bool initJewelItems( string filename ) ;
  35. bool initLevelDatas( string filename ) ;
  36. bool initPlateItems( string filename ) ;
  37. bool initMoveConfigDatas( string filename ) ;
  38. bool initGridBoxDatas(string filename) ;
  39. //静态全局单例
  40. static FillGlobalConfig* getInstance() ;
  41. vector<ContourConfig> _plateContours ;
  42. vector<ContourConfig> _jewelContours ;
  43. ContourData* getContourDataByPngName(string& pngname) ;
  44. //宝石基本信息
  45. struct JewelItem {
  46. int _id ;
  47. string _category;
  48. string _jewelName;
  49. string _code1;
  50. string _code2;
  51. int _size ; // 0-SM 1-MD 2-LG
  52. float _scale;// 0.0-1.0
  53. string _pngName;
  54. string _yzName;
  55. string _contourName;
  56. float _bbWidth;
  57. float _bbHeight;
  58. string _etc; //备注信息
  59. };
  60. JewelItem* getJewelItemById(int jid){ return _mapJewelItems.find(jid)!=_mapJewelItems.end()?(&_mapJewelItems[jid]):nullptr; }
  61. int getJewelItemCount() { return _mapJewelItems.size() ; }
  62. //关卡组成数据
  63. struct LevelData {
  64. int _id ;
  65. int _subId ;
  66. int _difficulty;//难度 0-普通, 1-难 , 2-极难
  67. vector<int> _jewelIds ;
  68. vector<int> _cnts ;//宝石个数,读取的时候要把组数乘以3计算出宝石个数。
  69. } ;
  70. //levelId 是关卡主编号值, subIndex是子关卡的索引值(从0开始)
  71. LevelData* getLevelData(int levelId,int subIndex) { return (_mapLevelDatas.find(levelId)!=_mapLevelDatas.end())?(&_mapLevelDatas[levelId][subIndex]):nullptr; }
  72. int getSubLevelCount(int levelId) { return (_mapLevelDatas.find(levelId)!=_mapLevelDatas.end())?(_mapLevelDatas[levelId].size()):0; }
  73. int getLevelCount() { return _mapLevelDatas.size() ; }
  74. LevelData& getLevelDataByIndex(int index) { auto it = _mapLevelDatas.begin(); std::advance(it,index); return it->second[0] ;}
  75. //盘子基本信息
  76. struct PlateItem {
  77. int _id ;
  78. string _name;
  79. int _size ;// 0-MINI 1-SM 2-MD 3-LG
  80. string _pngName ;
  81. string _contourName;
  82. float _blx,_bly,_trx,_try ;// bl for bottom-left, tr for top-right.
  83. double _bigJewCap ;//大宝石容量
  84. float _bbwid,_bbhei ;//精灵图片尺寸
  85. int _heng ; // 1-横放。0-竖放。
  86. } ;
  87. PlateItem* getPlateItemById(int pid){ return _mapPlateItems.find(pid)!=_mapPlateItems.end()?(&_mapPlateItems[pid]):nullptr; }
  88. int getPlateItemCount( int plateSzId ) { return (_mapPlateIdArray.find(plateSzId)!=_mapPlateIdArray.end())?(_mapPlateIdArray[plateSzId].size()):0; }
  89. PlateItem* getPlateItemBySzNDirection(int plateSzId,int heng) ;
  90. //移动盘子 配置参数
  91. struct MoveConfig {
  92. MoveConfig():_id(-1),_lowestEquvSmlJewelCnt(0),_nLayer(0),_midPlateCntH(0),_midPlateCntV(0),_bigPlateCntH(0),_bigPlateCntV(0),_hard(0) {}
  93. int _id ;//1,2,3,4,5... 序号
  94. string _type ; //A,B,C 类型
  95. int _lowestEquvSmlJewelCnt ;//最少等效小宝石数量
  96. int _nLayer ; // 层数
  97. int _midPlateCntH; // 水平中盘子数量
  98. int _midPlateCntV; // 垂直中盘子数量
  99. int _bigPlateCntH; // 水平大盘子数量
  100. int _bigPlateCntV; // 垂直大盘子数量
  101. int _hard ;//3,4,5,6,7.... 难度系数
  102. } ;
  103. //目前需求可移动盘子只有两行
  104. struct MultiMoveConfig {
  105. MultiMoveConfig():_first(nullptr),_second(nullptr){}
  106. MoveConfig* _first ;
  107. MoveConfig* _second ;
  108. };
  109. int getMoveConfigCount() { return _mapMoveConfigDatas.size() ; }
  110. MoveConfig* getMoveConfigDataByIndex(int index) { auto it=_mapMoveConfigDatas.begin();std::advance(it, index);return &(it->second); }
  111. /// 计算第一个移动行可选移动方案 https://t7le908iko.feishu.cn/docx/Cn4tdr0S7o76Ffx4lrVcJtManBg Section-6
  112. /// @param equvSmCnt 全部等效小宝石数量
  113. vector<MoveConfig*> getFirstRoundMoveConfigDatas(int equvSmCnt) ;
  114. /// 计算第二个移动行可选方案 https://t7le908iko.feishu.cn/docx/Cn4tdr0S7o76Ffx4lrVcJtManBg Section-6
  115. /// @param equvSmCnt 是第一移动行剩下的等效小宝石数量
  116. vector<MoveConfig*> getSecondRoundMoveConfigDatas(int equvSmCnt) ;
  117. vector<MoveConfig*> getMoveConfigDatasByTypeAndNLayers(string type,int nlayer) ;
  118. //计算给定宝石组合对应的全部 可移动盘子的可能方案
  119. vector<MultiMoveConfig> getAllMoveConfigByJewels(LevelData& levelData) ;
  120. // 大盘子中盘子的摆放位置信息
  121. struct GridBoxCell {
  122. //Cell():_move(0),_bigIndex(0),_mid1Index(0),_mid2Index(0),_bigFilled(false),_mid1Filled(false),_mid2Filled(false){}
  123. string _name ;
  124. int _move ;//0-none, 1-1stmove, 2-2ndmove.
  125. int _bigIndex ; //-1 for none
  126. int _mid1Index ;//-1 for none
  127. int _mid2Index ;//-1 for none
  128. bool _bigFilled ;
  129. bool _mid1Filled ;
  130. bool _mid2Filled ;
  131. float _bigllx,_biglly,_mid1llx,_mid1lly,_mid2llx,_mid2lly ;
  132. } ;
  133. void clearGridBoxFilledStatus() ;
  134. GridBoxCell* getLowestUnfilledGridBox(string name,const int moveid,const int iPlateSize,ContourData::Point& retPositionLL) ;
  135. void setFilled( GridBoxCell* gbc , const int iPlateSize ) ;
  136. private:
  137. static FillGlobalConfig* _s_instance ;
  138. unordered_map<int, JewelItem> _mapJewelItems ;
  139. unordered_map<int, vector<LevelData> > _mapLevelDatas ;// key 为主关卡编号, vector<LevelData> 为子关卡数组
  140. unordered_map<int, PlateItem> _mapPlateItems ;
  141. unordered_map<int, vector<int> > _mapPlateIdArray; // key为小、中、大的整数编码值, value为该类型下面的盘子ID数组
  142. unordered_map<int, MoveConfig> _mapMoveConfigDatas ;
  143. unordered_map<string, vector<GridBoxCell> > _mapGridBoxDatas ;
  144. } ;
  145. #endif /* GlobalConfig_hpp */