RiverHandler.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Terrain.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 "RiverHandler.h"
  12. #include "texts/CGeneralTextHandler.h"
  13. #include "GameSettings.h"
  14. #include "json/JsonNode.h"
  15. #include "VCMI_Lib.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. RiverTypeHandler::RiverTypeHandler()
  18. {
  19. objects.emplace_back(new RiverType());
  20. VLC->generaltexth->registerString("core", objects[0]->getNameTextID(), "");
  21. }
  22. std::shared_ptr<RiverType> RiverTypeHandler::loadFromJson(
  23. const std::string & scope,
  24. const JsonNode & json,
  25. const std::string & identifier,
  26. size_t index)
  27. {
  28. assert(identifier.find(':') == std::string::npos);
  29. auto info = std::make_shared<RiverType>();
  30. info->id = RiverId(index);
  31. info->identifier = identifier;
  32. info->modScope = scope;
  33. info->tilesFilename = AnimationPath::fromJson(json["tilesFilename"]);
  34. info->shortIdentifier = json["shortIdentifier"].String();
  35. info->deltaName = json["delta"].String();
  36. for(const auto & t : json["paletteAnimation"].Vector())
  37. {
  38. RiverPaletteAnimation element{
  39. static_cast<int>(t["start"].Integer()),
  40. static_cast<int>(t["length"].Integer())
  41. };
  42. info->paletteAnimation.push_back(element);
  43. }
  44. VLC->generaltexth->registerString(scope, info->getNameTextID(), json["text"].String());
  45. return info;
  46. }
  47. const std::vector<std::string> & RiverTypeHandler::getTypeNames() const
  48. {
  49. static const std::vector<std::string> typeNames = { "river" };
  50. return typeNames;
  51. }
  52. std::vector<JsonNode> RiverTypeHandler::loadLegacyData()
  53. {
  54. size_t dataSize = VLC->settings()->getInteger(EGameSettings::TEXTS_RIVER);
  55. objects.resize(dataSize);
  56. return {};
  57. }
  58. std::string RiverType::getJsonKey() const
  59. {
  60. return modScope + ":" + identifier;
  61. }
  62. std::string RiverType::getModScope() const
  63. {
  64. return modScope;
  65. }
  66. std::string RiverType::getNameTextID() const
  67. {
  68. return TextIdentifier( "river", modScope, identifier, "name" ).get();
  69. }
  70. std::string RiverType::getNameTranslated() const
  71. {
  72. return VLC->generaltexth->translate(getNameTextID());
  73. }
  74. RiverType::RiverType():
  75. id(River::NO_RIVER),
  76. identifier("empty"),
  77. modScope("core")
  78. {}
  79. VCMI_LIB_NAMESPACE_END