IAPConf.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. int cnt = atoi(_bc->getConf("goods", "count").c_str());
  20. for (int i=1; i<=cnt; i++) {
  21. GoodsInfo gi;
  22. std::string key = "goods_" + Value(i).asString();
  23. gi.id = _bc->getConf("goods", key+":id");
  24. gi.type = _bc->getConf("goods", key+":type");
  25. gi.style = _bc->getConf("goods", key+":style");
  26. gi.slogon = _bc->getConf("goods", key+":slogon");
  27. gi.hint = _bc->getConf("goods", key+":hint");
  28. gi.cost = _bc->getConf("goods", key+":cost");
  29. gi.always = _bc->getConf("goods", key+":always") == "1";
  30. gi.idxGT2 = Value(_bc->getConf("goods", key+":idxGT2")).asInt();
  31. {
  32. const auto& szStr = _bc->getConf("goods", key+":size");
  33. int nPos = szStr.find(",");
  34. gi.sz.width = atoi(szStr.substr(0, nPos).c_str());
  35. gi.sz.height = atoi(szStr.substr(nPos+1).c_str());
  36. }
  37. // areas
  38. int areaCnt = atoi(_bc->getConf("goods", key+":areas:count").c_str());
  39. for (int j=1; j<=areaCnt; j++) {
  40. auto& rewards = _bc->getConf("goods", key+":areas:area_"+Value(j).asString());
  41. // 解析得到各个奖励信息
  42. auto parseItem = [](std::string str, AreaInGooods& aig) {
  43. int nPos = str.find(":");
  44. std::string name = str.substr(0, nPos);
  45. std::string cnt = str.substr(nPos+1);
  46. aig.push_back({name, cnt});
  47. };
  48. AreaInGooods aig;
  49. int startPos = 0;
  50. int nPos = rewards.find(",");
  51. string conf = rewards.substr(startPos, nPos);
  52. while (nPos != string::npos) {
  53. parseItem(conf, aig);
  54. startPos = nPos + 1;
  55. nPos = rewards.find(",", startPos);
  56. conf = rewards.substr(startPos, nPos-startPos);
  57. }
  58. parseItem(conf, aig);
  59. gi.areas.push_back(aig);
  60. }
  61. goods.push_back(gi);
  62. }
  63. }