mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-14 02:33:51 +02:00
Fix remaining TODO's
This commit is contained in:
parent
b9540fa507
commit
1c4a142849
@ -73,7 +73,23 @@ void Rewardable::VisitInfo::serializeJson(JsonSerializeFormat & handler)
|
||||
|
||||
void Rewardable::Variables::serializeJson(JsonSerializeFormat & handler)
|
||||
{
|
||||
// TODO
|
||||
if (handler.saving)
|
||||
{
|
||||
JsonNode presetNode;
|
||||
for (auto const & entry : preset)
|
||||
presetNode[entry.first] = entry.second;
|
||||
|
||||
handler.serializeRaw("preset", presetNode, {});
|
||||
}
|
||||
else
|
||||
{
|
||||
preset.clear();
|
||||
JsonNode presetNode;
|
||||
handler.serializeRaw("preset", presetNode, {});
|
||||
|
||||
for (auto const & entry : presetNode.Struct())
|
||||
preset[entry.first] = entry.second;
|
||||
}
|
||||
}
|
||||
|
||||
void Rewardable::Configuration::serializeJson(JsonSerializeFormat & handler)
|
||||
|
@ -233,14 +233,6 @@ void Rewardable::Info::configureVariables(Rewardable::Configuration & object, CR
|
||||
if (category.first == "spell")
|
||||
value = JsonRandom::loadSpell(input, rng, object.variables.values).getNum();
|
||||
|
||||
// TODO
|
||||
// if (category.first == "creature")
|
||||
// value = JsonRandom::loadCreature(input, rng, object.variables.values).type->getId();
|
||||
|
||||
// TODO
|
||||
// if (category.first == "resource")
|
||||
// value = JsonRandom::loadResource(input, rng, object.variables.values).getNum();
|
||||
|
||||
if (category.first == "primarySkill")
|
||||
value = static_cast<int>(JsonRandom::loadPrimary(input, rng, object.variables.values));
|
||||
|
||||
@ -252,6 +244,32 @@ void Rewardable::Info::configureVariables(Rewardable::Configuration & object, CR
|
||||
}
|
||||
}
|
||||
|
||||
void Rewardable::Info::replaceTextPlaceholders(MetaString & target, const Variables & variables) const
|
||||
{
|
||||
for (const auto & variable : variables.values )
|
||||
{
|
||||
if( boost::algorithm::starts_with(variable.first, "spell"))
|
||||
target.replaceLocalString(EMetaText::SPELL_NAME, variable.second);
|
||||
|
||||
if( boost::algorithm::starts_with(variable.first, "secondarySkill"))
|
||||
target.replaceLocalString(EMetaText::SEC_SKILL_NAME, variable.second);
|
||||
}
|
||||
}
|
||||
|
||||
void Rewardable::Info::replaceTextPlaceholders(MetaString & target, const Variables & variables, const VisitInfo & info) const
|
||||
{
|
||||
for (const auto & artifact : info.reward.artifacts )
|
||||
target.replaceLocalString(EMetaText::ART_NAMES, artifact.getNum());
|
||||
|
||||
for (const auto & artifact : info.reward.spells )
|
||||
target.replaceLocalString(EMetaText::SPELL_NAME, artifact.getNum());
|
||||
|
||||
for (const auto & secondary : info.reward.secondary )
|
||||
target.replaceLocalString(EMetaText::SEC_SKILL_NAME, secondary.first.getNum());
|
||||
|
||||
replaceTextPlaceholders(target, variables);
|
||||
}
|
||||
|
||||
void Rewardable::Info::configureRewards(
|
||||
Rewardable::Configuration & object,
|
||||
CRandomGenerator & rng, const
|
||||
@ -304,37 +322,8 @@ void Rewardable::Info::configureRewards(
|
||||
info.message = loadMessage(reward["message"], TextIdentifier(objectTextID, modeName, i));
|
||||
info.description = loadMessage(reward["description"], TextIdentifier(objectTextID, "description", modeName, i), EMetaText::GENERAL_TXT);
|
||||
|
||||
for (const auto & artifact : info.reward.artifacts )
|
||||
{
|
||||
info.message.replaceLocalString(EMetaText::ART_NAMES, artifact.getNum());
|
||||
info.description.replaceLocalString(EMetaText::ART_NAMES, artifact.getNum());
|
||||
}
|
||||
|
||||
for (const auto & artifact : info.reward.spells )
|
||||
{
|
||||
info.message.replaceLocalString(EMetaText::SPELL_NAME, artifact.getNum());
|
||||
info.description.replaceLocalString(EMetaText::SPELL_NAME, artifact.getNum());
|
||||
}
|
||||
|
||||
for (const auto & secondary : info.reward.secondary )
|
||||
{
|
||||
info.message.replaceLocalString(EMetaText::SEC_SKILL_NAME, secondary.first.getNum());
|
||||
info.description.replaceLocalString(EMetaText::SEC_SKILL_NAME, secondary.first.getNum());
|
||||
}
|
||||
|
||||
for (const auto & variable : object.variables.values )
|
||||
{
|
||||
if( boost::algorithm::starts_with(variable.first, "spell"))
|
||||
{
|
||||
info.message.replaceLocalString(EMetaText::SPELL_NAME, variable.second);
|
||||
info.description.replaceLocalString(EMetaText::SPELL_NAME, variable.second);
|
||||
}
|
||||
if( boost::algorithm::starts_with(variable.first, "secondarySkill"))
|
||||
{
|
||||
info.message.replaceLocalString(EMetaText::SEC_SKILL_NAME, variable.second);
|
||||
info.description.replaceLocalString(EMetaText::SEC_SKILL_NAME, variable.second);
|
||||
}
|
||||
}
|
||||
replaceTextPlaceholders(info.message, object.variables, info);
|
||||
replaceTextPlaceholders(info.description, object.variables, info);
|
||||
|
||||
object.info.push_back(info);
|
||||
}
|
||||
@ -366,13 +355,7 @@ void Rewardable::Info::configureObject(Rewardable::Configuration & object, CRand
|
||||
Rewardable::VisitInfo onVisited;
|
||||
onVisited.visitType = Rewardable::EEventType::EVENT_ALREADY_VISITED;
|
||||
onVisited.message = loadMessage(parameters["onVisitedMessage"], TextIdentifier(objectTextID, "onVisited"));
|
||||
for (const auto & variable : object.variables.values )
|
||||
{
|
||||
if( boost::algorithm::starts_with(variable.first, "spell"))
|
||||
onVisited.message.replaceLocalString(EMetaText::SPELL_NAME, variable.second);
|
||||
if( boost::algorithm::starts_with(variable.first, "secondarySkill"))
|
||||
onVisited.message.replaceLocalString(EMetaText::SEC_SKILL_NAME, variable.second);
|
||||
}
|
||||
replaceTextPlaceholders(onVisited.message, object.variables);
|
||||
|
||||
object.info.push_back(onVisited);
|
||||
}
|
||||
@ -382,13 +365,7 @@ void Rewardable::Info::configureObject(Rewardable::Configuration & object, CRand
|
||||
Rewardable::VisitInfo onEmpty;
|
||||
onEmpty.visitType = Rewardable::EEventType::EVENT_NOT_AVAILABLE;
|
||||
onEmpty.message = loadMessage(parameters["onEmptyMessage"], TextIdentifier(objectTextID, "onEmpty"));
|
||||
for (const auto & variable : object.variables.values )
|
||||
{
|
||||
if( boost::algorithm::starts_with(variable.first, "spell"))
|
||||
onEmpty.message.replaceLocalString(EMetaText::SPELL_NAME, variable.second);
|
||||
if( boost::algorithm::starts_with(variable.first, "secondarySkill"))
|
||||
onEmpty.message.replaceLocalString(EMetaText::SEC_SKILL_NAME, variable.second);
|
||||
}
|
||||
replaceTextPlaceholders(onEmpty.message, object.variables);
|
||||
|
||||
object.info.push_back(onEmpty);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class CRandomGenerator;
|
||||
class MetaString;
|
||||
|
||||
namespace Rewardable
|
||||
{
|
||||
@ -24,6 +25,8 @@ struct Limiter;
|
||||
using LimitersList = std::vector<std::shared_ptr<Rewardable::Limiter>>;
|
||||
struct Reward;
|
||||
struct Configuration;
|
||||
struct Variables;
|
||||
struct VisitInfo;
|
||||
struct ResetInfo;
|
||||
enum class EEventType;
|
||||
|
||||
@ -32,6 +35,9 @@ class DLL_LINKAGE Info : public IObjectInfo
|
||||
JsonNode parameters;
|
||||
std::string objectTextID;
|
||||
|
||||
void replaceTextPlaceholders(MetaString & target, const Variables & variables) const;
|
||||
void replaceTextPlaceholders(MetaString & target, const Variables & variables, const VisitInfo & info) const;
|
||||
|
||||
void configureVariables(Rewardable::Configuration & object, CRandomGenerator & rng, const JsonNode & source) const;
|
||||
void configureRewards(Rewardable::Configuration & object, CRandomGenerator & rng, const JsonNode & source, Rewardable::EEventType mode, const std::string & textPrefix) const;
|
||||
|
||||
|
@ -20,7 +20,12 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
void Rewardable::RewardRevealTiles::serializeJson(JsonSerializeFormat & handler)
|
||||
{
|
||||
// TODO
|
||||
handler.serializeBool("hide", hide);
|
||||
handler.serializeInt("scoreSurface", scoreSurface);
|
||||
handler.serializeInt("scoreSubterra", scoreSubterra);
|
||||
handler.serializeInt("scoreWater", scoreWater);
|
||||
handler.serializeInt("scoreRock", scoreRock);
|
||||
handler.serializeInt("radius", radius);
|
||||
}
|
||||
|
||||
Rewardable::Reward::Reward()
|
||||
|
Loading…
Reference in New Issue
Block a user