2
0

RoadHandler.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "RoadHandler.h"
  12. #include "texts/CGeneralTextHandler.h"
  13. #include "IGameSettings.h"
  14. #include "json/JsonNode.h"
  15. #include "VCMI_Lib.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. RoadTypeHandler::RoadTypeHandler()
  18. {
  19. objects.emplace_back(new RoadType());
  20. VLC->generaltexth->registerString("core", objects[0]->getNameTextID(), "");
  21. }
  22. std::shared_ptr<RoadType> RoadTypeHandler::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<RoadType>();
  30. info->id = RoadId(index);
  31. info->identifier = identifier;
  32. info->modScope = scope;
  33. info->tilesFilename = AnimationPath::fromJson(json["tilesFilename"]);
  34. info->shortIdentifier = json["shortIdentifier"].String();
  35. info->movementCost = json["moveCost"].Integer();
  36. VLC->generaltexth->registerString(scope,info->getNameTextID(), json["text"]);
  37. return info;
  38. }
  39. const std::vector<std::string> & RoadTypeHandler::getTypeNames() const
  40. {
  41. static const std::vector<std::string> typeNames = { "road" };
  42. return typeNames;
  43. }
  44. std::vector<JsonNode> RoadTypeHandler::loadLegacyData()
  45. {
  46. size_t dataSize = VLC->engineSettings()->getInteger(EGameSettings::TEXTS_ROAD);
  47. objects.resize(dataSize);
  48. return {};
  49. }
  50. std::string RoadType::getJsonKey() const
  51. {
  52. return modScope + ":" + identifier;
  53. }
  54. std::string RoadType::getModScope() const
  55. {
  56. return modScope;
  57. }
  58. std::string RoadType::getNameTextID() const
  59. {
  60. return TextIdentifier( "road", modScope, identifier, "name" ).get();
  61. }
  62. std::string RoadType::getNameTranslated() const
  63. {
  64. return VLC->generaltexth->translate(getNameTextID());
  65. }
  66. RoadType::RoadType():
  67. id(Road::NO_ROAD),
  68. identifier("empty"),
  69. modScope("core"),
  70. movementCost(GameConstants::BASE_MOVEMENT_COST)
  71. {}
  72. VCMI_LIB_NAMESPACE_END