RoadHandler.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. assert(identifier.find(':') == std::string::npos);
  26. RoadType * info = new RoadType;
  27. info->id = RoadId(index);
  28. if (identifier.find(':') == std::string::npos)
  29. info->identifier = scope + ":" + identifier;
  30. else
  31. info->identifier = identifier;
  32. info->tilesFilename = json["tilesFilename"].String();
  33. info->shortIdentifier = json["shortIdentifier"].String();
  34. info->movementCost = json["moveCost"].Integer();
  35. VLC->generaltexth->registerString(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(size_t dataSize)
  44. {
  45. objects.resize(dataSize);
  46. return {};
  47. }
  48. std::vector<bool> RoadTypeHandler::getDefaultAllowed() const
  49. {
  50. return {};
  51. }
  52. std::string RoadType::getNameTextID() const
  53. {
  54. return TextIdentifier( "road", identifier, "name" ).get();
  55. }
  56. std::string RoadType::getNameTranslated() const
  57. {
  58. return VLC->generaltexth->translate(getNameTextID());
  59. }
  60. RoadType::RoadType():
  61. id(Road::NO_ROAD),
  62. identifier("core:empty"),
  63. movementCost(GameConstants::BASE_MOVEMENT_COST)
  64. {}
  65. VCMI_LIB_NAMESPACE_END