2
0

SpellSchoolHandler.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * SpellSchoolHandler.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 "SpellSchoolHandler.h"
  12. #include "../json/JsonNode.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. std::vector<JsonNode> SpellSchoolHandler::loadLegacyData()
  15. {
  16. objects.resize(4);
  17. return std::vector<JsonNode>(4, JsonNode(JsonMap()));
  18. }
  19. std::shared_ptr<spells::SpellSchoolType> SpellSchoolHandler::loadObjectImpl(std::string scope, std::string name, const JsonNode & data, size_t index)
  20. {
  21. auto ret = std::make_shared<spells::SpellSchoolType>();
  22. ret->id = SpellSchool(index);
  23. ret->jsonName = name;
  24. ret->spellBordersPath = AnimationPath::fromJson(data["schoolBorders"]);
  25. return ret;
  26. }
  27. /// loads single object into game. Scope is namespace of this object, same as name of source mod
  28. void SpellSchoolHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
  29. {
  30. objects.push_back(loadObjectImpl(scope, name, data, objects.size()));
  31. registerObject(scope, "spellSchool", name, objects.back()->getIndex());
  32. }
  33. void SpellSchoolHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
  34. {
  35. assert(objects[index] == nullptr); // ensure that this id was not loaded before
  36. objects[index] = loadObjectImpl(scope, name, data, index);
  37. registerObject(scope, "spellSchool", name, objects[index]->getIndex());
  38. }
  39. std::vector<SpellSchool> SpellSchoolHandler::getAllObjects() const
  40. {
  41. std::vector<SpellSchool> result;
  42. for (const auto & school : objects)
  43. result.push_back(school->id);
  44. return result;
  45. }
  46. VCMI_LIB_NAMESPACE_END