File tree Expand file tree Collapse file tree 5 files changed +70
-20
lines changed
libopenage/gamestate/system Expand file tree Collapse file tree 5 files changed +70
-20
lines changed Original file line number Diff line number Diff line change @@ -3,5 +3,6 @@ add_sources(libopenage
33 apply_effect.cpp
44 idle.cpp
55 move.cpp
6+ property.cpp
67 types.cpp
78)
Original file line number Diff line number Diff line change 1515#include " gamestate/component/api/idle.h"
1616#include " gamestate/component/types.h"
1717#include " gamestate/game_entity.h"
18+ #include " gamestate/system/property.h"
1819
1920
2021namespace openage ::gamestate::system {
@@ -27,18 +28,10 @@ const time::time_t Idle::idle(const std::shared_ptr<gamestate::GameEntity> &enti
2728
2829 auto idle_component = std::dynamic_pointer_cast<component::Idle>(
2930 entity->get_component (component::component_t ::IDLE));
30- auto ability = idle_component->get_ability ();
31- if (api::APIAbility::check_property (ability, api::ability_property_t ::ANIMATED)) {
32- auto property = api::APIAbility::get_property (ability, api::ability_property_t ::ANIMATED);
33- auto animations = api::APIAbilityProperty::get_animations (property);
34- auto animation_paths = api::APIAnimation::get_animation_paths (animations);
35-
36- if (animation_paths.size () > 0 ) [[likely]] {
37- entity->render_update (start_time, animation_paths[0 ]);
38- }
39- }
4031
41- // TODO: play sound
32+ // properties
33+ auto ability = idle_component->get_ability ();
34+ handle_animated (entity, ability, start_time);
4235
4336 return time::time_t::from_int (0 );
4437}
Original file line number Diff line number Diff line change 2626#include " gamestate/game_entity.h"
2727#include " gamestate/game_state.h"
2828#include " gamestate/map.h"
29+ #include " gamestate/system/property.h"
2930#include " pathfinding/path.h"
3031#include " pathfinding/pathfinder.h"
3132#include " util/fixed_point.h"
@@ -171,15 +172,7 @@ const time::time_t Move::move_default(const std::shared_ptr<gamestate::GameEntit
171172
172173 // properties
173174 auto ability = move_component->get_ability ();
174- if (api::APIAbility::check_property (ability, api::ability_property_t ::ANIMATED)) {
175- auto property = api::APIAbility::get_property (ability, api::ability_property_t ::ANIMATED);
176- auto animations = api::APIAbilityProperty::get_animations (property);
177- auto animation_paths = api::APIAnimation::get_animation_paths (animations);
178-
179- if (animation_paths.size () > 0 ) [[likely]] {
180- entity->render_update (start_time, animation_paths[0 ]);
181- }
182- }
175+ handle_animated (entity, ability, start_time);
183176
184177 return total_time;
185178}
Original file line number Diff line number Diff line change 1+ // Copyright 2024-2024 the openage authors. See copying.md for legal info.
2+
3+ #include " property.h"
4+
5+ #include " gamestate/api/ability.h"
6+ #include " gamestate/api/animation.h"
7+ #include " gamestate/api/property.h"
8+ #include " gamestate/game_entity.h"
9+
10+
11+ namespace openage ::gamestate::system {
12+
13+ bool handle_animated (const std::shared_ptr<gamestate::GameEntity> &entity,
14+ const nyan::Object &ability,
15+ const time::time_t &start_time) {
16+ bool animated = api::APIAbility::check_property (ability, api::ability_property_t ::ANIMATED);
17+
18+ if (animated) {
19+ auto property = api::APIAbility::get_property (ability, api::ability_property_t ::ANIMATED);
20+ auto animations = api::APIAbilityProperty::get_animations (property);
21+ auto animation_paths = api::APIAnimation::get_animation_paths (animations);
22+
23+ if (animation_paths.size () > 0 ) [[likely]] {
24+ // TODO: More than one animation path
25+ entity->render_update (start_time, animation_paths[0 ]);
26+ }
27+ }
28+
29+ return animated;
30+ }
31+
32+ } // namespace openage::gamestate::system
Original file line number Diff line number Diff line change 1+ // Copyright 2024-2024 the openage authors. See copying.md for legal info.
2+
3+ #pragma once
4+
5+ #include < memory>
6+
7+ #include < nyan/nyan.h>
8+
9+ #include " time/time.h"
10+
11+
12+ namespace openage ::gamestate {
13+ class GameEntity ;
14+
15+ namespace system {
16+
17+ /* *
18+ * Handle the animated property of an ability.
19+ *
20+ * @param entity Game entity.
21+ * @param ability Ability object.
22+ * @param start_time Start time of the animation.
23+ *
24+ * @return true if the ability has the property, false otherwise.
25+ */
26+ bool handle_animated (const std::shared_ptr<gamestate::GameEntity> &entity,
27+ const nyan::Object &ability,
28+ const time::time_t &start_time);
29+
30+ } // namespace system
31+ } // namespace openage::gamestate
You can’t perform that action at this time.
0 commit comments