1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

changed indentation from spaces to tabs

This commit is contained in:
Henning Koehler 2017-08-30 16:23:03 +12:00
parent aadb5d93f7
commit 36d671b093
4 changed files with 925 additions and 925 deletions

View File

@ -1,48 +1,48 @@
{ {
"type":"object", "type" : "object",
"$schema": "http://json-schema.org/draft-04/schema", "$schema" : "http://json-schema.org/draft-04/schema",
"title" : "VCMI skill format", "title" : "VCMI skill format",
"description" : "Format used to replace bonuses provided by secondary skills in VCMI", "description" : "Format used to replace bonuses provided by secondary skills in VCMI",
"definitions" : { "definitions" : {
"skillBonus":{ "skillBonus" : {
"type": "object", "type" : "object",
"description": "Set of bonuses provided by skill at given level", "description" : "Set of bonuses provided by skill at given level",
"required" : ["effects"], "required" : ["effects"],
"properties": { "properties" : {
"description": { "description" : {
"type": "string", "type" : "string",
"description": "localizable description" "description" : "localizable description"
}, },
"effects": { "effects" : {
"type": "object", "type" : "object",
"additionalProperties" : { "additionalProperties" : {
"$ref" : "vcmi:bonus" "$ref" : "vcmi:bonus"
} }
} }
} }
}, },
"required" : ["basic", "advanced", "expert"], "required" : ["basic", "advanced", "expert"],
"properties": { "properties" : {
"base":{ "base" : {
"type": "object", "type" : "object",
"description": "will be merged with all levels", "description" : "will be merged with all levels",
"additionalProperties": true "additionalProperties" : true
}, },
"basic":{ "basic" : {
"$ref" : "#/definitions/skillBonus" "$ref" : "#/definitions/skillBonus"
}, },
"advanced":{ "advanced" : {
"$ref" : "#/definitions/skillBonus" "$ref" : "#/definitions/skillBonus"
}, },
"expert":{ "expert" : {
"$ref" : "#/definitions/skillBonus" "$ref" : "#/definitions/skillBonus"
} }
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -37,14 +37,14 @@ CSkill::LevelInfo::~LevelInfo()
CSkill::CSkill(SecondarySkill id) : id(id) CSkill::CSkill(SecondarySkill id) : id(id)
{ {
if(id == SecondarySkill::DEFAULT) if(id == SecondarySkill::DEFAULT)
identifier = "default"; identifier = "default";
else else
identifier = NSecondarySkill::names[id]; identifier = NSecondarySkill::names[id];
// init levels // init levels
LevelInfo emptyLevel; LevelInfo emptyLevel;
for(int level = 1; level < NSecondarySkill::levels.size(); level++) for(int level = 1; level < NSecondarySkill::levels.size(); level++)
levels.push_back(emptyLevel); levels.push_back(emptyLevel);
} }
CSkill::~CSkill() CSkill::~CSkill()
@ -53,42 +53,42 @@ CSkill::~CSkill()
void CSkill::addNewBonus(const std::shared_ptr<Bonus>& b, int level) void CSkill::addNewBonus(const std::shared_ptr<Bonus>& b, int level)
{ {
b->source = Bonus::SECONDARY_SKILL; b->source = Bonus::SECONDARY_SKILL;
b->sid = id; b->sid = id;
b->duration = Bonus::PERMANENT; b->duration = Bonus::PERMANENT;
b->description = identifier; b->description = identifier;
levels[level-1].effects.push_back(b); levels[level-1].effects.push_back(b);
} }
void CSkill::setDescription(const std::string & desc, int level) void CSkill::setDescription(const std::string & desc, int level)
{ {
levels[level-1].description = desc; levels[level-1].description = desc;
} }
const std::vector<std::shared_ptr<Bonus>> & CSkill::getBonus(int level) const const std::vector<std::shared_ptr<Bonus>> & CSkill::getBonus(int level) const
{ {
return levels[level-1].effects; return levels[level-1].effects;
} }
const std::string & CSkill::getDescription(int level) const const std::string & CSkill::getDescription(int level) const
{ {
return levels[level-1].description; return levels[level-1].description;
} }
DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const CSkill::LevelInfo &info) DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const CSkill::LevelInfo &info)
{ {
out << "(\"" << info.description << "\", ["; out << "(\"" << info.description << "\", [";
for(int i=0; i < info.effects.size(); i++) for(int i=0; i < info.effects.size(); i++)
out << (i ? "," : "") << info.effects[i]->Description(); out << (i ? "," : "") << info.effects[i]->Description();
return out << "])"; return out << "])";
} }
DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const CSkill &skill) DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const CSkill &skill)
{ {
out << "Skill(" << (int)skill.id << "," << skill.identifier << "): ["; out << "Skill(" << (int)skill.id << "," << skill.identifier << "): [";
for(int i=0; i < skill.levels.size(); i++) for(int i=0; i < skill.levels.size(); i++)
out << (i ? "," : "") << skill.levels[i]; out << (i ? "," : "") << skill.levels[i];
return out << "]"; return out << "]";
} }
std::string CSkill::toString() const std::string CSkill::toString() const
@ -101,14 +101,14 @@ std::string CSkill::toString() const
///CSkillHandler ///CSkillHandler
CSkillHandler::CSkillHandler() CSkillHandler::CSkillHandler()
{ {
for(int id = 0; id < GameConstants::SKILL_QUANTITY; id++) for(int id = 0; id < GameConstants::SKILL_QUANTITY; id++)
{ {
CSkill * skill = new CSkill(SecondarySkill(id)); CSkill * skill = new CSkill(SecondarySkill(id));
for(int level = 1; level < NSecondarySkill::levels.size(); level++) for(int level = 1; level < NSecondarySkill::levels.size(); level++)
for (auto bonus : defaultBonus(SecondarySkill(id), level)) for (auto bonus : defaultBonus(SecondarySkill(id), level))
skill->addNewBonus(bonus, level); skill->addNewBonus(bonus, level);
objects.push_back(skill); objects.push_back(skill);
} }
} }
std::vector<JsonNode> CSkillHandler::loadLegacyData(size_t dataSize) std::vector<JsonNode> CSkillHandler::loadLegacyData(size_t dataSize)
@ -141,42 +141,42 @@ const std::string CSkillHandler::getTypeName() const
CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string & identifier) CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string & identifier)
{ {
CSkill * skill = NULL; CSkill * skill = NULL;
for(int id = 0; id < GameConstants::SKILL_QUANTITY; id++) for(int id = 0; id < GameConstants::SKILL_QUANTITY; id++)
{ {
if(NSecondarySkill::names[id].compare(identifier) == 0) if(NSecondarySkill::names[id].compare(identifier) == 0)
{ {
skill = new CSkill(SecondarySkill(id)); skill = new CSkill(SecondarySkill(id));
break; break;
} }
} }
if(!skill) if(!skill)
{ {
logGlobal->error("unknown secondary skill %s", identifier); logGlobal->error("unknown secondary skill %s", identifier);
throw std::runtime_error("invalid skill"); throw std::runtime_error("invalid skill");
} }
for(int level = 1; level < NSecondarySkill::levels.size(); level++) for(int level = 1; level < NSecondarySkill::levels.size(); level++)
{ {
const std::string & levelName = NSecondarySkill::levels[level]; // basic, advanced, expert const std::string & levelName = NSecondarySkill::levels[level]; // basic, advanced, expert
const JsonNode & levelNode = json[levelName]; const JsonNode & levelNode = json[levelName];
// parse bonus effects // parse bonus effects
for(auto b : levelNode["effects"].Struct()) for(auto b : levelNode["effects"].Struct())
{ {
auto bonus = JsonUtils::parseBonus(b.second); auto bonus = JsonUtils::parseBonus(b.second);
bonus->sid = skill->id; bonus->sid = skill->id;
skill->addNewBonus(bonus, level); skill->addNewBonus(bonus, level);
} }
// parse skill description - tracked separately // parse skill description - tracked separately
if(vstd::contains(levelNode.Struct(), "description") && !levelNode["description"].isNull()) if(vstd::contains(levelNode.Struct(), "description") && !levelNode["description"].isNull())
skill->setDescription(levelNode["description"].String(), level); skill->setDescription(levelNode["description"].String(), level);
} }
logMod->debug("loaded secondary skill %s(%d)", identifier, (int)skill->id); logMod->debug("loaded secondary skill %s(%d)", identifier, (int)skill->id);
logMod->trace("%s", skill->toString()); logMod->trace("%s", skill->toString());
return skill; return skill;
} }
void CSkillHandler::loadObject(std::string scope, std::string name, const JsonNode & data) void CSkillHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
@ -231,8 +231,8 @@ CSkillHandler::~CSkillHandler()
std::vector<bool> CSkillHandler::getDefaultAllowed() const std::vector<bool> CSkillHandler::getDefaultAllowed() const
{ {
std::vector<bool> allowedSkills(objects.size(), true); std::vector<bool> allowedSkills(objects.size(), true);
return allowedSkills; return allowedSkills;
} }
// HMM3 default bonus provided by secondary skill // HMM3 default bonus provided by secondary skill

View File

@ -38,51 +38,51 @@ protected:
std::vector<LevelInfo> levels; // bonuses provided by basic, advanced and expert level std::vector<LevelInfo> levels; // bonuses provided by basic, advanced and expert level
public: public:
CSkill(SecondarySkill id = SecondarySkill::DEFAULT); CSkill(SecondarySkill id = SecondarySkill::DEFAULT);
~CSkill(); ~CSkill();
void addNewBonus(const std::shared_ptr<Bonus>& b, int level); void addNewBonus(const std::shared_ptr<Bonus>& b, int level);
void setDescription(const std::string & desc, int level); void setDescription(const std::string & desc, int level);
const std::vector<std::shared_ptr<Bonus>> & getBonus(int level) const; const std::vector<std::shared_ptr<Bonus>> & getBonus(int level) const;
const std::string & getDescription(int level) const; const std::string & getDescription(int level) const;
std::string toString() const; std::string toString() const;
SecondarySkill id; SecondarySkill id;
std::string identifier; std::string identifier;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & id & identifier; h & id & identifier;
h & levels; h & levels;
} }
friend class CSkillHandler; friend class CSkillHandler;
friend std::ostream & operator<<(std::ostream &out, const CSkill &skill); friend std::ostream & operator<<(std::ostream &out, const CSkill &skill);
friend std::ostream & operator<<(std::ostream &out, const CSkill::LevelInfo &info); friend std::ostream & operator<<(std::ostream &out, const CSkill::LevelInfo &info);
}; };
class DLL_LINKAGE CSkillHandler: public CHandlerBase<SecondarySkill, CSkill> class DLL_LINKAGE CSkillHandler: public CHandlerBase<SecondarySkill, CSkill>
{ {
public: public:
CSkillHandler(); CSkillHandler();
virtual ~CSkillHandler(); virtual ~CSkillHandler();
///IHandler base ///IHandler base
std::vector<JsonNode> loadLegacyData(size_t dataSize) override; std::vector<JsonNode> loadLegacyData(size_t dataSize) override;
void afterLoadFinalization() override; void afterLoadFinalization() override;
void beforeValidate(JsonNode & object) override; void beforeValidate(JsonNode & object) override;
std::vector<bool> getDefaultAllowed() const override; std::vector<bool> getDefaultAllowed() const override;
const std::string getTypeName() const override; const std::string getTypeName() const override;
void loadObject(std::string scope, std::string name, const JsonNode & data) override; void loadObject(std::string scope, std::string name, const JsonNode & data) override;
void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override; void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & objects ; h & objects ;
} }
protected: protected:
CSkill * loadFromJson(const JsonNode & json, const std::string & identifier) override; CSkill * loadFromJson(const JsonNode & json, const std::string & identifier) override;
std::vector<std::shared_ptr<Bonus>> defaultBonus(SecondarySkill skill, int level) const; std::vector<std::shared_ptr<Bonus>> defaultBonus(SecondarySkill skill, int level) const;
}; };