mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
convert spec format in afterLoadFinalization
This commit is contained in:
parent
26862b4c51
commit
c31950612c
@ -548,24 +548,17 @@ void CHeroHandler::loadHeroSpecialty(CHero * hero, const JsonNode & node)
|
||||
const JsonNode & specialties = node["specialties"];
|
||||
if (!specialties.isNull())
|
||||
{
|
||||
logMod->warn("Hero %s has deprecated specialties format. New format:", hero->identifier);
|
||||
JsonNode specVec(JsonNode::JsonType::DATA_VECTOR);
|
||||
logMod->warn("Hero %s has deprecated specialties format.", hero->identifier);
|
||||
for(const JsonNode &specialty : node["specialties"].Vector())
|
||||
{
|
||||
SSpecialtyInfo spec;
|
||||
|
||||
spec.type = specialty["type"].Float();
|
||||
spec.val = specialty["val"].Float();
|
||||
spec.subtype = specialty["subtype"].Float();
|
||||
spec.additionalinfo = specialty["info"].Float();
|
||||
|
||||
for(std::shared_ptr<Bonus> bonus : SpecialtyInfoToBonuses(spec, sid))
|
||||
{
|
||||
hero->specialty.push_back(bonus);
|
||||
specVec.Vector().push_back(bonus->toJsonNode());
|
||||
}
|
||||
//we convert after loading completes, to have all identifiers for json logging
|
||||
hero->specDeprecated.push_back(spec);
|
||||
}
|
||||
logMod->info("\"specialty\" = %s", specVec.toJson());
|
||||
}
|
||||
//new format, using bonus system
|
||||
for(const JsonNode & specialty : node["specialty"].Vector())
|
||||
@ -737,6 +730,28 @@ void CHeroHandler::loadObject(std::string scope, std::string name, const JsonNod
|
||||
VLC->modh->identifiers.registerObject(scope, "hero", name, object->ID.getNum());
|
||||
}
|
||||
|
||||
void CHeroHandler::afterLoadFinalization()
|
||||
{
|
||||
for(ConstTransitivePtr<CHero> hero : heroes)
|
||||
{
|
||||
if(hero->specDeprecated.size() > 0)
|
||||
{
|
||||
logMod->debug("Converting specialties format for hero %s(%s)", hero->identifier, VLC->townh->encodeFaction(hero->heroClass->faction));
|
||||
JsonNode specVec(JsonNode::JsonType::DATA_VECTOR);
|
||||
for(const SSpecialtyInfo & spec : hero->specDeprecated)
|
||||
{
|
||||
for(std::shared_ptr<Bonus> bonus : SpecialtyInfoToBonuses(spec, hero->ID.getNum()))
|
||||
{
|
||||
hero->specialty.push_back(bonus);
|
||||
specVec.Vector().push_back(bonus->toJsonNode());
|
||||
}
|
||||
}
|
||||
hero->specDeprecated.clear();
|
||||
logMod->trace("\"specialty\" = %s", specVec.toJson());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui32 CHeroHandler::level (ui64 experience) const
|
||||
{
|
||||
return boost::range::upper_bound(expPerLevel, experience) - std::begin(expPerLevel);
|
||||
|
@ -302,6 +302,7 @@ public:
|
||||
|
||||
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 afterLoadFinalization() override;
|
||||
|
||||
CHeroHandler();
|
||||
~CHeroHandler();
|
||||
|
@ -1177,8 +1177,7 @@ JsonNode subtypeToJson(Bonus::BonusType type, int subtype)
|
||||
case Bonus::SPECIAL_BLESS_DAMAGE:
|
||||
case Bonus::MAXED_SPELL:
|
||||
case Bonus::SPECIAL_PECULIAR_ENCHANT:
|
||||
//return JsonUtils::stringNode((*VLC->spellh)[SpellID::ESpellID(subtype)]->identifier);
|
||||
return JsonUtils::intNode(subtype); //Issue 2790
|
||||
return JsonUtils::stringNode((*VLC->spellh)[SpellID::ESpellID(subtype)]->identifier);
|
||||
case Bonus::SPECIAL_UPGRADE:
|
||||
return JsonUtils::stringNode(CreatureID::encode(subtype));
|
||||
case Bonus::GENERATE_RESOURCE:
|
||||
|
Loading…
Reference in New Issue
Block a user