SpellSchoolHandler.cpp 1.6 KB

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