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

fixed crash when loading neutral faction; skills.json no longer requires index values

This commit is contained in:
Henning Koehler 2017-08-25 17:17:14 +12:00
parent 0357a4fe3b
commit c0740e3623
6 changed files with 41 additions and 7 deletions

View File

@ -29,10 +29,6 @@
"required" : ["basic", "advanced", "expert"],
"properties": {
"index":{
"type": "number",
"description": "numeric id of skill required only for original skills, prohibited for new skills"
},
"basic":{
"$ref" : "#/definitions/skillBonus"
},

View File

@ -1,6 +1,5 @@
{
"estates" : {
"index" : 13,
"basic" : {
"description" : "Hero generates 250 gold each day.",
"effects" : [

View File

@ -398,8 +398,14 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali
}
else
{
// trace only name field of original data - I miss list comprehension
std::vector<std::string> originalNames;
for (const JsonNode & orgElem : originalData)
originalNames.push_back(orgElem["name"].String());
logger->debugStream() << "no original data in loadMod(" << name << ") at index " << index;
logger->traceStream() << data;
logger->traceStream() << "originalData: " << originalNames;
logger->traceStream() << "new data: " << data;
performValidate(data, name);
handler->loadObject(modName, name, data, index);
}

View File

@ -150,6 +150,34 @@ CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string &
return skill;
}
void CSkillHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
{
auto type_name = getTypeName();
auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name));
if(object->id == SecondarySkill::DEFAULT) // new skill - no index identified
{
object->id = SecondarySkill(objects.size());
objects.push_back(object);
}
else
objects[object->id] = object;
registerObject(scope, type_name, name, object->id);
}
void CSkillHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
{
auto type_name = getTypeName();
auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name));
assert(object->id == index);
objects[index] = object;
registerObject(scope,type_name, name, object->id);
}
void CSkillHandler::afterLoadFinalization()
{
CLogger * logger = CLogger::getLogger(CLoggerDomain(getTypeName()));

View File

@ -73,6 +73,8 @@ public:
std::vector<bool> getDefaultAllowed() 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, size_t index) override;
template <typename Handler> void serialize(Handler &h, const int version)
{

View File

@ -763,7 +763,10 @@ void CTownHandler::loadObject(std::string scope, std::string name, const JsonNod
{
auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name));
object->index = index;
if (factions.size() > index)
assert(factions[index] == nullptr); // ensure that this id was not loaded before
else
factions.resize(index + 1);
factions[index] = object;
if (object->town)