diff --git a/src/lib.rs b/src/lib.rs index f32893c..7eb6321 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,7 +145,7 @@ pub fn main() { std::thread::sleep(std::time::Duration::from_secs(10)); let menu; unsafe { - menu = crate::common::consts::get_menu(); + menu = consts::get_menu(); } let mut app = training_mod_tui::App::new(menu); @@ -157,7 +157,7 @@ pub fn main() { let mut has_slept_millis = 0; let render_frames = 5; let mut url = String::new(); - let button_presses = &mut common::menu::BUTTON_PRESSES; + let button_presses = &mut menu::BUTTON_PRESSES; let mut received_input = true; loop { button_presses.a.read_press().then(|| { @@ -174,7 +174,7 @@ pub fn main() { { // Leave menu. menu::QUICK_MENU_ACTIVE = false; - crate::menu::set_menu_from_url(url.as_str()); + menu::set_menu_from_url(url.as_str()); println!("URL: {}", url.as_str()); } }); @@ -210,7 +210,7 @@ pub fn main() { } has_slept_millis = 16; if !menu::QUICK_MENU_ACTIVE { - app = training_mod_tui::App::new(crate::common::consts::get_menu()); + app = training_mod_tui::App::new(consts::get_menu()); set_should_display_text_to_screen(false); continue; } diff --git a/src/training/mod.rs b/src/training/mod.rs index 3d457e5..c59f01e 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -109,8 +109,8 @@ fn once_per_frame_per_fighter( } unsafe { - if crate::common::menu::menu_condition(module_accessor) { - crate::common::menu::spawn_menu(); + if menu::menu_condition(module_accessor) { + menu::spawn_menu(); } input_record::get_command_flag_cat(module_accessor); diff --git a/training_mod_consts/src/lib.rs b/training_mod_consts/src/lib.rs index b521f9d..7933f2e 100644 --- a/training_mod_consts/src/lib.rs +++ b/training_mod_consts/src/lib.rs @@ -1571,19 +1571,15 @@ pub unsafe fn get_menu() -> UiMenu<'static> { let non_ui_menu = MENU; let url_params = non_ui_menu.to_url_params(false); let toggle_values_all = url_params.split("&"); - let mut sub_menu_id_to_vals : HashMap<&str, Vec> = HashMap::new(); + let mut sub_menu_id_to_vals : HashMap<&str, u32> = HashMap::new(); for toggle_values in toggle_values_all { let toggle_value_split = toggle_values.split('=').collect::>(); let mut sub_menu_id = toggle_value_split[0]; if sub_menu_id.is_empty() { continue } sub_menu_id = sub_menu_id.strip_prefix("__").unwrap_or(sub_menu_id); - let bits: u32 = toggle_value_split[1].parse().unwrap_or(0); - if sub_menu_id_to_vals.contains_key(sub_menu_id) { - sub_menu_id_to_vals.get_mut(sub_menu_id).unwrap().push(bits); - } else { - sub_menu_id_to_vals.insert(sub_menu_id, vec![bits]); - } + let full_bits: u32 = toggle_value_split[1].parse().unwrap_or(0); + sub_menu_id_to_vals.insert(sub_menu_id, full_bits); } overall_menu.tabs.iter_mut() .for_each(|tab| { @@ -1591,7 +1587,7 @@ pub unsafe fn get_menu() -> UiMenu<'static> { let sub_menu_id = sub_menu.submenu_id; sub_menu.toggles.iter_mut().for_each(|toggle| { if sub_menu_id_to_vals.contains_key(sub_menu_id) && - sub_menu_id_to_vals[sub_menu_id].contains(&(toggle.toggle_value as u32)) { + (sub_menu_id_to_vals[sub_menu_id] & (toggle.toggle_value as u32) != 0) { toggle.checked = true } }) diff --git a/training_mod_tui/src/main.rs b/training_mod_tui/src/main.rs index 9e4424e..a614566 100644 --- a/training_mod_tui/src/main.rs +++ b/training_mod_tui/src/main.rs @@ -17,6 +17,39 @@ use tui::Terminal; use training_mod_consts::*; +fn test_backend_setup(ui_menu: UiMenu) -> Result< + (Terminal, training_mod_tui::App), + Box> { + let app = training_mod_tui::App::new(ui_menu); + let backend = tui::backend::TestBackend::new(75, 15); + let terminal = Terminal::new(backend)?; + let mut state = tui::widgets::ListState::default(); + state.select(Some(1)); + + Ok((terminal, app)) +} + +#[test] +fn ensure_menu_retains_multi_selections() -> Result<(), Box> { + let menu; + unsafe { + menu = get_menu(); + println!("MENU.miss_tech_state: {}", MENU.miss_tech_state); + } + + let (mut terminal, mut app) = test_backend_setup(menu)?; + let mut url = String::new(); + let _frame_res = terminal.draw(|f| url = training_mod_tui::ui(f, &mut app))?; + + unsafe { + // At this point, we didn't change the menu at all; we should still see all missed tech flags. + assert_eq!(get_menu_from_url(MENU, url.as_str(), false).miss_tech_state, + MissTechFlags::all()); + } + + Ok(()) +} + fn main() -> Result<(), Box> { let menu; unsafe { @@ -24,11 +57,7 @@ fn main() -> Result<(), Box> { } #[cfg(not(feature = "has_terminal"))] { - let mut app = training_mod_tui::App::new(menu); - let backend = tui::backend::TestBackend::new(75, 15); - let mut terminal = Terminal::new(backend)?; - let mut state = tui::widgets::ListState::default(); - state.select(Some(1)); + let (mut terminal, mut app) = test_backend_setup(menu)?; let mut url = String::new(); let frame_res = terminal.draw(|f| url = training_mod_tui::ui(f, &mut app))?;