BattleFieldHandler.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * BattleFieldHandler.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 <vcmi/Entity.h>
  12. #include "BattleFieldHandler.h"
  13. #include "JsonNode.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. BattleFieldInfo * BattleFieldHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index)
  16. {
  17. assert(identifier.find(':') == std::string::npos);
  18. auto * info = new BattleFieldInfo(BattleField(index), identifier);
  19. info->modScope = scope;
  20. info->graphics = ImagePath::fromJson(json["graphics"]);
  21. info->icon = json["icon"].String();
  22. info->name = json["name"].String();
  23. for(const auto & b : json["bonuses"].Vector())
  24. {
  25. auto bonus = JsonUtils::parseBonus(b);
  26. bonus->source = BonusSource::TERRAIN_OVERLAY;
  27. bonus->sid = BonusSourceID(info->getId());
  28. bonus->duration = BonusDuration::ONE_BATTLE;
  29. info->bonuses.push_back(bonus);
  30. }
  31. info->isSpecial = json["isSpecial"].Bool();
  32. for(auto node : json["impassableHexes"].Vector())
  33. info->impassableHexes.emplace_back(node.Integer());
  34. return info;
  35. }
  36. std::vector<JsonNode> BattleFieldHandler::loadLegacyData()
  37. {
  38. return std::vector<JsonNode>();
  39. }
  40. const std::vector<std::string> & BattleFieldHandler::getTypeNames() const
  41. {
  42. static const std::vector<std::string> types = std::vector<std::string> { "battlefield" };
  43. return types;
  44. }
  45. int32_t BattleFieldInfo::getIndex() const
  46. {
  47. return battlefield.getNum();
  48. }
  49. int32_t BattleFieldInfo::getIconIndex() const
  50. {
  51. return iconIndex;
  52. }
  53. std::string BattleFieldInfo::getJsonKey() const
  54. {
  55. return modScope + ':' + identifier;
  56. }
  57. std::string BattleFieldInfo::getNameTextID() const
  58. {
  59. return name;
  60. }
  61. std::string BattleFieldInfo::getNameTranslated() const
  62. {
  63. return name; // TODO?
  64. }
  65. void BattleFieldInfo::registerIcons(const IconRegistar & cb) const
  66. {
  67. //cb(getIconIndex(), "BATTLEFIELD", icon);
  68. }
  69. BattleField BattleFieldInfo::getId() const
  70. {
  71. return battlefield;
  72. }
  73. VCMI_LIB_NAMESPACE_END