From 715c28dd6c22586b2b0b79d95b3a0cb68b31365d Mon Sep 17 00:00:00 2001
From: sidschingis <SijingYou92@gmail.com>
Date: Sat, 13 Jun 2020 21:34:06 +0200
Subject: [PATCH] Move Angle Calculation To Common

Renamed NO_DI to ANGLE_NONE and moved to common
---
 src/common/consts.rs                  | 17 +++++++++++++++--
 src/training/directional_influence.rs |  9 ++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/common/consts.rs b/src/common/consts.rs
index 52ec5e90..b7efc51e 100644
--- a/src/common/consts.rs
+++ b/src/common/consts.rs
@@ -1,3 +1,4 @@
+use core::f64::consts::PI;
 use smash::lib::lua_const::*;
 
 /// Hitbox Visualization
@@ -19,7 +20,7 @@ pub enum HitboxVisualization {
 #[derive(Debug, Clone, Copy, PartialEq)]
 pub enum Direction {
     None = 0,
-    Right =1,
+    Right = 1,
     UpRight = 2,
     Up = 3,
     UpLeft = 4,
@@ -49,6 +50,18 @@ impl From<i32> for Direction {
     }
 }
 
+
+//pub static FIGHTER_FACING_LEFT: f32 = 1.0;
+pub static FIGHTER_FACING_RIGHT: f32 = -1.0;
+pub static ANGLE_NONE: f64 = -69.0;
+pub fn direction_to_angle(direction: Direction) -> f64 {
+    match direction {
+        Direction::None => ANGLE_NONE,
+        Direction::Random => ANGLE_NONE, // Random Direction should be handled by the calling context
+        _ => (direction as i32 - 1) as f64 * PI / 4.0,
+    }
+}
+
 /// Mash Attack States
 #[repr(i32)]
 #[derive(PartialEq, Debug, Copy, Clone)]
@@ -254,5 +267,5 @@ pub struct TrainingModpackMenu {
     pub shield_state: Shield,
     pub defensive_state: Defensive,
     pub oos_offset: i32,
-    pub mash_in_neutral: MashInNeutral
+    pub mash_in_neutral: MashInNeutral,
 }
diff --git a/src/training/directional_influence.rs b/src/training/directional_influence.rs
index 69485a01..29c5ec08 100644
--- a/src/training/directional_influence.rs
+++ b/src/training/directional_influence.rs
@@ -8,7 +8,6 @@ use smash::lib::L2CValue;
 use smash::lua2cpp::L2CFighterCommon;
 
 pub static mut DI_ANGLE: f64 = 0.0;
-pub static NO_DI: f64 = -69.0;
 
 #[skyline::hook(replace = smash::lua2cpp::L2CFighterCommon_FighterStatusDamage__correctDamageVectorCommon)]
 pub unsafe fn handle_correct_damage_vector_common(
@@ -37,16 +36,16 @@ unsafe fn mod_handle_di(fighter: &mut L2CFighterCommon, _arg1: L2CValue) {
     if MENU.di_state == Direction::Random {
         DI_ANGLE = get_random_di();
     } else {
-        DI_ANGLE = (MENU.di_state as i32 - 1) as f64 * PI / 4.0;
+        DI_ANGLE = direction_to_angle(MENU.di_state)
     }
 
     // If facing left, reverse angle
-    if DI_ANGLE != NO_DI && PostureModule::lr(module_accessor) != -1.0 {
+    if DI_ANGLE != ANGLE_NONE && PostureModule::lr(module_accessor) != FIGHTER_FACING_RIGHT {
         DI_ANGLE -= PI;
     }
 
     // Nothig to do on no DI
-    if DI_ANGLE == NO_DI {
+    if DI_ANGLE == ANGLE_NONE {
         return;
     }
 
@@ -68,6 +67,6 @@ unsafe fn get_random_di() -> f64 {
         // Either 0 (right) or PI (left)
         rand as f64 * PI
     } else {
-        NO_DI
+        ANGLE_NONE
     }
 }