1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

enabled config of skill descriptions

This commit is contained in:
Henning Koehler
2017-08-25 13:35:02 +12:00
parent 8c7895239e
commit 0357a4fe3b
12 changed files with 128 additions and 48 deletions

View File

@@ -377,6 +377,7 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali
if (!modInfo.patches.isNull())
JsonUtils::merge(modInfo.modData, modInfo.patches);
CLogger * logger = CLogger::getLogger(CLoggerDomain("mod"));
for(auto & entry : modInfo.modData.Struct())
{
const std::string & name = entry.first;
@@ -389,6 +390,7 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali
if (originalData.size() > index)
{
logger->traceStream() << "found original data in loadMod(" << name << ") at index " << index;
JsonUtils::merge(originalData[index], data);
performValidate(originalData[index],name);
handler->loadObject(modName, name, originalData[index], index);
@@ -396,8 +398,8 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali
}
else
{
logGlobal->debugStream() << "no original data in loadMod(" << name << ")";
logGlobal->traceStream() << data;
logger->debugStream() << "no original data in loadMod(" << name << ") at index " << index;
logger->traceStream() << data;
performValidate(data, name);
handler->loadObject(modName, name, data, index);
}

View File

@@ -27,16 +27,24 @@
#include "battle/CBattleInfoCallback.h"
///CSkill
CSkill::LevelInfo::LevelInfo() : description("")
{
}
CSkill::LevelInfo::~LevelInfo()
{
}
CSkill::CSkill(SecondarySkill id) : id(id)
{
if(id == SecondarySkill::DEFAULT)
identifier = "default";
else
identifier = NSecondarySkill::names[id];
// init bonus levels
BonusList emptyList;
for(auto level : NSecondarySkill::levels)
bonusByLevel.push_back(emptyList);
// init levels
LevelInfo emptyLevel;
for(int level = 1; level < NSecondarySkill::levels.size(); level++)
levels.push_back(emptyLevel);
}
CSkill::~CSkill()
@@ -48,18 +56,32 @@ void CSkill::addNewBonus(const std::shared_ptr<Bonus>& b, int level)
b->source = Bonus::SECONDARY_SKILL;
b->duration = Bonus::PERMANENT;
b->description = identifier;
bonusByLevel[level].push_back(b);
levels[level-1].effects.push_back(b);
}
BonusList CSkill::getBonus(int level)
void CSkill::setDescription(const std::string & desc, int level)
{
return bonusByLevel[level];
levels[level-1].description = desc;
}
const std::vector<std::shared_ptr<Bonus>> & CSkill::getBonus(int level) const
{
return levels[level-1].effects;
}
const std::string & CSkill::getDescription(int level) const
{
return levels[level-1].description;
}
DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const CSkill::LevelInfo &info)
{
return out << "(\"" << info.description << "\"," << info.effects << ")";
}
DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const CSkill &skill)
{
out << "Skill(" << (int)skill.id << "," << skill.identifier << "): " << skill.bonusByLevel;
return out;
return out << "Skill(" << (int)skill.id << "," << skill.identifier << "): " << skill.levels;
}
///CSkillHandler
@@ -108,12 +130,18 @@ CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string &
for(int level = 1; level < NSecondarySkill::levels.size(); level++)
{
const std::string & levelName = NSecondarySkill::levels[level]; // basic, advanced, expert
for(auto b : json[levelName].Vector())
const JsonNode & levelNode = json[levelName];
// parse bonus effects
for(auto b : levelNode["effects"].Vector())
{
auto bonus = JsonUtils::parseBonus(b);
bonus->sid = skill->id;
skill->addNewBonus(bonus, level);
}
// parse skill description - tracked separately
if(vstd::contains(levelNode.Struct(), "description") && !levelNode["description"].isNull())
//CGI->generaltexth->skillInfoTexts[skill->id][level-1] = levelNode["description"].String();
skill->setDescription(levelNode["description"].String(), level);
}
CLogger * logger = CLogger::getLogger(CLoggerDomain(getTypeName()));
logger->debugStream() << "loaded secondary skill " << identifier << "(" << (int)skill->id << ")";

View File

@@ -21,14 +21,30 @@ class JsonSerializeFormat;
class DLL_LINKAGE CSkill // secondary skill
{
protected:
std::vector<BonusList> bonusByLevel; // bonuses provided by none, basic, advanced and expert level
struct LevelInfo
{
std::string description; //descriptions of spell for skill level
std::vector<std::shared_ptr<Bonus>> effects;
LevelInfo();
~LevelInfo();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & description & effects;
}
};
std::vector<LevelInfo> levels; // bonuses provided by basic, advanced and expert level
public:
CSkill(SecondarySkill id = SecondarySkill::DEFAULT);
~CSkill();
void addNewBonus(const std::shared_ptr<Bonus>& b, int level);
BonusList getBonus(int level);
void setDescription(const std::string & desc, int level);
const std::vector<std::shared_ptr<Bonus>> & getBonus(int level) const;
const std::string & getDescription(int level) const;
SecondarySkill id;
std::string identifier;
@@ -36,11 +52,12 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & id & identifier;
h & bonusByLevel;
h & levels;
}
friend class CSkillHandler;
friend std::ostream & operator<<(std::ostream &out, const CSkill &skill);
friend std::ostream & operator<<(std::ostream &out, const CSkill::LevelInfo &info);
};
class DLL_LINKAGE CSkillHandler: public CHandlerBase<SecondarySkill, CSkill>

View File

@@ -766,7 +766,7 @@ void CGHeroInstance::recreateSecondarySkillsBonuses()
void CGHeroInstance::updateSkill(SecondarySkill which, int val)
{
BonusList skillBonus = (*VLC->skillh)[which]->getBonus(val);
auto skillBonus = (*VLC->skillh)[which]->getBonus(val);
for (auto b : skillBonus)
{
// TODO: add standard method for joining bonuses, should match on valType as well