Skip to content

Commit ac89cd1

Browse files
committed
Let nyan handle casting of ValueHolder to Value.
1 parent 6eef463 commit ac89cd1

File tree

10 files changed

+29
-36
lines changed

10 files changed

+29
-36
lines changed

libopenage/gamestate/api/ability.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ bool APIAbility::check_type(const nyan::Object &ability,
2525
nyan::fqon_t api_parent = get_api_parent(ability);
2626
nyan::ValueHolder ability_type = ABILITY_DEFS.get(type);
2727

28-
std::shared_ptr<nyan::ObjectValue> ability_val = std::dynamic_pointer_cast<nyan::ObjectValue>(
29-
ability_type.get_ptr());
28+
auto ability_val = ability_type.get_value_ptr<nyan::ObjectValue>();
3029

3130
return ability_val->get_name() == api_parent;
3231
}
@@ -61,8 +60,7 @@ const nyan::Object APIAbility::get_property(const nyan::Object &ability, const a
6160
nyan::ValueHolder property_type = ABILITY_PROPERTY_DEFS.get(property);
6261

6362
std::shared_ptr<nyan::View> db_view = ability.get_view();
64-
std::shared_ptr<nyan::ObjectValue> property_val = std::dynamic_pointer_cast<nyan::ObjectValue>(
65-
properties->get().at(property_type).get_ptr());
63+
auto property_val = properties->get().at(property_type).get_value_ptr<nyan::ObjectValue>();
6664

6765
return db_view->get_object(property_val->get_name());
6866
}

libopenage/gamestate/api/activity.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ std::vector<nyan::Object> APIActivityNode::get_next(const nyan::Object &node) {
6767

6868
std::vector<nyan::Object> next_nodes;
6969
for (auto &condition : conditions->get()) {
70-
auto condition_value = std::dynamic_pointer_cast<nyan::ObjectValue>(condition.get_ptr());
70+
auto condition_value = condition.get_value_ptr<nyan::ObjectValue>();
7171
auto condition_obj = db_view->get_object(condition_value->get_name());
7272

7373
auto next_node_value = condition_obj.get<nyan::ObjectValue>("Condition.next");
@@ -85,7 +85,7 @@ std::vector<nyan::Object> APIActivityNode::get_next(const nyan::Object &node) {
8585

8686
std::vector<nyan::Object> next_nodes;
8787
for (auto &next_node : next->get()) {
88-
auto next_node_value = std::dynamic_pointer_cast<nyan::ObjectValue>(next_node.second.get_ptr());
88+
auto next_node_value = next_node.second.get_value_ptr<nyan::ObjectValue>();
8989
next_nodes.push_back(db_view->get_object(next_node_value->get_name()));
9090
}
9191

@@ -104,7 +104,7 @@ std::vector<nyan::Object> APIActivityNode::get_next(const nyan::Object &node) {
104104
auto next = switch_condition_obj.get_dict("NextCommand.next");
105105
std::vector<nyan::Object> next_nodes;
106106
for (auto next_node : next) {
107-
auto next_node_value = std::dynamic_pointer_cast<nyan::ObjectValue>(next_node.second.get_ptr());
107+
auto next_node_value = next_node.second.get_value_ptr<nyan::ObjectValue>();
108108
next_nodes.push_back(db_view->get_object(next_node_value->get_name()));
109109
}
110110

@@ -179,14 +179,14 @@ APIActivitySwitchCondition::lookup_map_t APIActivitySwitchCondition::get_lookup_
179179
auto next = condition.get<nyan::Dict>("NextCommand.next");
180180
lookup_map_t lookup_map{};
181181
for (auto next_node : next->get()) {
182-
auto key_value = std::dynamic_pointer_cast<nyan::ObjectValue>(next_node.first.get_ptr());
182+
auto key_value = next_node.first.get_value_ptr<nyan::ObjectValue>();
183183
auto key_obj = condition.get_view()->get_object(key_value->get_name());
184184

185185
// Get engine lookup key value
186186
auto key = static_cast<activity::switch_key_t>(COMMAND_LOOKUP.get(key_obj.get_name()));
187187

188188
// Get node ID
189-
auto next_node_value = std::dynamic_pointer_cast<nyan::ObjectValue>(next_node.second.get_ptr());
189+
auto next_node_value = next_node.second.get_value_ptr<nyan::ObjectValue>();
190190
auto next_node_id = next_node_value->get_name();
191191

192192
lookup_map[key] = next_node_id;

libopenage/gamestate/api/effect.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ bool APIEffect::check_type(const nyan::Object &effect,
1717
nyan::fqon_t api_parent = get_api_parent(effect);
1818
nyan::ValueHolder effect_type = EFFECT_DEFS.get(type);
1919

20-
std::shared_ptr<nyan::ObjectValue> effect_val = std::dynamic_pointer_cast<nyan::ObjectValue>(
21-
effect_type.get_ptr());
20+
auto effect_val = effect_type.get_value_ptr<nyan::ObjectValue>();
2221

2322
return effect_val->get_name() == api_parent;
2423
}
@@ -43,8 +42,7 @@ const nyan::Object APIEffect::get_property(const nyan::Object &effect,
4342
nyan::ValueHolder property_type = EFFECT_PROPERTY_DEFS.get(property);
4443

4544
std::shared_ptr<nyan::View> db_view = effect.get_view();
46-
std::shared_ptr<nyan::ObjectValue> property_val = std::dynamic_pointer_cast<nyan::ObjectValue>(
47-
properties->get().at(property_type).get_ptr());
45+
auto property_val = properties->get().at(property_type).get_value_ptr<nyan::ObjectValue>();
4846

4947
return db_view->get_object(property_val->get_name());
5048
}

libopenage/gamestate/api/patch.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ const nyan::Object APIPatch::get_property(const nyan::Object &patch,
3737
nyan::ValueHolder property_type = PATCH_PROPERTY_DEFS.get(property);
3838

3939
std::shared_ptr<nyan::View> db_view = patch.get_view();
40-
std::shared_ptr<nyan::ObjectValue> property_val = std::dynamic_pointer_cast<nyan::ObjectValue>(
41-
properties->get().at(property_type).get_ptr());
40+
auto property_val = properties->get().at(property_type).get_value_ptr<nyan::ObjectValue>();
4241

4342
return db_view->get_object(property_val->get_name());
4443
}

libopenage/gamestate/api/player_setup.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const std::vector<nyan::Object> APIPlayerSetup::get_modifiers(const nyan::Object
2222
auto db_view = player_setup.get_view();
2323
auto modifiers = player_setup.get_set("PlayerSetup.modifiers");
2424
for (auto &modifier_val : modifiers) {
25-
auto modifier_obj_val = std::dynamic_pointer_cast<nyan::ObjectValue>(modifier_val.get_ptr());
25+
auto modifier_obj_val = modifier_val.get_value_ptr<nyan::ObjectValue>();
2626
auto modifier_obj = db_view->get_object(modifier_obj_val->get_name());
2727
result.push_back(modifier_obj);
2828
}
@@ -36,7 +36,7 @@ const std::vector<nyan::Object> APIPlayerSetup::get_start_resources(const nyan::
3636
auto db_view = player_setup.get_view();
3737
auto start_resources = player_setup.get_set("PlayerSetup.starting_resources");
3838
for (auto &resource_val : start_resources) {
39-
auto resource_obj_val = std::dynamic_pointer_cast<nyan::ObjectValue>(resource_val.get_ptr());
39+
auto resource_obj_val = resource_val.get_value_ptr<nyan::ObjectValue>();
4040
auto resource_obj = db_view->get_object(resource_obj_val->get_name());
4141
result.push_back(resource_obj);
4242
}
@@ -50,7 +50,7 @@ const std::vector<nyan::Object> APIPlayerSetup::get_patches(const nyan::Object &
5050
auto db_view = player_setup.get_view();
5151
auto patches = player_setup.get_set("PlayerSetup.game_setup");
5252
for (auto &patch_val : patches) {
53-
auto patch_obj_val = std::dynamic_pointer_cast<nyan::ObjectValue>(patch_val.get_ptr());
53+
auto patch_obj_val = patch_val.get_value_ptr<nyan::ObjectValue>();
5454
auto patch_obj = db_view->get_object(patch_obj_val->get_name());
5555
result.push_back(patch_obj);
5656
}

libopenage/gamestate/api/property.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const std::vector<nyan::Object> APIAbilityProperty::get_animations(const nyan::O
2222
auto db_view = property.get_view();
2323
auto animations = property.get_set("Animated.animations");
2424
for (auto &anim_val : animations) {
25-
auto anim_obj_val = std::dynamic_pointer_cast<nyan::ObjectValue>(anim_val.get_ptr());
25+
auto anim_obj_val = anim_val.get_value_ptr<nyan::ObjectValue>();
2626
auto anim_obj = db_view->get_object(anim_obj_val->get_name());
2727
result.push_back(anim_obj);
2828
}
@@ -36,7 +36,7 @@ const std::vector<nyan::Object> APIAbilityProperty::get_command_sounds(const nya
3636
auto db_view = property.get_view();
3737
auto command_sounds = property.get_set("CommandSound.sounds");
3838
for (auto &sound_val : command_sounds) {
39-
auto sound_obj_val = std::dynamic_pointer_cast<nyan::ObjectValue>(sound_val.get_ptr());
39+
auto sound_obj_val = sound_val.get_value_ptr<nyan::ObjectValue>();
4040
auto sound_obj = db_view->get_object(sound_obj_val->get_name());
4141
result.push_back(sound_obj);
4242
}
@@ -50,7 +50,7 @@ const std::vector<nyan::Object> APIAbilityProperty::get_execution_sounds(const n
5050
auto db_view = property.get_view();
5151
auto execution_sounds = property.get_set("ExecutionSound.sounds");
5252
for (auto &sound_val : execution_sounds) {
53-
auto sound_obj_val = std::dynamic_pointer_cast<nyan::ObjectValue>(sound_val.get_ptr());
53+
auto sound_obj_val = sound_val.get_value_ptr<nyan::ObjectValue>();
5454
auto sound_obj = db_view->get_object(sound_obj_val->get_name());
5555
result.push_back(sound_obj);
5656
}
@@ -64,7 +64,7 @@ const std::vector<nyan::Object> APIAbilityProperty::get_diplo_stances(const nyan
6464
auto db_view = property.get_view();
6565
auto diplo_stances = property.get_set("Diplomatic.stances");
6666
for (auto &diplo_stance_val : diplo_stances) {
67-
auto diplo_stance_obj_val = std::dynamic_pointer_cast<nyan::ObjectValue>(diplo_stance_val.get_ptr());
67+
auto diplo_stance_obj_val = diplo_stance_val.get_value_ptr<nyan::ObjectValue>();
6868
auto diplo_stance_obj = db_view->get_object(diplo_stance_obj_val->get_name());
6969
result.push_back(diplo_stance_obj);
7070
}

libopenage/gamestate/api/resistance.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ bool APIResistance::check_effect_type(const nyan::Object &resistance,
1717
nyan::fqon_t api_parent = get_api_parent(resistance);
1818
nyan::ValueHolder effect_type = RESISTANCE_DEFS.get(type);
1919

20-
std::shared_ptr<nyan::ObjectValue> effect_val = std::dynamic_pointer_cast<nyan::ObjectValue>(
21-
effect_type.get_ptr());
20+
auto effect_val = effect_type.get_value_ptr<nyan::ObjectValue>();
2221

2322
return effect_val->get_name() == api_parent;
2423
}
@@ -43,8 +42,7 @@ const nyan::Object APIResistance::get_property(const nyan::Object &resistance,
4342
nyan::ValueHolder property_type = RESISTANCE_PROPERTY_DEFS.get(property);
4443

4544
std::shared_ptr<nyan::View> db_view = resistance.get_view();
46-
std::shared_ptr<nyan::ObjectValue> property_val = std::dynamic_pointer_cast<nyan::ObjectValue>(
47-
properties->get().at(property_type).get_ptr());
45+
auto property_val = properties->get().at(property_type).get_value_ptr<nyan::ObjectValue>();
4846

4947
return db_view->get_object(property_val->get_name());
5048
}

libopenage/gamestate/api/terrain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ const std::unordered_map<nyan::fqon_t, int> APITerrain::get_path_costs(const nya
2525

2626
nyan::dict_t path_costs = terrain.get_dict("Terrain.path_costs");
2727
for (const auto &pair : path_costs) {
28-
auto key = std::dynamic_pointer_cast<nyan::ObjectValue>(pair.first.get_ptr());
29-
auto value = std::dynamic_pointer_cast<nyan::Int>(pair.second.get_ptr());
28+
auto key = pair.first.get_value_ptr<nyan::ObjectValue>();
29+
auto value = pair.second.get_value_ptr<nyan::Int>();
3030

3131
result.emplace(key->get_name(), value->get());
3232
}

libopenage/gamestate/entity_factory.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void EntityFactory::init_components(const std::shared_ptr<openage::event::EventL
173173

174174
std::optional<nyan::Object> activity_ability;
175175
for (const auto &ability_val : abilities) {
176-
auto ability_fqon = std::dynamic_pointer_cast<nyan::ObjectValue>(ability_val.get_ptr())->get_name();
176+
auto ability_fqon = ability_val.get_value_ptr<nyan::ObjectValue>()->get_name();
177177
auto ability_obj = owner_db_view->get_object(ability_fqon);
178178

179179
auto ability_parent = api::get_api_parent(ability_obj);
@@ -200,7 +200,7 @@ void EntityFactory::init_components(const std::shared_ptr<openage::event::EventL
200200

201201
auto attr_settings = ability_obj.get_set("Live.attributes");
202202
for (auto &setting : attr_settings) {
203-
auto setting_obj_val = std::dynamic_pointer_cast<nyan::ObjectValue>(setting.get_ptr());
203+
auto setting_obj_val = setting.get_value_ptr<nyan::ObjectValue>();
204204
auto setting_obj = owner_db_view->get_object(setting_obj_val->get_name());
205205
auto attribute = setting_obj.get_object("AttributeSetting.attribute");
206206
auto start_value = setting_obj.get_int("AttributeSetting.starting_value");
@@ -367,7 +367,7 @@ void EntityFactory::init_activity(const std::shared_ptr<openage::event::EventLoo
367367
auto xor_gate = std::static_pointer_cast<activity::XorGate>(activity_node);
368368
auto conditions = nyan_node.get<nyan::OrderedSet>("XORGate.next");
369369
for (auto &condition : conditions->get()) {
370-
auto condition_value = std::dynamic_pointer_cast<nyan::ObjectValue>(condition.get_ptr());
370+
auto condition_value = condition.get_value_ptr<nyan::ObjectValue>();
371371
auto condition_obj = owner_db_view->get_object_ptr(condition_value->get_name());
372372

373373
auto output_value = condition_obj->get<nyan::ObjectValue>("Condition.next")->get_name();
@@ -389,10 +389,10 @@ void EntityFactory::init_activity(const std::shared_ptr<openage::event::EventLoo
389389
auto xor_event_gate = std::static_pointer_cast<activity::XorEventGate>(activity_node);
390390
auto next = nyan_node.get<nyan::Dict>("XOREventGate.next");
391391
for (auto &next_node : next->get()) {
392-
auto event_value = std::dynamic_pointer_cast<nyan::ObjectValue>(next_node.first.get_ptr());
392+
auto event_value = next_node.first.get_value_ptr<nyan::ObjectValue>();
393393
auto event_obj = owner_db_view->get_object(event_value->get_name());
394394

395-
auto next_node_value = std::dynamic_pointer_cast<nyan::ObjectValue>(next_node.second.get_ptr());
395+
auto next_node_value = next_node.second.get_value_ptr<nyan::ObjectValue>();
396396
auto next_node_obj = owner_db_view->get_object(next_node_value->get_name());
397397

398398
auto output_id = visited[next_node_obj.get_name()];

libopenage/gamestate/system/apply_effect.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ const time::time_t ApplyEffect::apply_effect(const std::shared_ptr<gamestate::Ga
9898
// Extract the effects from the ability
9999
std::unordered_map<api::effect_t, std::vector<nyan::Object>> effects{};
100100
for (auto &batch : batches) {
101-
std::shared_ptr<nyan::ObjectValue> batch_obj_val = std::dynamic_pointer_cast<nyan::ObjectValue>(batch.get_ptr());
101+
auto batch_obj_val = batch.get_value_ptr<nyan::ObjectValue>();
102102
auto batch_obj = effect_ability.get_view()->get_object(batch_obj_val->get_name());
103103
auto batch_effects = batch_obj.get_set("EffectBatch.effects");
104104

105105
for (auto &batch_effect : batch_effects) {
106-
std::shared_ptr<nyan::ObjectValue> effect_obj_val = std::dynamic_pointer_cast<nyan::ObjectValue>(batch_effect.get_ptr());
106+
auto effect_obj_val = batch_effect.get_value_ptr<nyan::ObjectValue>();
107107
auto effect_obj = effect_ability.get_view()->get_object(effect_obj_val->get_name());
108108
auto effect_type = api::APIEffect::get_type(effect_obj);
109109

@@ -118,7 +118,7 @@ const time::time_t ApplyEffect::apply_effect(const std::shared_ptr<gamestate::Ga
118118
// Extract the resistances from the ability
119119
std::unordered_map<api::effect_t, std::vector<nyan::Object>> resistances{};
120120
for (auto &resistance : resistances_set) {
121-
std::shared_ptr<nyan::ObjectValue> resistance_obj_val = std::dynamic_pointer_cast<nyan::ObjectValue>(resistance.get_ptr());
121+
auto resistance_obj_val = resistance.get_value_ptr<nyan::ObjectValue>();
122122
auto resistance_obj = resistance_ability.get_view()->get_object(resistance_obj_val->get_name());
123123
auto resistance_type = api::APIResistance::get_effect_type(resistance_obj);
124124

0 commit comments

Comments
 (0)