RoadHandler.cpp 1.9 KB

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