RoadHandler.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. info->identifier = identifier;
  30. info->modScope = scope;
  31. info->tilesFilename = json["tilesFilename"].String();
  32. info->shortIdentifier = json["shortIdentifier"].String();
  33. info->movementCost = json["moveCost"].Integer();
  34. VLC->generaltexth->registerString(scope,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::getJsonKey() const
  52. {
  53. return modScope + ":" + identifier;
  54. }
  55. std::string RoadType::getNameTextID() const
  56. {
  57. return TextIdentifier( "road", modScope, identifier, "name" ).get();
  58. }
  59. std::string RoadType::getNameTranslated() const
  60. {
  61. return VLC->generaltexth->translate(getNameTextID());
  62. }
  63. RoadType::RoadType():
  64. id(Road::NO_ROAD),
  65. identifier("empty"),
  66. modScope("core"),
  67. movementCost(GameConstants::BASE_MOVEMENT_COST)
  68. {}
  69. VCMI_LIB_NAMESPACE_END