diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1d59522..63f706e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,6 +8,24 @@ on: workflow_dispatch: jobs: + rustfmt_check: + name: Code Formatting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install minimal nightly rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + components: rustfmt, clippy + default: true + target: x86_64-unknown-linux-gnu + - name: rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check checker: name: Check, Clippy, Tests runs-on: ubuntu-latest diff --git a/src/common/consts.rs b/src/common/consts.rs index 4a311f4..3a14928 100644 --- a/src/common/consts.rs +++ b/src/common/consts.rs @@ -1,2 +1 @@ pub use training_mod_consts::*; - diff --git a/src/common/dev_config.rs b/src/common/dev_config.rs index 9d67453..f65c72f 100644 --- a/src/common/dev_config.rs +++ b/src/common/dev_config.rs @@ -38,7 +38,7 @@ pub unsafe fn config() -> &'static DevConfig { } lazy_static! { - pub static ref DEV_CONFIG : Mutex = Mutex::new(DevConfig::load_from_toml()); + pub static ref DEV_CONFIG: Mutex = Mutex::new(DevConfig::load_from_toml()); } impl DevConfig { @@ -46,7 +46,8 @@ impl DevConfig { let dev_path = DEV_TOML_PATH; if fs::metadata(dev_path).is_ok() { info!("Loading dev.toml configs..."); - let dev_config_str = fs::read_to_string(dev_path).unwrap_or_else(|_| panic!("Could not read {}", dev_path)); + let dev_config_str = fs::read_to_string(dev_path) + .unwrap_or_else(|_| panic!("Could not read {}", dev_path)); return toml::from_str(&dev_config_str).expect("Could not parse dev config"); } diff --git a/src/lib.rs b/src/lib.rs index 4832f93..91cadbe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,7 +84,11 @@ pub fn main() { "Shield + Downtaunt".to_string(), 120, ); - notification("Load State".to_string(), "Shield + Uptaunt".to_string(), 120); + notification( + "Load State".to_string(), + "Shield + Uptaunt".to_string(), + 120, + ); } hitbox_visualizer::hitbox_visualization(); @@ -105,8 +109,9 @@ pub fn main() { error!("Could not move file from {src_path:#?} to {dest_path:#?} with error {e}") }); } - fs::remove_dir_all(LEGACY_TRAINING_MODPACK_ROOT) - .unwrap_or_else(|e| error!("Could not delete legacy Training Modpack folder with error {e}")); + fs::remove_dir_all(LEGACY_TRAINING_MODPACK_ROOT).unwrap_or_else(|e| { + error!("Could not delete legacy Training Modpack folder with error {e}") + }); } info!("Performing version check..."); diff --git a/src/training/attack_angle.rs b/src/training/attack_angle.rs index 15d3913..1de2f6c 100644 --- a/src/training/attack_angle.rs +++ b/src/training/attack_angle.rs @@ -1,7 +1,7 @@ use smash::app::{self}; -use crate::common::*; use crate::common::consts::*; +use crate::common::*; static mut DIRECTION: AttackAngle = AttackAngle::UP; diff --git a/src/training/charge.rs b/src/training/charge.rs index 1d311e9..a3202fb 100644 --- a/src/training/charge.rs +++ b/src/training/charge.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use smash::app::{self, ArticleOperationTarget, FighterFacial, FighterUtil, lua_bind::*}; +use smash::app::{self, lua_bind::*, ArticleOperationTarget, FighterFacial, FighterUtil}; use smash::lib::lua_const::*; use smash::phx::{Hash40, Vector3f}; diff --git a/src/training/clatter.rs b/src/training/clatter.rs index df173c9..cc7b9d3 100644 --- a/src/training/clatter.rs +++ b/src/training/clatter.rs @@ -1,10 +1,10 @@ -use smash::app::BattleObjectModuleAccessor; use smash::app::lua_bind::{ControlModule, EffectModule}; +use smash::app::BattleObjectModuleAccessor; use smash::lib::lua_const::*; use smash::phx::{Hash40, Vector3f}; -use crate::common::*; use crate::common::consts::*; +use crate::common::*; use crate::training::mash; static mut COUNTER: u32 = 0; diff --git a/src/training/combo.rs b/src/training/combo.rs index 8566c34..921b107 100644 --- a/src/training/combo.rs +++ b/src/training/combo.rs @@ -1,8 +1,8 @@ use skyline::nn::ui2d::ResColor; use training_mod_consts::OnOff; -use crate::common::*; use crate::common::consts::FighterId; +use crate::common::*; use crate::training::*; pub static mut FRAME_ADVANTAGE: i32 = 0; @@ -57,9 +57,24 @@ fn update_frame_advantage(new_frame_adv: i32) { format!("{FRAME_ADVANTAGE}"), 60, match FRAME_ADVANTAGE { - x if x < 0 => ResColor { r: 200, g: 8, b: 8, a: 255 }, - x if x == 0 => ResColor { r: 0, g: 0, b: 0, a: 255 }, - _ => ResColor { r: 31, g: 198, b: 0, a: 255 }, + x if x < 0 => ResColor { + r: 200, + g: 8, + b: 8, + a: 255, + }, + x if x == 0 => ResColor { + r: 0, + g: 0, + b: 0, + a: 255, + }, + _ => ResColor { + r: 31, + g: 198, + b: 0, + a: 255, + }, }, ); } @@ -83,10 +98,10 @@ pub unsafe fn is_enable_transition_term( if !PLAYER_ACTIONABLE && ((is - && actionable_statuses!() - .iter() - .any(|actionable_transition| *actionable_transition == transition_term)) - || (CancelModule::is_enable_cancel(module_accessor))) + && actionable_statuses!() + .iter() + .any(|actionable_transition| *actionable_transition == transition_term)) + || (CancelModule::is_enable_cancel(module_accessor))) { PLAYER_ACTIVE_FRAME = frame_counter::get_frame_count(FRAME_COUNTER_INDEX); PLAYER_ACTIONABLE = true; diff --git a/src/training/crouch.rs b/src/training/crouch.rs index eb41092..394d7da 100644 --- a/src/training/crouch.rs +++ b/src/training/crouch.rs @@ -1,8 +1,8 @@ -use smash::app::{BattleObjectModuleAccessor, lua_bind::StatusModule}; +use smash::app::{lua_bind::StatusModule, BattleObjectModuleAccessor}; use smash::lib::lua_const::*; -use crate::common::*; use crate::common::consts::OnOff; +use crate::common::*; pub unsafe fn mod_get_stick_y(module_accessor: &mut BattleObjectModuleAccessor) -> Option { if !is_operation_cpu(module_accessor) { @@ -12,13 +12,13 @@ pub unsafe fn mod_get_stick_y(module_accessor: &mut BattleObjectModuleAccessor) if MENU.crouch == OnOff::On && [ - *FIGHTER_STATUS_KIND_WAIT, - *FIGHTER_STATUS_KIND_SQUAT, - *FIGHTER_STATUS_KIND_SQUAT_B, - *FIGHTER_STATUS_KIND_SQUAT_F, - *FIGHTER_STATUS_KIND_SQUAT_RV, - *FIGHTER_STATUS_KIND_SQUAT_WAIT, - ] + *FIGHTER_STATUS_KIND_WAIT, + *FIGHTER_STATUS_KIND_SQUAT, + *FIGHTER_STATUS_KIND_SQUAT_B, + *FIGHTER_STATUS_KIND_SQUAT_F, + *FIGHTER_STATUS_KIND_SQUAT_RV, + *FIGHTER_STATUS_KIND_SQUAT_WAIT, + ] .contains(&fighter_status_kind) { Some(-1.0) diff --git a/src/training/directional_influence.rs b/src/training/directional_influence.rs index d00dea7..647ea88 100644 --- a/src/training/directional_influence.rs +++ b/src/training/directional_influence.rs @@ -1,12 +1,12 @@ use core::f64::consts::PI; use smash::app::{self, lua_bind::*, sv_system}; -use smash::lib::L2CValue; use smash::lib::lua_const::*; +use smash::lib::L2CValue; use smash::lua2cpp::L2CFighterCommon; -use crate::common::*; use crate::common::consts::*; +use crate::common::*; static mut DI_CASE: Direction = Direction::empty(); diff --git a/src/training/frame_counter.rs b/src/training/frame_counter.rs index 08e37f7..1b4e252 100644 --- a/src/training/frame_counter.rs +++ b/src/training/frame_counter.rs @@ -65,7 +65,9 @@ pub fn get_frame_count(index: usize) -> u32 { } pub fn tick_idx(index: usize) { - unsafe { COUNTERS[index] += 1; } + unsafe { + COUNTERS[index] += 1; + } } fn tick() { diff --git a/src/training/ledge.rs b/src/training/ledge.rs index be59877..88a2a9a 100644 --- a/src/training/ledge.rs +++ b/src/training/ledge.rs @@ -1,8 +1,8 @@ use smash::app::{self, lua_bind::*}; use smash::lib::lua_const::*; -use crate::common::*; use crate::common::consts::*; +use crate::common::*; use crate::training::frame_counter; use crate::training::mash; diff --git a/src/training/mash.rs b/src/training/mash.rs index 089a997..220ea7f 100644 --- a/src/training/mash.rs +++ b/src/training/mash.rs @@ -1,14 +1,14 @@ use smash::app::{self, lua_bind::*}; use smash::lib::lua_const::*; -use crate::common::*; use crate::common::consts::*; -use crate::training::{attack_angle, save_states}; +use crate::common::*; use crate::training::character_specific; use crate::training::fast_fall; use crate::training::frame_counter; use crate::training::full_hop; use crate::training::shield; +use crate::training::{attack_angle, save_states}; const DISTANCE_CLOSE_THRESHOLD: f32 = 16.0; const DISTANCE_MID_THRESHOLD: f32 = 37.0; diff --git a/src/training/save_states.rs b/src/training/save_states.rs index 92a7bf0..d31b25c 100644 --- a/src/training/save_states.rs +++ b/src/training/save_states.rs @@ -354,7 +354,8 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) ] .contains(&fighter_kind); - if MENU.save_state_slot_enable == OnOff::On && !is_operation_cpu(module_accessor) + if MENU.save_state_slot_enable == OnOff::On + && !is_operation_cpu(module_accessor) && button_config::combo_passes_exclusive( module_accessor, button_config::ButtonCombo::PrevSaveStateSlot, @@ -375,7 +376,8 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) return; } - if MENU.save_state_slot_enable == OnOff::On && !is_operation_cpu(module_accessor) + if MENU.save_state_slot_enable == OnOff::On + && !is_operation_cpu(module_accessor) && button_config::combo_passes_exclusive( module_accessor, button_config::ButtonCombo::NextSaveStateSlot, diff --git a/src/training/sdi.rs b/src/training/sdi.rs index af0c5fe..c39f652 100644 --- a/src/training/sdi.rs +++ b/src/training/sdi.rs @@ -3,8 +3,8 @@ use core::f64::consts::PI; use smash::app::{self, lua_bind::*}; use smash::Vector2f; -use crate::common::*; use crate::common::consts::*; +use crate::common::*; use crate::training::directional_influence; static mut COUNTER: u32 = 0; diff --git a/src/training/shield.rs b/src/training/shield.rs index f48b90e..99cbe55 100644 --- a/src/training/shield.rs +++ b/src/training/shield.rs @@ -2,14 +2,14 @@ use smash::app; use smash::app::lua_bind::*; use smash::app::sv_system; use smash::hash40; -use smash::lib::L2CValue; use smash::lib::lua_const::*; +use smash::lib::L2CValue; use smash::lua2cpp::L2CFighterCommon; -use crate::common::*; use crate::common::consts::*; -use crate::training::{frame_counter, save_states}; +use crate::common::*; use crate::training::mash; +use crate::training::{frame_counter, save_states}; // How many hits to hold shield until picking an Out Of Shield option static mut MULTI_HIT_OFFSET: u32 = 0; @@ -188,8 +188,9 @@ pub fn should_hold_shield(module_accessor: &mut app::BattleObjectModuleAccessor) } // We should hold shield if the state requires it - if unsafe { save_states::is_loading() } || - ![Shield::Hold, Shield::Infinite, Shield::Constant].contains(shield_state) { + if unsafe { save_states::is_loading() } + || ![Shield::Hold, Shield::Infinite, Shield::Constant].contains(shield_state) + { return false; } diff --git a/src/training/shield_tilt.rs b/src/training/shield_tilt.rs index 6920bac..bf42bd9 100644 --- a/src/training/shield_tilt.rs +++ b/src/training/shield_tilt.rs @@ -1,7 +1,7 @@ use smash::app::{self}; -use crate::common::*; use crate::common::consts::*; +use crate::common::*; static mut STICK_DIRECTION: Direction = Direction::OUT; diff --git a/src/training/throw.rs b/src/training/throw.rs index a713eea..41d8894 100644 --- a/src/training/throw.rs +++ b/src/training/throw.rs @@ -1,8 +1,8 @@ use smash::app::{self, lua_bind::*}; use smash::lib::lua_const::*; -use crate::common::*; use crate::common::consts::*; +use crate::common::*; use crate::training::frame_counter; use crate::training::mash; diff --git a/src/training/ui/display.rs b/src/training/ui/display.rs index 8c8d706..d2040ed 100644 --- a/src/training/ui/display.rs +++ b/src/training/ui/display.rs @@ -27,8 +27,10 @@ pub unsafe fn draw(root_pane: &mut Pane) { let queue = &mut ui::notifications::QUEUE; let notification = queue.first(); - root_pane.find_pane_by_name_recursive(display_parent_fmt!(notification_idx)) - .unwrap().set_visible(notification.is_some()); + root_pane + .find_pane_by_name_recursive(display_parent_fmt!(notification_idx)) + .unwrap() + .set_visible(notification.is_some()); if notification.is_none() { return; } @@ -36,12 +38,16 @@ pub unsafe fn draw(root_pane: &mut Pane) { let notification = notification.unwrap(); let color = notification.color; - root_pane.find_pane_by_name_recursive(display_header_fmt!(notification_idx)) + root_pane + .find_pane_by_name_recursive(display_header_fmt!(notification_idx)) .unwrap() - .as_textbox().set_text_string(¬ification.header); + .as_textbox() + .set_text_string(¬ification.header); - let text = root_pane.find_pane_by_name_recursive(display_txt_fmt!(notification_idx)) - .unwrap().as_textbox(); + let text = root_pane + .find_pane_by_name_recursive(display_txt_fmt!(notification_idx)) + .unwrap() + .as_textbox(); text.set_text_string(¬ification.message); text.set_default_material_colors(); text.set_color(color.r, color.g, color.b, color.a); @@ -51,4 +57,4 @@ pub unsafe fn draw(root_pane: &mut Pane) { if has_completed { queue.remove(0); } -} \ No newline at end of file +} diff --git a/src/training/ui/notifications.rs b/src/training/ui/notifications.rs index b1d0b5a..602d72c 100644 --- a/src/training/ui/notifications.rs +++ b/src/training/ui/notifications.rs @@ -33,12 +33,17 @@ impl Notification { pub fn notification(header: String, message: String, len: u32) { unsafe { let queue = &mut QUEUE; - queue.push(Notification::new(header, message, len, ResColor { - r: 0, - g: 0, - b: 0, - a: 255, - })); + queue.push(Notification::new( + header, + message, + len, + ResColor { + r: 0, + g: 0, + b: 0, + a: 255, + }, + )); } } @@ -54,4 +59,4 @@ pub fn clear_notifications(header: &'static str) { let queue = &mut QUEUE; queue.retain(|notif| notif.header != header); } -} \ No newline at end of file +} diff --git a/training_mod_consts/src/options.rs b/training_mod_consts/src/options.rs index e92181a..4272322 100644 --- a/training_mod_consts/src/options.rs +++ b/training_mod_consts/src/options.rs @@ -6,7 +6,6 @@ use smash::lib::lua_const::*; use strum::IntoEnumIterator; use strum_macros::EnumIter; - const fn num_bits() -> u32 { (std::mem::size_of::() * 8) as u32 } @@ -1105,4 +1104,4 @@ impl SaveDamage { } extra_bitflag_impls! {SaveDamage} -impl_serde_for_bitflags!(SaveDamage); \ No newline at end of file +impl_serde_for_bitflags!(SaveDamage); diff --git a/training_mod_tui/src/list.rs b/training_mod_tui/src/list.rs index fb1aa0f..103d82f 100644 --- a/training_mod_tui/src/list.rs +++ b/training_mod_tui/src/list.rs @@ -3,15 +3,13 @@ use tui::widgets::ListState; pub struct MultiStatefulList { pub lists: Vec>, pub state: usize, - pub total_len: usize + pub total_len: usize, } impl MultiStatefulList { pub fn selected_list_item(&mut self) -> &mut T { let (list_section, list_idx) = self.idx_to_list_idx(self.state); - &mut self - .lists[list_section] - .items[list_idx] + &mut self.lists[list_section].items[list_idx] } pub fn idx_to_list_idx(&self, idx: usize) -> (usize, usize) { @@ -20,15 +18,18 @@ impl MultiStatefulList { pub fn idx_to_list_idx_opt(&self, idx: usize) -> Option<(usize, usize)> { for list_section in 0..self.lists.len() { - let list_section_min_idx = (self.total_len as f32 / self.lists.len() as f32).ceil() as usize * list_section; + let list_section_min_idx = + (self.total_len as f32 / self.lists.len() as f32).ceil() as usize * list_section; let list_section_max_idx = std::cmp::min( - (self.total_len as f32 / self.lists.len() as f32).ceil() as usize * (list_section + 1), - self.total_len); + (self.total_len as f32 / self.lists.len() as f32).ceil() as usize + * (list_section + 1), + self.total_len, + ); if (list_section_min_idx..list_section_max_idx).contains(&idx) { return Some((list_section, idx - list_section_min_idx)); } } - + None } @@ -42,37 +43,41 @@ impl MultiStatefulList { } pub fn with_items(items: Vec, num_lists: usize) -> MultiStatefulList { - let lists = (0..num_lists).map(|list_section| { - let list_section_min_idx = (items.len() as f32 / num_lists as f32).ceil() as usize * list_section; - let list_section_max_idx = std::cmp::min( - (items.len() as f32 / num_lists as f32).ceil() as usize * (list_section + 1), - items.len()); - let mut state = ListState::default(); - if list_section == 0 { - // Enforce state as first of list - state.select(Some(0)); - } - StatefulList { - state, - items: items[list_section_min_idx..list_section_max_idx].to_vec(), - } - }).collect(); + let lists = (0..num_lists) + .map(|list_section| { + let list_section_min_idx = + (items.len() as f32 / num_lists as f32).ceil() as usize * list_section; + let list_section_max_idx = std::cmp::min( + (items.len() as f32 / num_lists as f32).ceil() as usize * (list_section + 1), + items.len(), + ); + let mut state = ListState::default(); + if list_section == 0 { + // Enforce state as first of list + state.select(Some(0)); + } + StatefulList { + state, + items: items[list_section_min_idx..list_section_max_idx].to_vec(), + } + }) + .collect(); let total_len = items.len(); MultiStatefulList { lists, total_len, - state: 0 + state: 0, } } pub fn next(&mut self) { let (list_section, _) = self.idx_to_list_idx(self.state); - let (next_list_section, next_list_idx) = self.idx_to_list_idx(self.state+1); + let (next_list_section, next_list_idx) = self.idx_to_list_idx(self.state + 1); if list_section != next_list_section { self.lists[list_section].unselect(); } - let state= if self.state + 1 >= self.total_len { + let state = if self.state + 1 >= self.total_len { (0, 0) } else { (next_list_section, next_list_idx) @@ -84,10 +89,13 @@ impl MultiStatefulList { pub fn previous(&mut self) { let (list_section, _) = self.idx_to_list_idx(self.state); - let (last_list_section, last_list_idx) = (self.lists.len() - 1, self.lists[self.lists.len() - 1].items.len() - 1); + let (last_list_section, last_list_idx) = ( + self.lists.len() - 1, + self.lists[self.lists.len() - 1].items.len() - 1, + ); self.lists[list_section].unselect(); - let state= if self.state == 0 { + let state = if self.state == 0 { (last_list_section, last_list_idx) } else { let (prev_list_section, prev_list_idx) = self.idx_to_list_idx(self.state - 1); @@ -124,7 +132,7 @@ impl MultiStatefulList { list_section - 1 }; - let prev_list_idx= if list_idx > self.lists[prev_list_section].items.len() - 1 { + let prev_list_idx = if list_idx > self.lists[prev_list_section].items.len() - 1 { self.lists[prev_list_section].items.len() - 1 } else { list_idx @@ -150,10 +158,7 @@ impl StatefulList { let mut state = ListState::default(); // Enforce state as first of list state.select(Some(0)); - StatefulList { - state, - items, - } + StatefulList { state, items } } pub fn next(&mut self) { @@ -187,4 +192,4 @@ impl StatefulList { pub fn unselect(&mut self) { self.state.select(None); } -} \ No newline at end of file +}