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:
parent
0357a4fe3b
commit
c0740e3623
@ -29,10 +29,6 @@
|
|||||||
"required" : ["basic", "advanced", "expert"],
|
"required" : ["basic", "advanced", "expert"],
|
||||||
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"index":{
|
|
||||||
"type": "number",
|
|
||||||
"description": "numeric id of skill required only for original skills, prohibited for new skills"
|
|
||||||
},
|
|
||||||
"basic":{
|
"basic":{
|
||||||
"$ref" : "#/definitions/skillBonus"
|
"$ref" : "#/definitions/skillBonus"
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"estates" : {
|
"estates" : {
|
||||||
"index" : 13,
|
|
||||||
"basic" : {
|
"basic" : {
|
||||||
"description" : "Hero generates 250 gold each day.",
|
"description" : "Hero generates 250 gold each day.",
|
||||||
"effects" : [
|
"effects" : [
|
||||||
|
@ -398,8 +398,14 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali
|
|||||||
}
|
}
|
||||||
else
|
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->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);
|
performValidate(data, name);
|
||||||
handler->loadObject(modName, name, data, index);
|
handler->loadObject(modName, name, data, index);
|
||||||
}
|
}
|
||||||
|
@ -150,6 +150,34 @@ CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string &
|
|||||||
return skill;
|
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()
|
void CSkillHandler::afterLoadFinalization()
|
||||||
{
|
{
|
||||||
CLogger * logger = CLogger::getLogger(CLoggerDomain(getTypeName()));
|
CLogger * logger = CLogger::getLogger(CLoggerDomain(getTypeName()));
|
||||||
|
@ -73,6 +73,8 @@ public:
|
|||||||
|
|
||||||
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, size_t index) override;
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
|
@ -763,7 +763,10 @@ void CTownHandler::loadObject(std::string scope, std::string name, const JsonNod
|
|||||||
{
|
{
|
||||||
auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name));
|
auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name));
|
||||||
object->index = index;
|
object->index = index;
|
||||||
assert(factions[index] == nullptr); // ensure that this id was not loaded before
|
if (factions.size() > index)
|
||||||
|
assert(factions[index] == nullptr); // ensure that this id was not loaded before
|
||||||
|
else
|
||||||
|
factions.resize(index + 1);
|
||||||
factions[index] = object;
|
factions[index] = object;
|
||||||
|
|
||||||
if (object->town)
|
if (object->town)
|
||||||
|
Loading…
Reference in New Issue
Block a user