RoadHandler.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "CModHandler.h"
  13. #include "CGeneralTextHandler.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. RoadTypeHandler::RoadTypeHandler()
  16. {
  17. objects.push_back(new RoadType);
  18. VLC->generaltexth->registerString("core", objects[0]->getNameTextID(), "");
  19. }
  20. RoadType * RoadTypeHandler::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. RoadType * info = new RoadType;
  28. info->id = RoadId(index);
  29. if (identifier.find(':') == std::string::npos)
  30. info->identifier = scope + ":" + identifier;
  31. else
  32. info->identifier = identifier;
  33. info->tilesFilename = json["tilesFilename"].String();
  34. info->shortIdentifier = json["shortIdentifier"].String();
  35. info->movementCost = json["moveCost"].Integer();
  36. VLC->generaltexth->registerString(scope,info->getNameTextID(), json["text"].String());
  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(size_t dataSize)
  45. {
  46. objects.resize(dataSize);
  47. return {};
  48. }
  49. std::vector<bool> RoadTypeHandler::getDefaultAllowed() const
  50. {
  51. return {};
  52. }
  53. std::string RoadType::getNameTextID() const
  54. {
  55. return TextIdentifier( "road", 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. movementCost(GameConstants::BASE_MOVEMENT_COST)
  65. {}
  66. VCMI_LIB_NAMESPACE_END