Fish_ArmatureCFG.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include "stdafx.h"
  2. #include <cassert>
  3. #include <fstream>
  4. #include <iostream>
  5. #include <iostream>
  6. #include <boost/smart_ptr.hpp>
  7. #include <boost/algorithm/string.hpp>
  8. #include "tinyxml2.h"
  9. #include "Fish_ArmatureCFG.h"
  10. #include "FileEncrypt.h"
  11. std::auto_ptr<Fish_ArmatureCFG> Fish_ArmatureCFG::msSingleton(nullptr);
  12. int Fish_ArmatureCFG::GetCount()
  13. {
  14. return (int)mMapData.size();
  15. }
  16. const Fish_ArmatureCFGData* Fish_ArmatureCFG::GetData(int ID)
  17. {
  18. auto it = mMapData.find(ID);
  19. if (it != mMapData.end())
  20. {
  21. return &it->second;
  22. }
  23. return NULL;
  24. }
  25. boost::unordered_map<int, Fish_ArmatureCFGData>& Fish_ArmatureCFG::GetMapData()
  26. {
  27. return mMapData;
  28. }
  29. void Fish_ArmatureCFG::Reload()
  30. {
  31. mMapData.clear();
  32. Load();
  33. }
  34. void Fish_ArmatureCFG::Load(const std::string& path)
  35. {
  36. std::ifstream readStream(path, std::ios::binary);
  37. if (!readStream.is_open())
  38. {
  39. assert(false);
  40. return;
  41. }
  42. readStream.seekg(0, std::ios::end);
  43. int fileSize = readStream.tellg();
  44. boost::shared_array<char> buffer(new char[fileSize+1]);
  45. buffer.get()[fileSize] = '\0';
  46. readStream.seekg(0, std::ios::beg);
  47. readStream.read(buffer.get(), fileSize);
  48. readStream.close();
  49. FileEncrypt::decryptBuffer( buffer, fileSize );
  50. tinyxml2::XMLDocument xmlDoc;
  51. auto result = xmlDoc.Parse(buffer.get(), fileSize);
  52. if (result != tinyxml2::XML_SUCCESS)
  53. {
  54. assert(false);
  55. return;
  56. }
  57. auto root = xmlDoc.RootElement();
  58. if (root == NULL)
  59. {
  60. assert(false);
  61. return;
  62. }
  63. auto element = root->FirstChildElement("Data");
  64. while (element != NULL)
  65. {
  66. Fish_ArmatureCFGData data;
  67. data.mID = element->IntAttribute("ID");
  68. data.mName = element->Attribute("Name");
  69. data.mResType = element->IntAttribute("ResType");
  70. data.mResName = element->Attribute("ResName");
  71. data.mResPath = element->Attribute("ResPath");
  72. data.mMoveAction = element->Attribute("MoveAction");
  73. data.mDieAction = element->Attribute("DieAction");
  74. data.mColor = element->IntAttribute("Color");
  75. data.mScale = element->FloatAttribute("Scale");
  76. data.mEnableFlipped = element->BoolAttribute("EnableFlipped");
  77. {
  78. const char* Collider = element->Attribute("Collider");
  79. std::vector<std::string> vecCollider;
  80. boost::split(vecCollider, Collider, boost::is_any_of(","));
  81. float temp;
  82. for (unsigned int i = 0; i < vecCollider.size(); i++)
  83. {
  84. if (tinyxml2::XMLUtil::ToFloat(vecCollider[i].c_str(), &temp))
  85. {
  86. data.mCollider.push_back(temp);
  87. }
  88. }
  89. }
  90. {
  91. const char* AttachArmatures = element->Attribute("AttachArmatures");
  92. std::vector<std::string> vecAttachArmatures;
  93. boost::split(vecAttachArmatures, AttachArmatures, boost::is_any_of(","));
  94. int temp;
  95. for (unsigned int i = 0; i < vecAttachArmatures.size(); i++)
  96. {
  97. if (tinyxml2::XMLUtil::ToInt(vecAttachArmatures[i].c_str(), &temp))
  98. {
  99. data.mAttachArmatures.push_back(temp);
  100. }
  101. }
  102. }
  103. data.mFixFlag = element->Attribute("FixFlag");
  104. {
  105. const char* Circles = element->Attribute("Circles");
  106. std::vector<std::string> vecCircles;
  107. boost::split(vecCircles, Circles, boost::is_any_of(","));
  108. for (unsigned int i = 0; i < vecCircles.size(); i++)
  109. {
  110. data.mCircles.push_back(vecCircles[i]);
  111. }
  112. }
  113. {
  114. const char* AttachParticles = element->Attribute("AttachParticles");
  115. std::vector<std::string> vecAttachParticles;
  116. boost::split(vecAttachParticles, AttachParticles, boost::is_any_of(","));
  117. for (unsigned int i = 0; i < vecAttachParticles.size(); i++)
  118. {
  119. data.mAttachParticles.push_back(vecAttachParticles[i]);
  120. }
  121. }
  122. if (mMapData.find(data.mID) != mMapData.end())std::cout <<"data refind:" << data.mID << std::endl;
  123. assert(mMapData.find(data.mID) == mMapData.end());
  124. mMapData.insert(std::make_pair(data.mID, data));
  125. element = element->NextSiblingElement();
  126. }
  127. }
  128. void Fish_ArmatureCFG::Load()
  129. {
  130. Load("../Config/Fish_ArmatureCFG.xml");
  131. }
  132. Fish_ArmatureCFG* Fish_ArmatureCFG::GetSingleton()
  133. {
  134. if (msSingleton.get() == nullptr)
  135. {
  136. msSingleton.reset(new Fish_ArmatureCFG());
  137. }
  138. return msSingleton.get();
  139. }