2
0

CRmgTemplateStorage.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * CRmgTemplateStorage.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CRmgTemplateStorage.h"
  12. #include "CRmgTemplate.h"
  13. #include "../serializer/JsonDeserializer.h"
  14. using namespace rmg;
  15. void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
  16. {
  17. //unused
  18. loadObject(scope, name, data);
  19. }
  20. void CRmgTemplateStorage::loadObject(std::string scope, std::string name, const JsonNode & data)
  21. {
  22. try
  23. {
  24. JsonDeserializer handler(nullptr, data);
  25. auto fullKey = normalizeIdentifier(scope, "core", name); //actually it's not used
  26. templates[fullKey].setId(name);
  27. templates[fullKey].serializeJson(handler);
  28. templates[fullKey].validate();
  29. }
  30. catch(const std::exception & e)
  31. {
  32. logGlobal->error("Template %s has errors. Message: %s.", name, std::string(e.what()));
  33. }
  34. }
  35. std::vector<bool> CRmgTemplateStorage::getDefaultAllowed() const
  36. {
  37. //all templates are allowed
  38. return std::vector<bool>();
  39. }
  40. std::vector<JsonNode> CRmgTemplateStorage::loadLegacyData(size_t dataSize)
  41. {
  42. return std::vector<JsonNode>();
  43. //it would be cool to load old rmg.txt files
  44. }
  45. const CRmgTemplate * CRmgTemplateStorage::getTemplate(const std::string & templateName) const
  46. {
  47. auto iter = templates.find(templateName);
  48. if(iter==templates.end())
  49. return nullptr;
  50. return &iter->second;
  51. }
  52. std::vector<const CRmgTemplate *> CRmgTemplateStorage::getTemplates() const
  53. {
  54. std::vector<const CRmgTemplate *> result;
  55. for(auto i=templates.cbegin(); i!=templates.cend(); ++i)
  56. {
  57. result.push_back(&i->second);
  58. }
  59. return result;
  60. }