BattleFieldHandler.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. BattleFieldInfo * BattleFieldHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index)
  14. {
  15. BattleFieldInfo * info = new BattleFieldInfo(BattleField(index), identifier);
  16. if(json["graphics"].getType() == JsonNode::JsonType::DATA_STRING)
  17. {
  18. info->graphics = json["graphics"].String();
  19. }
  20. if(json["icon"].getType() == JsonNode::JsonType::DATA_STRING)
  21. {
  22. info->icon = json["icon"].String();
  23. }
  24. if(json["name"].getType() == JsonNode::JsonType::DATA_STRING)
  25. {
  26. info->name = json["name"].String();
  27. }
  28. if(json["bonuses"].getType() == JsonNode::JsonType::DATA_VECTOR)
  29. {
  30. for(auto b : json["bonuses"].Vector())
  31. {
  32. auto bonus = JsonUtils::parseBonus(b);
  33. bonus->source = Bonus::TERRAIN_OVERLAY;
  34. bonus->sid = info->getIndex();
  35. bonus->duration = Bonus::ONE_BATTLE;
  36. info->bonuses.push_back(bonus);
  37. }
  38. }
  39. if(json["isSpecial"].getType() == JsonNode::JsonType::DATA_BOOL)
  40. {
  41. info->isSpecial = json["isSpecial"].Bool();
  42. }
  43. if(json["impassableHexes"].getType() == JsonNode::JsonType::DATA_VECTOR)
  44. {
  45. for(auto node : json["impassableHexes"].Vector())
  46. info->impassableHexes.push_back(BattleHex(node.Integer()));
  47. }
  48. return info;
  49. }
  50. std::vector<JsonNode> BattleFieldHandler::loadLegacyData(size_t dataSize)
  51. {
  52. return std::vector<JsonNode>();
  53. }
  54. const std::vector<std::string> & BattleFieldHandler::getTypeNames() const
  55. {
  56. static const std::vector<std::string> types = std::vector<std::string> { "battlefield" };
  57. return types;
  58. }
  59. std::vector<bool> BattleFieldHandler::getDefaultAllowed() const
  60. {
  61. return std::vector<bool>();
  62. }
  63. int32_t BattleFieldInfo::getIndex() const
  64. {
  65. return battlefield.getNum();
  66. }
  67. int32_t BattleFieldInfo::getIconIndex() const
  68. {
  69. return iconIndex;
  70. }
  71. const std::string & BattleFieldInfo::getName() const
  72. {
  73. return name;
  74. }
  75. const std::string & BattleFieldInfo::getJsonKey() const
  76. {
  77. return identifier;
  78. }
  79. void BattleFieldInfo::registerIcons(const IconRegistar & cb) const
  80. {
  81. //cb(getIconIndex(), "BATTLEFIELD", icon);
  82. }
  83. BattleField BattleFieldInfo::getId() const
  84. {
  85. return battlefield;
  86. }