M_ActivityFeedBackGiftCFG.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include "stdafx.h"
  2. #include "tinyxml2/tinyxml2.h"
  3. #include "LuaCfgHelper.h"
  4. #include <iostream>
  5. #include <boost/algorithm/string.hpp>
  6. #include "M_ActivityFeedBackGiftCFG.h"
  7. std::auto_ptr<M_ActivityFeedBackGiftCFG> M_ActivityFeedBackGiftCFG::msSingleton(nullptr);
  8. int M_ActivityFeedBackGiftCFG::GetCount()
  9. {
  10. return (int)mMapData.size();
  11. }
  12. const M_ActivityFeedBackGiftCFGData* M_ActivityFeedBackGiftCFG::GetData(int VipLv)
  13. {
  14. auto it = mMapData.find(VipLv);
  15. if (it != mMapData.end())
  16. {
  17. return &it->second;
  18. }
  19. return NULL;
  20. }
  21. const std::map<int, M_ActivityFeedBackGiftCFGData>& M_ActivityFeedBackGiftCFG::GetMapData()
  22. {
  23. return mMapData;
  24. }
  25. void M_ActivityFeedBackGiftCFG::Load()
  26. {
  27. tinyxml2::XMLDocument xmlDoc;
  28. std::string content = FileUtils::getInstance()->getStringFromFile("Config/M_ActivityFeedBackGiftCFG.xml");
  29. auto result = xmlDoc.Parse(content.c_str(), content.length());
  30. if (result != tinyxml2::XML_SUCCESS)
  31. {
  32. CCLOGERROR("Result:%d", result);
  33. CCASSERT(false, "result != tinyxml2::XML_SUCCESS");
  34. return;
  35. }
  36. auto root = xmlDoc.RootElement();
  37. if (root == NULL)
  38. {
  39. CCASSERT(false, "root == NULL");
  40. return;
  41. }
  42. auto element = root->FirstChildElement("Data");
  43. while (element != NULL)
  44. {
  45. M_ActivityFeedBackGiftCFGData data;
  46. data.mVipLv = element->IntAttribute("VipLv");
  47. {
  48. const char* Gear1 = element->Attribute("Gear1");
  49. std::vector<std::string> vecGear1;
  50. boost::split(vecGear1, Gear1, boost::is_any_of(","));
  51. int temp;
  52. for (unsigned int i = 0; i < vecGear1.size(); i++)
  53. {
  54. if (tinyxml2::XMLUtil::ToInt(vecGear1[i].c_str(), &temp))
  55. {
  56. data.mGear1.push_back(temp);
  57. }
  58. }
  59. }
  60. {
  61. const char* Gear2 = element->Attribute("Gear2");
  62. std::vector<std::string> vecGear2;
  63. boost::split(vecGear2, Gear2, boost::is_any_of(","));
  64. int temp;
  65. for (unsigned int i = 0; i < vecGear2.size(); i++)
  66. {
  67. if (tinyxml2::XMLUtil::ToInt(vecGear2[i].c_str(), &temp))
  68. {
  69. data.mGear2.push_back(temp);
  70. }
  71. }
  72. }
  73. {
  74. const char* Gear3 = element->Attribute("Gear3");
  75. std::vector<std::string> vecGear3;
  76. boost::split(vecGear3, Gear3, boost::is_any_of(","));
  77. int temp;
  78. for (unsigned int i = 0; i < vecGear3.size(); i++)
  79. {
  80. if (tinyxml2::XMLUtil::ToInt(vecGear3[i].c_str(), &temp))
  81. {
  82. data.mGear3.push_back(temp);
  83. }
  84. }
  85. }
  86. {
  87. const char* Gear4 = element->Attribute("Gear4");
  88. std::vector<std::string> vecGear4;
  89. boost::split(vecGear4, Gear4, boost::is_any_of(","));
  90. int temp;
  91. for (unsigned int i = 0; i < vecGear4.size(); i++)
  92. {
  93. if (tinyxml2::XMLUtil::ToInt(vecGear4[i].c_str(), &temp))
  94. {
  95. data.mGear4.push_back(temp);
  96. }
  97. }
  98. }
  99. {
  100. const char* Gear5 = element->Attribute("Gear5");
  101. std::vector<std::string> vecGear5;
  102. boost::split(vecGear5, Gear5, boost::is_any_of(","));
  103. int temp;
  104. for (unsigned int i = 0; i < vecGear5.size(); i++)
  105. {
  106. if (tinyxml2::XMLUtil::ToInt(vecGear5[i].c_str(), &temp))
  107. {
  108. data.mGear5.push_back(temp);
  109. }
  110. }
  111. }
  112. if (mMapData.find(data.mVipLv) != mMapData.end())std::cout <<"data refind:" << data.mVipLv << std::endl;
  113. CCASSERT(mMapData.find(data.mVipLv) == mMapData.end(), "data.mVipLv is exists");
  114. mMapData.insert(std::make_pair(data.mVipLv, data));
  115. element = element->NextSiblingElement();
  116. }
  117. CCLOG("M_ActivityFeedBackGiftCFG Loaded. Load Data:%u", mMapData.size());
  118. }
  119. void M_ActivityFeedBackGiftCFG::LoadLua()
  120. {
  121. LuaEngine::getInstance()->executeScriptFile("config/M_ActivityFeedBackGiftCFG");
  122. lua_State* L = LuaEngine::getInstance()->getLuaStack()->getLuaState();
  123. lua_getglobal(L, "M_ActivityFeedBackGiftCFG");
  124. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  125. lua_pushstring(L, "datas");
  126. lua_gettable(L, -2);
  127. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  128. lua_pushnil(L);
  129. while(lua_next(L, 2))
  130. {
  131. CCASSERT(lua_istable(L, -1) == 1, "is not table");
  132. M_ActivityFeedBackGiftCFGData data;
  133. LuaCfgHelper::readInt(L, "VipLv", data.mVipLv);
  134. LuaCfgHelper::readVectorInt(L, "Gear1", data.mGear1);
  135. LuaCfgHelper::readVectorInt(L, "Gear2", data.mGear2);
  136. LuaCfgHelper::readVectorInt(L, "Gear3", data.mGear3);
  137. LuaCfgHelper::readVectorInt(L, "Gear4", data.mGear4);
  138. LuaCfgHelper::readVectorInt(L, "Gear5", data.mGear5);
  139. if (mMapData.find(data.mVipLv) != mMapData.end())std::cout <<"data refind:" << data.mVipLv << std::endl;
  140. CCASSERT(mMapData.find(data.mVipLv) == mMapData.end(), "data.mVipLv is exists");
  141. mMapData.insert(std::make_pair(data.mVipLv, data));
  142. lua_pop(L, 1);
  143. }
  144. lua_settop(L, 0);
  145. CCLOG("M_ActivityFeedBackGiftCFG Loaded. Load Data:%u", mMapData.size());
  146. }
  147. void M_ActivityFeedBackGiftCFG::Reload()
  148. {
  149. mMapData.clear();
  150. Load();
  151. }
  152. M_ActivityFeedBackGiftCFG* M_ActivityFeedBackGiftCFG::GetSingleton()
  153. {
  154. if (msSingleton.get() == nullptr)
  155. {
  156. msSingleton.reset(new M_ActivityFeedBackGiftCFG());
  157. }
  158. return msSingleton.get();
  159. }
  160. void M_ActivityFeedBackGiftCFG::Release()
  161. {
  162. msSingleton.reset(nullptr);
  163. }