1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-12 10:03:53 +02:00
vcmi/lib/BattleFieldHandler.cpp
Ivan Savenko 47c1803c42 Finalization of refactoring:
- Entity interface now has getNameTranslated & getNameTextID methods
- Entity interface no longer has getName method
- removed (most) usages of normalizeIndentifier workaround method
- all moddable objects have identifier in form of mod:name
- all moddable object register strings in form of mod.type.name
2023-01-20 15:18:36 +02:00

97 lines
2.1 KiB
C++

/*
* BattleFieldHandler.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include <vcmi/Entity.h>
#include "BattleFieldHandler.h"
VCMI_LIB_NAMESPACE_BEGIN
BattleFieldInfo * BattleFieldHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index)
{
assert(identifier.find(':') == std::string::npos);
BattleFieldInfo * info = new BattleFieldInfo(BattleField(index), identifier);
info->graphics = json["graphics"].String();
info->icon = json["icon"].String();
info->name = json["name"].String();
for(auto b : json["bonuses"].Vector())
{
auto bonus = JsonUtils::parseBonus(b);
bonus->source = Bonus::TERRAIN_OVERLAY;
bonus->sid = info->getIndex();
bonus->duration = Bonus::ONE_BATTLE;
info->bonuses.push_back(bonus);
}
info->isSpecial = json["isSpecial"].Bool();
for(auto node : json["impassableHexes"].Vector())
info->impassableHexes.push_back(BattleHex(node.Integer()));
return info;
}
std::vector<JsonNode> BattleFieldHandler::loadLegacyData(size_t dataSize)
{
return std::vector<JsonNode>();
}
const std::vector<std::string> & BattleFieldHandler::getTypeNames() const
{
static const std::vector<std::string> types = std::vector<std::string> { "battlefield" };
return types;
}
std::vector<bool> BattleFieldHandler::getDefaultAllowed() const
{
return std::vector<bool>();
}
int32_t BattleFieldInfo::getIndex() const
{
return battlefield.getNum();
}
int32_t BattleFieldInfo::getIconIndex() const
{
return iconIndex;
}
std::string BattleFieldInfo::getJsonKey() const
{
return identifier;
}
std::string BattleFieldInfo::getNameTextID() const
{
return name;
}
std::string BattleFieldInfo::getNameTranslated() const
{
return name; // TODO?
}
void BattleFieldInfo::registerIcons(const IconRegistar & cb) const
{
//cb(getIconIndex(), "BATTLEFIELD", icon);
}
BattleField BattleFieldInfo::getId() const
{
return battlefield;
}
VCMI_LIB_NAMESPACE_END