IAPConf.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // IAPConf.hpp
  3. // TileManor
  4. //
  5. // Created by 徐炼新 on 2024/1/16.
  6. //
  7. #ifndef IAPConf_hpp
  8. #define IAPConf_hpp
  9. #include "cocos2d.h"
  10. #include "RUBaseConf.h"
  11. #include "RUUtils.h"
  12. USING_NS_CC;
  13. typedef struct {
  14. std::string name;
  15. std::string count;
  16. } ItemInGoods;
  17. typedef std::vector<ItemInGoods> AreaInGooods;
  18. typedef struct {
  19. std::string id;
  20. std::string type;
  21. std::string style;
  22. std::string slogon;
  23. std::string hint;
  24. std::string cost;
  25. cocos2d::Size sz;
  26. bool always;
  27. int idxGT2;
  28. std::vector<AreaInGooods> areas;
  29. std::string serialize() const {
  30. std::string ret;
  31. ret.append(id).append("|").append(cost).append("|").append(std::to_string(idxGT2));
  32. for (auto& area : areas) {
  33. for (auto& item : area) {
  34. ret.append("|").append(item.name).append("|").append(item.count);
  35. }
  36. ret.append("|");
  37. }
  38. return ret;
  39. }
  40. void deserialize(const std::string& str) {
  41. auto parts = redutils::parseAsStringList(str, "|");
  42. if (parts.size() < 5) {
  43. return;
  44. }
  45. id = parts.at(0);
  46. cost = parts.at(1);
  47. idxGT2 = atoi(parts.at(2).c_str());
  48. int idx = 3;
  49. while (idx < parts.size()) {
  50. AreaInGooods area;
  51. while (idx < parts.size() && parts.at(idx).size() > 0) {
  52. ItemInGoods item;
  53. item.name = parts.at(idx);
  54. item.count = parts.at(idx+1);
  55. area.push_back(item);
  56. idx += 2;
  57. }
  58. areas.push_back(area);
  59. idx++;
  60. }
  61. }
  62. } GoodsInfo;
  63. class IAPConf {
  64. public:
  65. static IAPConf* getInstance();
  66. void initWith(redutils::BaseConf*);
  67. void getAllGoods(std::vector<GoodsInfo>&);
  68. private:
  69. IAPConf() = default;
  70. private:
  71. static IAPConf* _instance;
  72. redutils::BaseConf* _bc = nullptr;
  73. };
  74. #endif /* IAPConf_hpp */