LCOV - code coverage report
Current view: top level - core/animations/states - LegsRunAnimationState.cpp (source / functions) Coverage Total Hit
Test: coverage-src.info Lines: 0.0 % 51 0
Test Date: 2025-05-27 23:26:07 Functions: 0.0 % 3 0

            Line data    Source code
       1              : #include "core/animations/states/LegsRunAnimationState.hpp"
       2              : 
       3              : #include "core/animations/states/LegsRollAnimationState.hpp"
       4              : #include "core/animations/states/LegsStandAnimationState.hpp"
       5              : #include "core/animations/states/LegsRunBackAnimationState.hpp"
       6              : #include "core/animations/states/LegsFallAnimationState.hpp"
       7              : #include "core/animations/states/LegsJumpSideAnimationState.hpp"
       8              : #include "core/animations/states/LegsJumpAnimationState.hpp"
       9              : #include "core/animations/states/LegsProneAnimationState.hpp"
      10              : 
      11              : #include "core/animations/states/CommonAnimationStateTransitions.hpp"
      12              : 
      13              : #include "core/entities/Soldier.hpp"
      14              : 
      15              : #include "core/physics/Constants.hpp"
      16              : #include <spdlog/spdlog.h>
      17              : 
      18              : namespace Soldank
      19              : {
      20            0 : LegsRunAnimationState::LegsRunAnimationState(const AnimationDataManager& animation_data_manager)
      21            0 :     : AnimationState(animation_data_manager.Get(AnimationType::Run))
      22            0 :     , animation_data_manager_(animation_data_manager)
      23              : {
      24            0 : }
      25              : 
      26            0 : std::optional<std::shared_ptr<AnimationState>> LegsRunAnimationState::HandleInput(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.on_ground) {
      33              :         auto maybe_rolling_animation_state =
      34            0 :           CommonAnimationStateTransitions::TryTransitionToRolling(soldier, animation_data_manager_);
      35            0 :         if (maybe_rolling_animation_state.has_value()) {
      36            0 :             return *maybe_rolling_animation_state;
      37              :         }
      38            0 :     }
      39              : 
      40            0 :     if (!soldier.control.left && !soldier.control.right) {
      41            0 :         if (soldier.on_ground) {
      42            0 :             if (soldier.control.up) {
      43            0 :                 return std::make_shared<LegsJumpAnimationState>(animation_data_manager_);
      44              :             }
      45            0 :             return std::make_shared<LegsStandAnimationState>(animation_data_manager_);
      46              :         }
      47              : 
      48            0 :         if (soldier.control.up) {
      49            0 :             return std::nullopt;
      50              :         }
      51              : 
      52            0 :         return std::make_shared<LegsFallAnimationState>(animation_data_manager_);
      53              :     }
      54              : 
      55            0 :     if (soldier.control.up && soldier.on_ground) {
      56            0 :         soldier.control.was_running_left = soldier.control.left;
      57            0 :         return std::make_shared<LegsJumpSideAnimationState>(animation_data_manager_);
      58              :     }
      59              : 
      60            0 :     if (soldier.control.left && soldier.direction == 1) {
      61            0 :         return std::make_shared<LegsRunBackAnimationState>(animation_data_manager_);
      62              :     }
      63              : 
      64            0 :     if (soldier.control.right && soldier.direction == -1) {
      65            0 :         return std::make_shared<LegsRunBackAnimationState>(animation_data_manager_);
      66              :     }
      67              : 
      68              :     // if using jets, reset animation because first frame looks like "directional" jetting
      69            0 :     if (soldier.control.jets && soldier.jets_count > 0) {
      70            0 :         if (soldier.control.up) {
      71            0 :             return std::make_shared<LegsFallAnimationState>(animation_data_manager_);
      72              :         }
      73            0 :         return std::make_shared<LegsRunAnimationState>(animation_data_manager_);
      74              :     }
      75              : 
      76            0 :     return std::nullopt;
      77              : }
      78              : 
      79            0 : void LegsRunAnimationState::Update(Soldier& soldier, const PhysicsEvents& physics_events)
      80              : {
      81            0 :     soldier.stance = PhysicsConstants::STANCE_STAND;
      82            0 :     if (soldier.control.left && !soldier.control.up && soldier.direction == -1) {
      83            0 :         glm::vec2 particle_force = soldier.particle.GetForce();
      84            0 :         if (soldier.on_ground) {
      85            0 :             particle_force.x = -PhysicsConstants::RUNSPEED;
      86            0 :             particle_force.y = -PhysicsConstants::RUNSPEEDUP;
      87              :         } else {
      88            0 :             particle_force.x = -PhysicsConstants::FLYSPEED;
      89              :         }
      90            0 :         soldier.particle.SetForce(particle_force);
      91            0 :     } else if (soldier.control.right && !soldier.control.up && soldier.direction == 1) {
      92            0 :         if (soldier.on_ground) {
      93            0 :             glm::vec2 particle_force = soldier.particle.GetForce();
      94            0 :             particle_force.x = PhysicsConstants::RUNSPEED;
      95            0 :             particle_force.y = -PhysicsConstants::RUNSPEEDUP;
      96            0 :             soldier.particle.SetForce(particle_force);
      97              :         } else {
      98            0 :             glm::vec2 particle_force = soldier.particle.GetForce();
      99            0 :             particle_force.x = PhysicsConstants::FLYSPEED;
     100            0 :             soldier.particle.SetForce(particle_force);
     101              :         }
     102              :     }
     103            0 : }
     104              : } // namespace Soldank
        

Generated by: LCOV version 2.0-1