RiverHandler.cpp 1.9 KB

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