RiverHandler.cpp 2.1 KB

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