1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- //
- // IAPConf.hpp
- // TileManor
- //
- // Created by 徐炼新 on 2024/1/16.
- //
- #ifndef IAPConf_hpp
- #define IAPConf_hpp
- #include "cocos2d.h"
- #include "RUBaseConf.h"
- #include "RUUtils.h"
- USING_NS_CC;
- typedef struct {
- std::string name;
- std::string count;
- } ItemInGoods;
- typedef std::vector<ItemInGoods> AreaInGooods;
- typedef struct {
- std::string id;
- std::string type;
- std::string style;
- std::string slogon;
- std::string hint;
- std::string cost;
- cocos2d::Size sz;
- bool always;
- int idxGT2;
- std::vector<AreaInGooods> areas;
- std::string serialize() const {
- std::string ret;
- ret.append(id).append("|").append(cost).append("|").append(std::to_string(idxGT2));
- for (auto& area : areas) {
- for (auto& item : area) {
- ret.append("|").append(item.name).append("|").append(item.count);
- }
- ret.append("|");
- }
- return ret;
- }
- void deserialize(const std::string& str) {
- auto parts = redutils::parseAsStringList(str, "|");
- if (parts.size() < 5) {
- return;
- }
- id = parts.at(0);
- cost = parts.at(1);
- idxGT2 = atoi(parts.at(2).c_str());
- int idx = 3;
- while (idx < parts.size()) {
- AreaInGooods area;
- while (idx < parts.size() && parts.at(idx).size() > 0) {
- ItemInGoods item;
- item.name = parts.at(idx);
- item.count = parts.at(idx+1);
- area.push_back(item);
- idx += 2;
- }
- areas.push_back(area);
- idx++;
- }
- }
- } GoodsInfo;
- class IAPConf {
- public:
- static IAPConf* getInstance();
-
- void initWith(redutils::BaseConf*);
-
- void getAllGoods(std::vector<GoodsInfo>&);
-
- private:
- IAPConf() = default;
-
- private:
- static IAPConf* _instance;
-
- redutils::BaseConf* _bc = nullptr;
- };
- #endif /* IAPConf_hpp */
|