mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-29 21:56:54 +02:00
Adding logging and error handling
This commit is contained in:
parent
7c13246851
commit
23e411cacd
@ -130,8 +130,8 @@ std::unique_ptr<CCampaign> CCampaignHandler::getCampaign( const std::string & na
|
|||||||
if(sc.isNotVoid())
|
if(sc.isNotVoid())
|
||||||
{
|
{
|
||||||
CMapService mapService;
|
CMapService mapService;
|
||||||
auto hdr = mapService.loadMapHeader(ResourceID(sc.mapName, EResType::MAP));
|
if(auto hdr = mapService.loadMapHeader(ResourceID(sc.mapName, EResType::MAP)))
|
||||||
sc.scenarioName = hdr->name;
|
sc.scenarioName = hdr->name;
|
||||||
}
|
}
|
||||||
ret->scenarios.push_back(sc);
|
ret->scenarios.push_back(sc);
|
||||||
}
|
}
|
||||||
@ -187,7 +187,7 @@ CCampaignHeader CCampaignHandler::readHeaderFromJson(JsonNode & reader, std::str
|
|||||||
ret.version = reader["version"].Integer();
|
ret.version = reader["version"].Integer();
|
||||||
if(ret.version < CampaignVersion::VCMI_MIN || ret.version > CampaignVersion::VCMI_MAX)
|
if(ret.version < CampaignVersion::VCMI_MIN || ret.version > CampaignVersion::VCMI_MAX)
|
||||||
{
|
{
|
||||||
logGlobal->info("Unsupported campaign %s version %d", filename, ret.version);
|
logGlobal->info("VCMP Loading: Unsupported campaign %s version %d", filename, ret.version);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,17 +299,26 @@ CScenarioTravel CCampaignHandler::readScenarioTravelFromJson(JsonNode & reader,
|
|||||||
|
|
||||||
for(auto & k : reader["keepCreatures"].Vector())
|
for(auto & k : reader["keepCreatures"].Vector())
|
||||||
{
|
{
|
||||||
int creId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "creature", k.String()).get();
|
if(auto identifier = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "creature", k.String()))
|
||||||
ret.monstersKeptByHero[creId / 8] |= (1 << creId % 8);
|
{
|
||||||
|
int creId = identifier.get();
|
||||||
|
ret.monstersKeptByHero[creId / 8] |= (1 << creId % 8);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
logGlobal->warn("VCMP Loading: keepCreatures contains unresolved identifier %s", k.String());
|
||||||
}
|
}
|
||||||
for(auto & k : reader["keepArtifacts"].Vector())
|
for(auto & k : reader["keepArtifacts"].Vector())
|
||||||
{
|
{
|
||||||
int artId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "artifact", k.String()).get();
|
if(auto identifier = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "artifact", k.String()))
|
||||||
ret.artifsKeptByHero[artId / 8] |= (1 << artId % 8);
|
{
|
||||||
|
int artId = identifier.get();
|
||||||
|
ret.artifsKeptByHero[artId / 8] |= (1 << artId % 8);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
logGlobal->warn("VCMP Loading: keepArtifacts contains unresolved identifier %s", k.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.startOptions = startOptionsMap[reader["startOptions"].String()];
|
ret.startOptions = startOptionsMap[reader["startOptions"].String()];
|
||||||
|
|
||||||
switch(ret.startOptions)
|
switch(ret.startOptions)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@ -322,36 +331,58 @@ CScenarioTravel CCampaignHandler::readScenarioTravelFromJson(JsonNode & reader,
|
|||||||
{
|
{
|
||||||
CScenarioTravel::STravelBonus bonus;
|
CScenarioTravel::STravelBonus bonus;
|
||||||
bonus.type = bonusTypeMap[bjson["what"].String()];
|
bonus.type = bonusTypeMap[bjson["what"].String()];
|
||||||
if(bonus.type == CScenarioTravel::STravelBonus::EBonusType::RESOURCE)
|
switch (bonus.type)
|
||||||
{
|
{
|
||||||
bonus.info1 = resourceTypeMap[bjson["type"].String()];
|
case CScenarioTravel::STravelBonus::EBonusType::RESOURCE:
|
||||||
bonus.info2 = bjson["amount"].Integer();
|
bonus.info1 = resourceTypeMap[bjson["type"].String()];
|
||||||
}
|
bonus.info2 = bjson["amount"].Integer();
|
||||||
else if(bonus.type == CScenarioTravel::STravelBonus::EBonusType::BUILDING)
|
break;
|
||||||
bonus.info1 = vstd::find_pos(EBuildingType::names, bjson["type"].String());
|
|
||||||
else
|
case CScenarioTravel::STravelBonus::EBonusType::BUILDING:
|
||||||
{
|
bonus.info1 = vstd::find_pos(EBuildingType::names, bjson["type"].String());
|
||||||
if(int heroId = heroSpecialMap[bjson["hero"].String()])
|
if(bonus.info1 == -1)
|
||||||
bonus.info1 = heroId;
|
logGlobal->warn("VCMP Loading: unresolved building identifier %s", bjson["type"].String());
|
||||||
else
|
break;
|
||||||
bonus.info1 = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "hero", bjson["hero"].String()).get();
|
|
||||||
|
default:
|
||||||
if(bonus.type == CScenarioTravel::STravelBonus::EBonusType::SPELL
|
if(int heroId = heroSpecialMap[bjson["hero"].String()])
|
||||||
|| bonus.type == CScenarioTravel::STravelBonus::EBonusType::MONSTER
|
bonus.info1 = heroId;
|
||||||
|| bonus.type == CScenarioTravel::STravelBonus::EBonusType::SECONDARY_SKILL
|
else
|
||||||
|| bonus.type == CScenarioTravel::STravelBonus::EBonusType::ARTIFACT)
|
if(auto identifier = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "hero", bjson["hero"].String()))
|
||||||
bonus.info2 = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), bjson["what"].String(), bjson["type"].String()).get();
|
bonus.info1 = identifier.get();
|
||||||
else if(bonus.type == CScenarioTravel::STravelBonus::EBonusType::SPELL_SCROLL)
|
else
|
||||||
bonus.info2 = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "spell", bjson["type"].String()).get();
|
logGlobal->warn("VCMP Loading: unresolved hero identifier %s", bjson["hero"].String());
|
||||||
else if(bonus.type == CScenarioTravel::STravelBonus::EBonusType::PRIMARY_SKILL)
|
|
||||||
{
|
bonus.info3 = bjson["amount"].Integer();
|
||||||
for(auto & ps : primarySkillsMap)
|
|
||||||
bonus.info2 |= bjson[ps.first].Integer() << ps.second;
|
switch(bonus.type)
|
||||||
}
|
{
|
||||||
else
|
case CScenarioTravel::STravelBonus::EBonusType::SPELL:
|
||||||
bonus.info2 = bjson["type"].Integer();
|
case CScenarioTravel::STravelBonus::EBonusType::MONSTER:
|
||||||
|
case CScenarioTravel::STravelBonus::EBonusType::SECONDARY_SKILL:
|
||||||
bonus.info3 = bjson["amount"].Integer();
|
case CScenarioTravel::STravelBonus::EBonusType::ARTIFACT:
|
||||||
|
if(auto identifier = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), bjson["what"].String(), bjson["type"].String()))
|
||||||
|
bonus.info2 = identifier.get();
|
||||||
|
else
|
||||||
|
logGlobal->warn("VCMP Loading: unresolved %s identifier %s", bjson["what"].String(), bjson["type"].String());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CScenarioTravel::STravelBonus::EBonusType::SPELL_SCROLL:
|
||||||
|
if(auto Identifier = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "spell", bjson["type"].String()))
|
||||||
|
bonus.info2 = Identifier.get();
|
||||||
|
else
|
||||||
|
logGlobal->warn("VCMP Loading: unresolved spell scroll identifier %s", bjson["type"].String());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CScenarioTravel::STravelBonus::EBonusType::PRIMARY_SKILL:
|
||||||
|
for(auto & ps : primarySkillsMap)
|
||||||
|
bonus.info2 |= bjson[ps.first].Integer() << ps.second;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
bonus.info2 = bjson["type"].Integer();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ret.bonusesToChoose.push_back(bonus);
|
ret.bonusesToChoose.push_back(bonus);
|
||||||
}
|
}
|
||||||
@ -380,7 +411,10 @@ CScenarioTravel CCampaignHandler::readScenarioTravelFromJson(JsonNode & reader,
|
|||||||
if(int heroId = heroSpecialMap[bjson["hero"].String()])
|
if(int heroId = heroSpecialMap[bjson["hero"].String()])
|
||||||
bonus.info2 = heroId;
|
bonus.info2 = heroId;
|
||||||
else
|
else
|
||||||
bonus.info2 = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "hero", bjson["hero"].String()).get();
|
if (auto identifier = VLC->modh->identifiers.getIdentifier(CModHandler::scopeMap(), "hero", bjson["hero"].String()))
|
||||||
|
bonus.info2 = identifier.get();
|
||||||
|
else
|
||||||
|
logGlobal->warn("VCMP Loading: unresolved hero identifier %s", bjson["hero"].String());
|
||||||
|
|
||||||
ret.bonusesToChoose.push_back(bonus);
|
ret.bonusesToChoose.push_back(bonus);
|
||||||
}
|
}
|
||||||
@ -388,7 +422,7 @@ CScenarioTravel CCampaignHandler::readScenarioTravelFromJson(JsonNode & reader,
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
logGlobal->warn("Corrupted h3c file");
|
logGlobal->warn("VCMP Loading: Unsupported start options value");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user