Line data Source code
1 : #include "core/animations/states/LegsFallAnimationState.hpp"
2 :
3 : #include "core/animations/states/LegsCrouchRunAnimationState.hpp"
4 : #include "core/animations/states/LegsJumpAnimationState.hpp"
5 : #include "core/animations/states/LegsStandAnimationState.hpp"
6 : #include "core/animations/states/LegsRunBackAnimationState.hpp"
7 : #include "core/animations/states/LegsRunAnimationState.hpp"
8 : #include "core/animations/states/LegsProneAnimationState.hpp"
9 : #include "core/animations/states/CommonAnimationStateTransitions.hpp"
10 :
11 : #include "core/physics/Constants.hpp"
12 : #include "core/entities/Soldier.hpp"
13 :
14 : namespace Soldank
15 : {
16 0 : LegsFallAnimationState::LegsFallAnimationState(const AnimationDataManager& animation_data_manager)
17 0 : : AnimationState(animation_data_manager.Get(AnimationType::Fall))
18 0 : , animation_data_manager_(animation_data_manager)
19 : {
20 0 : }
21 :
22 0 : std::optional<std::shared_ptr<AnimationState>> LegsFallAnimationState::HandleInput(Soldier& soldier)
23 : {
24 0 : if (soldier.control.prone) {
25 0 : return std::make_shared<LegsProneAnimationState>(animation_data_manager_);
26 : }
27 :
28 0 : if (soldier.control.up && !soldier.on_ground) {
29 0 : return std::nullopt;
30 : }
31 :
32 : auto maybe_running_animation_state =
33 0 : CommonAnimationStateTransitions::TryTransitionToRunning(soldier, animation_data_manager_);
34 0 : if (maybe_running_animation_state.has_value()) {
35 0 : return *maybe_running_animation_state;
36 : }
37 :
38 0 : if (soldier.on_ground) {
39 0 : if (soldier.control.up) {
40 0 : return std::make_shared<LegsJumpAnimationState>(animation_data_manager_);
41 : }
42 :
43 0 : if (soldier.control.down) {
44 0 : return std::make_shared<LegsCrouchRunAnimationState>(animation_data_manager_);
45 : }
46 :
47 0 : return std::make_shared<LegsStandAnimationState>(animation_data_manager_);
48 : }
49 :
50 0 : return std::nullopt;
51 0 : }
52 :
53 0 : void LegsFallAnimationState::Update(Soldier& soldier, const PhysicsEvents& physics_events)
54 : {
55 0 : soldier.stance = PhysicsConstants::STANCE_STAND;
56 0 : }
57 : } // namespace Soldank
|