SpellSchoolHandler.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "../GameLibrary.h"
  13. #include "../json/JsonNode.h"
  14. #include "../texts/CGeneralTextHandler.h"
  15. #include "../texts/TextIdentifier.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. std::string spells::SpellSchoolType::getNameTextID() const
  18. {
  19. return TextIdentifier( "spellSchool", modScope, identifier, "name" ).get();
  20. }
  21. std::string spells::SpellSchoolType::getNameTranslated() const
  22. {
  23. return LIBRARY->generaltexth->translate(getNameTextID());
  24. }
  25. std::vector<JsonNode> SpellSchoolHandler::loadLegacyData()
  26. {
  27. objects.resize(4);
  28. return std::vector<JsonNode>(4, JsonNode(JsonMap()));
  29. }
  30. std::shared_ptr<spells::SpellSchoolType> SpellSchoolHandler::loadObjectImpl(std::string scope, std::string name, const JsonNode & data, size_t index)
  31. {
  32. auto ret = std::make_shared<spells::SpellSchoolType>();
  33. ret->id = SpellSchool(index);
  34. ret->modScope = scope;
  35. ret->identifier = name;
  36. ret->spellBordersPath = AnimationPath::fromJson(data["schoolBorders"]);
  37. ret->schoolBookmarkPath = AnimationPath::fromJson(data["schoolBookmark"]);
  38. ret->schoolHeaderPath = ImagePath::fromJson(data["schoolHeader"]);
  39. LIBRARY->generaltexth->registerString(scope, ret->getNameTextID(), data["name"]);
  40. return ret;
  41. }
  42. /// loads single object into game. Scope is namespace of this object, same as name of source mod
  43. void SpellSchoolHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
  44. {
  45. objects.push_back(loadObjectImpl(scope, name, data, objects.size()));
  46. registerObject(scope, "spellSchool", name, objects.back()->getIndex());
  47. }
  48. void SpellSchoolHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
  49. {
  50. assert(objects[index] == nullptr); // ensure that this id was not loaded before
  51. objects[index] = loadObjectImpl(scope, name, data, index);
  52. registerObject(scope, "spellSchool", name, objects[index]->getIndex());
  53. }
  54. std::vector<SpellSchool> SpellSchoolHandler::getAllObjects() const
  55. {
  56. std::vector<SpellSchool> result;
  57. for (const auto & school : objects)
  58. result.push_back(school->id);
  59. return result;
  60. }
  61. VCMI_LIB_NAMESPACE_END