BattleFieldHandler.cpp 2.4 KB

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