Skip to content

Commit 6eef463

Browse files
committed
gamestate: Use nyan Object::extends to check for parent relationship.
1 parent eb683c1 commit 6eef463

File tree

11 files changed

+13
-85
lines changed

11 files changed

+13
-85
lines changed

libopenage/gamestate/api/ability.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@
1717
namespace openage::gamestate::api {
1818

1919
bool APIAbility::is_ability(const nyan::Object &obj) {
20-
for (auto &parent : obj.get_parents()) {
21-
if (parent == "engine.ability.Ability") {
22-
return true;
23-
}
24-
}
25-
26-
return false;
20+
return obj.extends("engine.ability.Ability");
2721
}
2822

2923
bool APIAbility::check_type(const nyan::Object &ability,

libopenage/gamestate/api/activity.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99
namespace openage::gamestate::api {
1010

1111
bool APIActivity::is_activity(const nyan::Object &obj) {
12-
for (auto &parent : obj.get_parents()) {
13-
if (parent == "engine.util.activity.Activity") {
14-
return true;
15-
}
16-
}
17-
18-
return false;
12+
return obj.extends("engine.util.activity.Activity");
1913
}
2014

2115
nyan::Object APIActivity::get_start(const nyan::Object &activity) {
@@ -27,13 +21,7 @@ nyan::Object APIActivity::get_start(const nyan::Object &activity) {
2721

2822

2923
bool APIActivityNode::is_node(const nyan::Object &obj) {
30-
for (auto &parent : obj.get_parents()) {
31-
if (parent == "engine.util.activity.node.Node") {
32-
return true;
33-
}
34-
}
35-
36-
return false;
24+
return obj.extends("engine.util.activity.node.Node");
3725
}
3826

3927
activity::node_t APIActivityNode::get_type(const nyan::Object &node) {

libopenage/gamestate/api/animation.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010
namespace openage::gamestate::api {
1111

1212
bool APIAnimation::is_animation(nyan::Object &obj) {
13-
for (auto &parent : obj.get_parents()) {
14-
if (parent == "engine.util.animation.Animation") {
15-
return true;
16-
}
17-
}
18-
19-
return false;
13+
return obj.extends("engine.util.animation.Animation");
2014
}
2115

2216
const std::string APIAnimation::get_animation_path(const nyan::Object &animation) {

libopenage/gamestate/api/effect.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99
namespace openage::gamestate::api {
1010

1111
bool APIEffect::is_effect(const nyan::Object &obj) {
12-
for (auto &parent : obj.get_parents()) {
13-
if (parent == "engine.effect.Effect") {
14-
return true;
15-
}
16-
}
17-
18-
return false;
12+
return obj.extends("engine.effect.Effect");
1913
}
2014

2115
bool APIEffect::check_type(const nyan::Object &effect,

libopenage/gamestate/api/object.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88
namespace openage::gamestate::api {
99

1010
bool APIObject::is_object(const nyan::Object &obj) {
11-
for (const auto &parent : obj.get_parents()) {
12-
if (parent == "engine.root.Object") {
13-
return true;
14-
}
15-
}
16-
17-
return false;
11+
return obj.extends("engine.root.Object");
1812
}
1913

20-
} // namespace
14+
} // namespace openage::gamestate::api

libopenage/gamestate/api/patch.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@
1616
namespace openage::gamestate::api {
1717

1818
bool APIPatch::is_patch(const nyan::Object &obj) {
19-
for (auto &parent : obj.get_parents()) {
20-
if (parent == "engine.util.patch.Patch") {
21-
return true;
22-
}
23-
}
24-
25-
return false;
19+
return obj.extends("engine.util.patch.Patch");
2620
}
2721

2822
bool APIPatch::check_property(const nyan::Object &patch,

libopenage/gamestate/api/player_setup.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
namespace openage::gamestate::api {
1414

1515
bool APIPlayerSetup::is_player_setup(const nyan::Object &obj) {
16-
for (auto &parent : obj.get_parents()) {
17-
if (parent == "engine.util.setup.PlayerSetup") {
18-
return true;
19-
}
20-
}
21-
22-
return false;
16+
return obj.extends("engine.util.setup.PlayerSetup");
2317
}
2418

2519
const std::vector<nyan::Object> APIPlayerSetup::get_modifiers(const nyan::Object &player_setup) {

libopenage/gamestate/api/property.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
namespace openage::gamestate::api {
1414

1515
bool APIAbilityProperty::is_property(const nyan::Object &obj) {
16-
for (auto &parent : obj.get_parents()) {
17-
if (parent == "engine.ability.property.Property") {
18-
return true;
19-
}
20-
}
21-
22-
return false;
16+
return obj.extends("engine.ability.property.Property");
2317
}
2418

2519
const std::vector<nyan::Object> APIAbilityProperty::get_animations(const nyan::Object &property) {

libopenage/gamestate/api/resistance.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99
namespace openage::gamestate::api {
1010

1111
bool APIResistance::is_resistance(const nyan::Object &obj) {
12-
for (auto &parent : obj.get_parents()) {
13-
if (parent == "engine.resistance.Resistance") {
14-
return true;
15-
}
16-
}
17-
18-
return false;
12+
return obj.extends("engine.resistance.Resistance");
1913
}
2014

2115
bool APIResistance::check_effect_type(const nyan::Object &resistance,

libopenage/gamestate/api/sound.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@
1212
namespace openage::gamestate::api {
1313

1414
bool APISound::is_sound(const nyan::Object &obj) {
15-
for (auto &parent : obj.get_parents()) {
16-
if (parent == "engine.util.sound.Sound") {
17-
return true;
18-
}
19-
}
20-
21-
return false;
15+
return obj.extends("engine.util.sound.Sound");
2216
}
2317

2418
const std::string APISound::get_sound_path(const nyan::Object &sound) {

0 commit comments

Comments
 (0)