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