mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Attempt to fix crash on rewardable configuration
This commit is contained in:
@@ -34,14 +34,16 @@ std::optional<int> Rewardable::Configuration::getVariable(const std::string & ca
|
|||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonNode Rewardable::Configuration::getPresetVariable(const std::string & category, const std::string & name) const
|
const JsonNode & Rewardable::Configuration::getPresetVariable(const std::string & category, const std::string & name) const
|
||||||
{
|
{
|
||||||
|
static const JsonNode emptyNode;
|
||||||
|
|
||||||
std::string variableID = category + '@' + name;
|
std::string variableID = category + '@' + name;
|
||||||
|
|
||||||
if (variables.preset.count(variableID))
|
if (variables.preset.count(variableID))
|
||||||
return variables.preset.at(variableID);
|
return variables.preset.at(variableID);
|
||||||
else
|
else
|
||||||
return JsonNode();
|
return emptyNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rewardable::Configuration::presetVariable(const std::string & category, const std::string & name, const JsonNode & value)
|
void Rewardable::Configuration::presetVariable(const std::string & category, const std::string & name, const JsonNode & value)
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ struct DLL_LINKAGE Configuration
|
|||||||
ui16 getResetDuration() const;
|
ui16 getResetDuration() const;
|
||||||
|
|
||||||
std::optional<int> getVariable(const std::string & category, const std::string & name) const;
|
std::optional<int> getVariable(const std::string & category, const std::string & name) const;
|
||||||
JsonNode getPresetVariable(const std::string & category, const std::string & name) const;
|
const JsonNode & getPresetVariable(const std::string & category, const std::string & name) const;
|
||||||
void presetVariable(const std::string & category, const std::string & name, const JsonNode & value);
|
void presetVariable(const std::string & category, const std::string & name, const JsonNode & value);
|
||||||
void initVariable(const std::string & category, const std::string & name, int value);
|
void initVariable(const std::string & category, const std::string & name, int value);
|
||||||
|
|
||||||
|
|||||||
@@ -272,18 +272,18 @@ void Rewardable::Info::replaceTextPlaceholders(MetaString & target, const Variab
|
|||||||
|
|
||||||
void Rewardable::Info::configureRewards(
|
void Rewardable::Info::configureRewards(
|
||||||
Rewardable::Configuration & object,
|
Rewardable::Configuration & object,
|
||||||
CRandomGenerator & rng, const
|
CRandomGenerator & rng,
|
||||||
JsonNode & source,
|
const JsonNode & source,
|
||||||
Rewardable::EEventType event,
|
Rewardable::EEventType event,
|
||||||
const std::string & modeName) const
|
const std::string & modeName) const
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < source.Vector().size(); ++i)
|
for(size_t i = 0; i < source.Vector().size(); ++i)
|
||||||
{
|
{
|
||||||
const JsonNode reward = source.Vector()[i];
|
const JsonNode & reward = source.Vector().at(i);
|
||||||
|
|
||||||
if (!reward["appearChance"].isNull())
|
if (!reward["appearChance"].isNull())
|
||||||
{
|
{
|
||||||
JsonNode chance = reward["appearChance"];
|
const JsonNode & chance = reward["appearChance"];
|
||||||
std::string diceID = std::to_string(chance["dice"].Integer());
|
std::string diceID = std::to_string(chance["dice"].Integer());
|
||||||
|
|
||||||
auto diceValue = object.getVariable("dice", diceID);
|
auto diceValue = object.getVariable("dice", diceID);
|
||||||
|
|||||||
Reference in New Issue
Block a user