IAPConf.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // IAPConf.cpp
  3. // TileManor
  4. //
  5. // Created by 徐炼新 on 2024/1/16.
  6. //
  7. #include "IAPConf.hpp"
  8. IAPConf* IAPConf::_instance = nullptr;
  9. IAPConf* IAPConf::getInstance() {
  10. if (_instance == nullptr) {
  11. _instance = new IAPConf();
  12. }
  13. return _instance;
  14. }
  15. void IAPConf::initWith(redutils::BaseConf* bc) {
  16. _bc = bc;
  17. }
  18. void IAPConf::getAllGoods(std::vector<GoodsInfo>& goods) {
  19. // 清空
  20. goods.clear();
  21. // 获取
  22. int cnt = atoi(_bc->getConf("goods", "count").c_str());
  23. for (int i=1; i<=cnt; i++) {
  24. GoodsInfo gi;
  25. std::string key = "goods_" + Value(i).asString();
  26. gi.id = _bc->getConf("goods", key+":id");
  27. gi.type = _bc->getConf("goods", key+":type");
  28. gi.style = _bc->getConf("goods", key+":style");
  29. gi.slogon = _bc->getConf("goods", key+":slogon");
  30. gi.hint = _bc->getConf("goods", key+":hint");
  31. gi.cost = _bc->getConf("goods", key+":cost");
  32. gi.always = _bc->getConf("goods", key+":always") == "1";
  33. gi.idxGT2 = Value(_bc->getConf("goods", key+":idxGT2")).asInt();
  34. {
  35. const auto& szStr = _bc->getConf("goods", key+":size");
  36. int nPos = szStr.find(",");
  37. gi.sz.width = atoi(szStr.substr(0, nPos).c_str());
  38. gi.sz.height = atoi(szStr.substr(nPos+1).c_str());
  39. }
  40. // areas
  41. int areaCnt = atoi(_bc->getConf("goods", key+":areas:count").c_str());
  42. for (int j=1; j<=areaCnt; j++) {
  43. auto& rewards = _bc->getConf("goods", key+":areas:area_"+Value(j).asString());
  44. // 解析得到各个奖励信息
  45. auto parseItem = [](std::string str, AreaInGooods& aig) {
  46. int nPos = str.find(":");
  47. std::string name = str.substr(0, nPos);
  48. std::string cnt = str.substr(nPos+1);
  49. aig.push_back({name, cnt});
  50. };
  51. AreaInGooods aig;
  52. int startPos = 0;
  53. int nPos = rewards.find(",");
  54. string conf = rewards.substr(startPos, nPos);
  55. while (nPos != string::npos) {
  56. parseItem(conf, aig);
  57. startPos = nPos + 1;
  58. nPos = rewards.find(",", startPos);
  59. conf = rewards.substr(startPos, nPos-startPos);
  60. }
  61. parseItem(conf, aig);
  62. gi.areas.push_back(aig);
  63. }
  64. goods.push_back(gi);
  65. }
  66. }