mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Create separate instance of updater for every bonus
This commit is contained in:
parent
985adbe07b
commit
28081085a8
@ -19,14 +19,6 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
const std::map<std::string, TUpdaterPtr> bonusUpdaterMap =
|
||||
{
|
||||
{"TIMES_HERO_LEVEL", std::make_shared<TimesHeroLevelUpdater>()},
|
||||
{"TIMES_STACK_LEVEL", std::make_shared<TimesStackLevelUpdater>()},
|
||||
{"ARMY_MOVEMENT", std::make_shared<ArmyMovementUpdater>()},
|
||||
{"BONUS_OWNER_UPDATER", std::make_shared<OwnerUpdater>()}
|
||||
};
|
||||
|
||||
std::shared_ptr<Bonus> IUpdater::createUpdatedBonus(const std::shared_ptr<Bonus> & b, const CBonusSystemNode & context) const
|
||||
{
|
||||
return b;
|
||||
|
@ -13,8 +13,6 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
extern DLL_LINKAGE const std::map<std::string, TUpdaterPtr> bonusUpdaterMap;
|
||||
|
||||
// observers for updating bonuses based on certain events (e.g. hero gaining level)
|
||||
|
||||
class DLL_LINKAGE IUpdater
|
||||
@ -114,4 +112,4 @@ public:
|
||||
JsonNode toJsonNode() const override;
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
@ -325,11 +325,25 @@ static BonusParams convertDeprecatedBonus(const JsonNode &ability)
|
||||
|
||||
static TUpdaterPtr parseUpdater(const JsonNode & updaterJson)
|
||||
{
|
||||
const std::map<std::string, std::function<TUpdaterPtr()>> bonusUpdaterMap =
|
||||
{
|
||||
{"TIMES_HERO_LEVEL", std::make_shared<TimesHeroLevelUpdater>},
|
||||
{"TIMES_STACK_LEVEL", std::make_shared<TimesStackLevelUpdater>},
|
||||
{"ARMY_MOVEMENT", std::make_shared<ArmyMovementUpdater>},
|
||||
{"BONUS_OWNER_UPDATER", std::make_shared<OwnerUpdater>}
|
||||
};
|
||||
|
||||
switch(updaterJson.getType())
|
||||
{
|
||||
case JsonNode::JsonType::DATA_STRING:
|
||||
return parseByMap(bonusUpdaterMap, &updaterJson, "updater type ");
|
||||
break;
|
||||
{
|
||||
auto it = bonusUpdaterMap.find(updaterJson.String());
|
||||
if (it != bonusUpdaterMap.end())
|
||||
return it->second();
|
||||
|
||||
logGlobal->error("Unknown bonus updater type '%s'", updaterJson.String());
|
||||
return nullptr;
|
||||
}
|
||||
case JsonNode::JsonType::DATA_STRUCT:
|
||||
if(updaterJson["type"].String() == "GROWS_WITH_LEVEL")
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user