RoadHandler.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. }
  19. RoadType * RoadTypeHandler::loadFromJson(
  20. const std::string & scope,
  21. const JsonNode & json,
  22. const std::string & identifier,
  23. size_t index)
  24. {
  25. RoadType * info = new RoadType;
  26. info->id = RoadId(index);
  27. if (identifier.find(':') == std::string::npos)
  28. info->identifier = scope + ":" + identifier;
  29. else
  30. info->identifier = identifier;
  31. info->tilesFilename = json["tilesFilename"].String();
  32. info->shortIdentifier = json["shortIdentifier"].String();
  33. info->movementCost = json["moveCost"].Integer();
  34. VLC->generaltexth->registerString(info->getNameTextID(), json["text"].String());
  35. return info;
  36. }
  37. const std::vector<std::string> & RoadTypeHandler::getTypeNames() const
  38. {
  39. static const std::vector<std::string> typeNames = { "road" };
  40. return typeNames;
  41. }
  42. std::vector<JsonNode> RoadTypeHandler::loadLegacyData(size_t dataSize)
  43. {
  44. objects.resize(dataSize);
  45. return {};
  46. }
  47. std::vector<bool> RoadTypeHandler::getDefaultAllowed() const
  48. {
  49. return {};
  50. }
  51. std::string RoadType::getNameTextID() const
  52. {
  53. return TextIdentifier( "road", identifier, "name" ).get();
  54. }
  55. std::string RoadType::getNameTranslated() const
  56. {
  57. return VLC->generaltexth->translate(getNameTextID());
  58. }
  59. RoadType::RoadType():
  60. id(Road::NO_ROAD),
  61. identifier("core:empty"),
  62. movementCost(GameConstants::BASE_MOVEMENT_COST)
  63. {}
  64. VCMI_LIB_NAMESPACE_END