// // FillGlobalConfig.hpp // auto_fill_jewel_v3 // // Created by Red on 2024/11/25. // 从 config.json 读取全局盘子和宝石配置数据 #ifndef FillGlobalConfig_hpp #define FillGlobalConfig_hpp #include #include "contourdata.h" #include using std::string; #include "ajson5.hpp" #include using std::unordered_map; #include using std::vector; #define FILLGLOBALCONFIG_JEWELSIZE_SM 0 #define FILLGLOBALCONFIG_JEWELSIZE_MD 1 #define FILLGLOBALCONFIG_JEWELSIZE_LG 2 #define FILLGLOBALCONFIG_DIFFCULTY_NORM 0 #define FILLGLOBALCONFIG_DIFFCULTY_HARD1 1 #define FILLGLOBALCONFIG_DIFFCULTY_HARD2 2 //#define FILLGLOBALCONFIG_PLATESIZE_SM 1 #define FILLGLOBALCONFIG_PLATESIZE_MD 2 #define FILLGLOBALCONFIG_PLATESIZE_LG 3 struct FillGlobalConfig { //这个结构体似乎不用了 struct ContourConfig { string _name; ContourData _contour ; } ; bool init(string filename) ; bool initJewelItems( string filename ) ; bool initLevelDatas( string filename ) ; bool initPlateItems( string filename ) ; bool initMoveConfigDatas( string filename ) ; bool initGridBoxDatas(string filename) ; //静态全局单例 static FillGlobalConfig* getInstance() ; vector _plateContours ; vector _jewelContours ; ContourData* getContourDataByPngName(string& pngname) ; //宝石基本信息 struct JewelItem { int _id ; string _category; string _jewelName; string _code1; string _code2; int _size ; // 0-SM 1-MD 2-LG float _scale;// 0.0-1.0 string _pngName; string _yzName; string _contourName; float _bbWidth; float _bbHeight; string _etc; //备注信息 }; JewelItem* getJewelItemById(int jid){ return _mapJewelItems.find(jid)!=_mapJewelItems.end()?(&_mapJewelItems[jid]):nullptr; } int getJewelItemCount() { return _mapJewelItems.size() ; } //关卡组成数据 struct LevelData { int _id ; int _subId ; int _difficulty;//难度 0-普通, 1-难 , 2-极难 vector _jewelIds ; vector _cnts ;//宝石个数,读取的时候要把组数乘以3计算出宝石个数。 } ; //levelId 是关卡主编号值, subIndex是子关卡的索引值(从0开始) LevelData* getLevelData(int levelId,int subIndex) { return (_mapLevelDatas.find(levelId)!=_mapLevelDatas.end())?(&_mapLevelDatas[levelId][subIndex]):nullptr; } int getSubLevelCount(int levelId) { return (_mapLevelDatas.find(levelId)!=_mapLevelDatas.end())?(_mapLevelDatas[levelId].size()):0; } int getLevelCount() { return _mapLevelDatas.size() ; } LevelData& getLevelDataByIndex(int index) { auto it = _mapLevelDatas.begin(); std::advance(it,index); return it->second[0] ;} //盘子基本信息 struct PlateItem { int _id ; string _name; int _size ;// 0-MINI 1-SM 2-MD 3-LG string _pngName ; string _contourName; float _blx,_bly,_trx,_try ;// bl for bottom-left, tr for top-right. double _bigJewCap ;//大宝石容量 float _bbwid,_bbhei ;//精灵图片尺寸 int _heng ; // 1-横放。0-竖放。 } ; PlateItem* getPlateItemById(int pid){ return _mapPlateItems.find(pid)!=_mapPlateItems.end()?(&_mapPlateItems[pid]):nullptr; } int getPlateItemCount( int plateSzId ) { return (_mapPlateIdArray.find(plateSzId)!=_mapPlateIdArray.end())?(_mapPlateIdArray[plateSzId].size()):0; } PlateItem* getPlateItemBySzNDirection(int plateSzId,int heng) ; //移动盘子 配置参数 struct MoveConfig { MoveConfig():_id(-1),_lowestEquvSmlJewelCnt(0),_nLayer(0),_midPlateCntH(0),_midPlateCntV(0),_bigPlateCntH(0),_bigPlateCntV(0),_hard(0) {} int _id ;//1,2,3,4,5... 序号 string _type ; //A,B,C 类型 int _lowestEquvSmlJewelCnt ;//最少等效小宝石数量 int _nLayer ; // 层数 int _midPlateCntH; // 水平中盘子数量 int _midPlateCntV; // 垂直中盘子数量 int _bigPlateCntH; // 水平大盘子数量 int _bigPlateCntV; // 垂直大盘子数量 int _hard ;//3,4,5,6,7.... 难度系数 } ; //目前需求可移动盘子只有两行 struct MultiMoveConfig { MultiMoveConfig():_first(nullptr),_second(nullptr){} MoveConfig* _first ; MoveConfig* _second ; }; int getMoveConfigCount() { return _mapMoveConfigDatas.size() ; } MoveConfig* getMoveConfigDataByIndex(int index) { auto it=_mapMoveConfigDatas.begin();std::advance(it, index);return &(it->second); } /// 计算第一个移动行可选移动方案 https://t7le908iko.feishu.cn/docx/Cn4tdr0S7o76Ffx4lrVcJtManBg Section-6 /// @param equvSmCnt 全部等效小宝石数量 vector getFirstRoundMoveConfigDatas(int equvSmCnt) ; /// 计算第二个移动行可选方案 https://t7le908iko.feishu.cn/docx/Cn4tdr0S7o76Ffx4lrVcJtManBg Section-6 /// @param equvSmCnt 是第一移动行剩下的等效小宝石数量 vector getSecondRoundMoveConfigDatas(int equvSmCnt) ; vector getMoveConfigDatasByTypeAndNLayers(string type,int nlayer) ; //计算给定宝石组合对应的全部 可移动盘子的可能方案 vector getAllMoveConfigByJewels(LevelData& levelData) ; // 大盘子中盘子的摆放位置信息 struct GridBoxCell { //Cell():_move(0),_bigIndex(0),_mid1Index(0),_mid2Index(0),_bigFilled(false),_mid1Filled(false),_mid2Filled(false){} string _name ; int _move ;//0-none, 1-1stmove, 2-2ndmove. int _bigIndex ; //-1 for none int _mid1Index ;//-1 for none int _mid2Index ;//-1 for none bool _bigFilled ; bool _mid1Filled ; bool _mid2Filled ; float _bigllx,_biglly,_mid1llx,_mid1lly,_mid2llx,_mid2lly ; } ; void clearGridBoxFilledStatus() ; GridBoxCell* getLowestUnfilledGridBox(string name,const int moveid,const int iPlateSize,ContourData::Point& retPositionLL) ; void setFilled( GridBoxCell* gbc , const int iPlateSize ) ; private: static FillGlobalConfig* _s_instance ; unordered_map _mapJewelItems ; unordered_map > _mapLevelDatas ;// key 为主关卡编号, vector 为子关卡数组 unordered_map _mapPlateItems ; unordered_map > _mapPlateIdArray; // key为小、中、大的整数编码值, value为该类型下面的盘子ID数组 unordered_map _mapMoveConfigDatas ; unordered_map > _mapGridBoxDatas ; } ; #endif /* GlobalConfig_hpp */