mirror of
https://github.com/jugeeya/UltimateTrainingModpack.git
synced 2024-11-20 08:54:15 +00:00
Format Rust code using rustfmt
This commit is contained in:
parent
2f032c1fc0
commit
dee5e56433
3 changed files with 65 additions and 27 deletions
|
@ -1,8 +1,8 @@
|
|||
use lazy_static::lazy_static;
|
||||
use parking_lot::Mutex;
|
||||
use serde::Deserialize;
|
||||
use smash::app::lua_bind::ControlModule;
|
||||
use smash::lib::lua_const::*;
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
use toml;
|
||||
|
||||
|
@ -22,17 +22,26 @@ lazy_static! {
|
|||
("JUMPMINI", 0xA), // *CONTROL_PAD_BUTTON_JUMP_MINI
|
||||
]);
|
||||
}
|
||||
static mut BUTTON_COMBO_CONFIG: BtnComboConfig = BtnComboConfig{
|
||||
open_menu: BtnList{ hold: vec![], press: vec![] },
|
||||
save_state: BtnList{ hold: vec![], press: vec![] },
|
||||
load_state: BtnList{ hold: vec![], press: vec![] },
|
||||
static mut BUTTON_COMBO_CONFIG: BtnComboConfig = BtnComboConfig {
|
||||
open_menu: BtnList {
|
||||
hold: vec![],
|
||||
press: vec![],
|
||||
},
|
||||
save_state: BtnList {
|
||||
hold: vec![],
|
||||
press: vec![],
|
||||
},
|
||||
load_state: BtnList {
|
||||
hold: vec![],
|
||||
press: vec![],
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ButtonCombo {
|
||||
OpenMenu,
|
||||
SaveState,
|
||||
LoadState
|
||||
LoadState,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
|
@ -57,11 +66,16 @@ pub fn validate_config(data: &str) -> bool {
|
|||
let conf: TopLevelBtnComboConfig = toml::from_str(data).unwrap();
|
||||
let conf = conf.button_config;
|
||||
let configs = [conf.open_menu, conf.save_state, conf.load_state];
|
||||
let bad_keys = configs.iter().flat_map(|btn_list| {
|
||||
btn_list.hold.iter()
|
||||
let bad_keys = configs
|
||||
.iter()
|
||||
.flat_map(|btn_list| {
|
||||
btn_list
|
||||
.hold
|
||||
.iter()
|
||||
.chain(btn_list.press.iter())
|
||||
.filter(|x| !BUTTON_MAPPING.contains_key(x.to_uppercase().as_str()))
|
||||
}).collect::<Vec<&String>>();
|
||||
})
|
||||
.collect::<Vec<&String>>();
|
||||
|
||||
if !bad_keys.is_empty() {
|
||||
skyline::error::show_error(
|
||||
|
@ -69,7 +83,10 @@ pub fn validate_config(data: &str) -> bool {
|
|||
"Training Modpack custom button\nconfiguration is invalid!\0",
|
||||
&format!(
|
||||
"The following keys are invalid in\nsd:/TrainingModpack/training_modpack.toml:\n\
|
||||
{:?}\n\nPossible Keys: {:#?}\0", &bad_keys, BUTTON_MAPPING.keys())
|
||||
{:?}\n\nPossible Keys: {:#?}\0",
|
||||
&bad_keys,
|
||||
BUTTON_MAPPING.keys()
|
||||
),
|
||||
);
|
||||
false
|
||||
} else {
|
||||
|
@ -80,10 +97,19 @@ pub fn validate_config(data: &str) -> bool {
|
|||
pub fn save_all_btn_config_from_defaults() {
|
||||
let conf = TopLevelBtnComboConfig {
|
||||
button_config: BtnComboConfig {
|
||||
open_menu: BtnList { hold: vec!["SPECIAL".to_string()], press: vec!["UPTAUNT".to_string()] },
|
||||
save_state: BtnList { hold: vec!["GRAB".to_string()], press: vec!["DOWNTAUNT".to_string()] },
|
||||
load_state: BtnList { hold: vec!["GRAB".to_string()], press: vec!["UPTAUNT".to_string()] },
|
||||
}
|
||||
open_menu: BtnList {
|
||||
hold: vec!["SPECIAL".to_string()],
|
||||
press: vec!["UPTAUNT".to_string()],
|
||||
},
|
||||
save_state: BtnList {
|
||||
hold: vec!["GRAB".to_string()],
|
||||
press: vec!["DOWNTAUNT".to_string()],
|
||||
},
|
||||
load_state: BtnList {
|
||||
hold: vec!["GRAB".to_string()],
|
||||
press: vec!["UPTAUNT".to_string()],
|
||||
},
|
||||
},
|
||||
};
|
||||
unsafe {
|
||||
// This println is necessary. Why?.......
|
||||
|
@ -101,17 +127,30 @@ pub fn save_all_btn_config_from_toml(data: &str) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn combo_passes(module_accessor: *mut smash::app::BattleObjectModuleAccessor, combo: ButtonCombo) -> bool{
|
||||
pub fn combo_passes(
|
||||
module_accessor: *mut smash::app::BattleObjectModuleAccessor,
|
||||
combo: ButtonCombo,
|
||||
) -> bool {
|
||||
unsafe {
|
||||
let (hold, press) = match combo {
|
||||
ButtonCombo::OpenMenu => (&BUTTON_COMBO_CONFIG.open_menu.hold, &BUTTON_COMBO_CONFIG.open_menu.press),
|
||||
ButtonCombo::SaveState => (&BUTTON_COMBO_CONFIG.save_state.hold, &BUTTON_COMBO_CONFIG.save_state.press),
|
||||
ButtonCombo::LoadState => (&BUTTON_COMBO_CONFIG.load_state.hold, &BUTTON_COMBO_CONFIG.load_state.press),
|
||||
ButtonCombo::OpenMenu => (
|
||||
&BUTTON_COMBO_CONFIG.open_menu.hold,
|
||||
&BUTTON_COMBO_CONFIG.open_menu.press,
|
||||
),
|
||||
ButtonCombo::SaveState => (
|
||||
&BUTTON_COMBO_CONFIG.save_state.hold,
|
||||
&BUTTON_COMBO_CONFIG.save_state.press,
|
||||
),
|
||||
ButtonCombo::LoadState => (
|
||||
&BUTTON_COMBO_CONFIG.load_state.hold,
|
||||
&BUTTON_COMBO_CONFIG.load_state.press,
|
||||
),
|
||||
};
|
||||
hold.iter()
|
||||
.map(|hold| *BUTTON_MAPPING.get(&*hold.to_uppercase()).unwrap())
|
||||
.all(|hold| ControlModule::check_button_on(module_accessor, hold))
|
||||
&& press.iter()
|
||||
&& press
|
||||
.iter()
|
||||
.map(|press| *BUTTON_MAPPING.get(&*press.to_uppercase()).unwrap())
|
||||
.all(|press| ControlModule::check_button_trigger(module_accessor, press))
|
||||
}
|
||||
|
|
|
@ -35,9 +35,7 @@ pub unsafe fn menu_condition(module_accessor: &mut smash::app::BattleObjectModul
|
|||
|
||||
// Only check for button combination if the counter is 0 (not locked out)
|
||||
match frame_counter::get_frame_count(FRAME_COUNTER_INDEX) {
|
||||
0 => {
|
||||
button_config::combo_passes(module_accessor, button_config::ButtonCombo::OpenMenu)
|
||||
}
|
||||
0 => button_config::combo_passes(module_accessor, button_config::ButtonCombo::OpenMenu),
|
||||
1..MENU_LOCKOUT_FRAMES => false,
|
||||
_ => {
|
||||
// Waited longer than the lockout time, reset the counter so the menu can be opened again
|
||||
|
|
|
@ -237,7 +237,8 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor)
|
|||
&& is_dead(module_accessor);
|
||||
let mut triggered_reset: bool = false;
|
||||
if !is_operation_cpu(module_accessor) {
|
||||
triggered_reset = button_config::combo_passes(module_accessor, button_config::ButtonCombo::LoadState);
|
||||
triggered_reset =
|
||||
button_config::combo_passes(module_accessor, button_config::ButtonCombo::LoadState);
|
||||
}
|
||||
if (autoload_reset || triggered_reset) && !fighter_is_nana {
|
||||
if save_state.state == NoAction {
|
||||
|
|
Loading…
Reference in a new issue