1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-20 00:46:34 +00:00

Format Rust code using rustfmt

This commit is contained in:
github-actions[bot] 2023-01-27 19:24:09 +00:00 committed by GitHub
parent 77f439a6eb
commit 37360c787a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 87 additions and 77 deletions

View file

@ -61,7 +61,8 @@ struct TopLevelBtnComboConfig {
} }
pub fn validate_config(data: &str) -> bool { pub fn validate_config(data: &str) -> bool {
let conf: TopLevelBtnComboConfig = toml::from_str(data).expect("Custom button config has invalid schema"); let conf: TopLevelBtnComboConfig =
toml::from_str(data).expect("Custom button config has invalid schema");
let conf = conf.button_config; let conf = conf.button_config;
let configs = [conf.open_menu, conf.save_state, conf.load_state]; let configs = [conf.open_menu, conf.save_state, conf.load_state];
let bad_keys = configs let bad_keys = configs

View file

@ -1,7 +1,7 @@
use crate::common::*; use crate::common::*;
use crate::events::{Event, EVENT_QUEUE}; use crate::events::{Event, EVENT_QUEUE};
use crate::training::frame_counter;
use crate::logging::*; use crate::logging::*;
use crate::training::frame_counter;
use ramhorns::Template; use ramhorns::Template;
use skyline::info::get_program_id; use skyline::info::get_program_id;
@ -347,10 +347,7 @@ static mut WEB_MENU_ACTIVE: bool = false;
unsafe fn spawn_web_session(session: WebSession) { unsafe fn spawn_web_session(session: WebSession) {
info!("Opening menu session..."); info!("Opening menu session...");
let loaded_msg = session.recv(); let loaded_msg = session.recv();
info!( info!("Received loaded message from web: {}", &loaded_msg);
"Received loaded message from web: {}",
&loaded_msg
);
let message_send = MenuJsonStruct { let message_send = MenuJsonStruct {
menu: MENU, menu: MENU,
defaults_menu: DEFAULTS_MENU, defaults_menu: DEFAULTS_MENU,

View file

@ -1,64 +1,67 @@
use skyline_web::DialogOk; use crate::logging::*;
use std::fs; use skyline_web::DialogOk;
use crate::logging::*; use std::fs;
pub const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION");
const VERSION_FILE_PATH: &str = "sd:/TrainingModpack/version.txt"; const VERSION_FILE_PATH: &str = "sd:/TrainingModpack/version.txt";
enum VersionCheck { enum VersionCheck {
Current, Current,
NoFile, NoFile,
Update, Update,
} }
fn is_current_version(fpath: &str) -> VersionCheck { fn is_current_version(fpath: &str) -> VersionCheck {
// Create a blank version file if it doesn't exists // Create a blank version file if it doesn't exists
if fs::metadata(fpath).is_err() { if fs::metadata(fpath).is_err() {
fs::File::create(fpath).expect("Could not create version file!"); fs::File::create(fpath).expect("Could not create version file!");
return VersionCheck::NoFile; return VersionCheck::NoFile;
} }
if fs::read_to_string(fpath).unwrap_or("".to_string()) == CURRENT_VERSION { if fs::read_to_string(fpath).unwrap_or("".to_string()) == CURRENT_VERSION {
VersionCheck::Current VersionCheck::Current
} else { } else {
VersionCheck::Update VersionCheck::Update
} }
} }
fn record_current_version(fpath: &str) { fn record_current_version(fpath: &str) {
// Write the current version to the version file // Write the current version to the version file
fs::write(fpath, CURRENT_VERSION).expect("Could not record current version!") fs::write(fpath, CURRENT_VERSION).expect("Could not record current version!")
} }
pub fn version_check() { pub fn version_check() {
match is_current_version(VERSION_FILE_PATH) { match is_current_version(VERSION_FILE_PATH) {
VersionCheck::Current => { VersionCheck::Current => {
// Version is current, no need to take any action // Version is current, no need to take any action
} }
VersionCheck::Update => { VersionCheck::Update => {
// Display dialog box on launch if changing versions // Display dialog box on launch if changing versions
DialogOk::ok( DialogOk::ok(
format!( format!(
"Thank you for installing version {CURRENT_VERSION} of the Training Modpack.\n\n\ "Thank you for installing version {CURRENT_VERSION} of the Training Modpack.\n\n\
Due to a breaking change in this version, your menu selections and defaults must be reset once.\n\n\ Due to a breaking change in this version, your menu selections and defaults must be reset once.\n\n\
Please refer to the Github page and the Discord server for a full list of recent features, bugfixes, and other changes." Please refer to the Github page and the Discord server for a full list of recent features, bugfixes, and other changes."
) )
); );
// Remove old menu selections, silently ignoring errors (i.e. if the file doesn't exist) // Remove old menu selections, silently ignoring errors (i.e. if the file doesn't exist)
fs::remove_file("sd:/TrainingModpack/training_modpack_menu.conf").unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu.conf")); fs::remove_file("sd:/TrainingModpack/training_modpack_menu.conf")
fs::remove_file("sd:/TrainingModpack/training_modpack_menu.json").unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu.json")); .unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu.conf"));
fs::remove_file("sd:/TrainingModpack/training_modpack_menu_defaults.conf").unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu_defaults.conf")); fs::remove_file("sd:/TrainingModpack/training_modpack_menu.json")
record_current_version(VERSION_FILE_PATH); .unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu.json"));
} fs::remove_file("sd:/TrainingModpack/training_modpack_menu_defaults.conf")
VersionCheck::NoFile => { .unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu_defaults.conf"));
// Display dialog box on fresh installation record_current_version(VERSION_FILE_PATH);
DialogOk::ok( }
format!( VersionCheck::NoFile => {
"Thank you for installing version {CURRENT_VERSION} of the Training Modpack.\n\n\ // Display dialog box on fresh installation
Please refer to the Github page and the Discord server for a full list of features and instructions on how to utilize the improved Training Mode." DialogOk::ok(
) format!(
); "Thank you for installing version {CURRENT_VERSION} of the Training Modpack.\n\n\
record_current_version(VERSION_FILE_PATH); Please refer to the Github page and the Discord server for a full list of features and instructions on how to utilize the improved Training Mode."
} )
} );
} record_current_version(VERSION_FILE_PATH);
}
}
}

View file

@ -21,9 +21,9 @@ mod hazard_manager;
mod hitbox_visualizer; mod hitbox_visualizer;
mod training; mod training;
mod logging;
#[cfg(test)] #[cfg(test)]
mod test; mod test;
mod logging;
use crate::common::*; use crate::common::*;
use crate::events::{Event, EVENT_QUEUE}; use crate::events::{Event, EVENT_QUEUE};
@ -32,11 +32,11 @@ use skyline::libc::mkdir;
use skyline::nro::{self, NroInfo}; use skyline::nro::{self, NroInfo};
use std::fs; use std::fs;
use crate::logging::*;
use crate::menu::quick_menu_loop; use crate::menu::quick_menu_loop;
#[cfg(feature = "web_session_preload")] #[cfg(feature = "web_session_preload")]
use crate::menu::web_session_loop; use crate::menu::web_session_loop;
use training_mod_consts::{MenuJsonStruct, OnOff}; use training_mod_consts::{MenuJsonStruct, OnOff};
use crate::logging::*;
fn nro_main(nro: &NroInfo<'_>) { fn nro_main(nro: &NroInfo<'_>) {
if nro.module.isLoaded { if nro.module.isLoaded {
@ -108,7 +108,8 @@ pub fn main() {
let menu_conf_path = "sd:/TrainingModpack/training_modpack_menu.json"; let menu_conf_path = "sd:/TrainingModpack/training_modpack_menu.json";
info!("Checking for previous menu in training_modpack_menu.json..."); info!("Checking for previous menu in training_modpack_menu.json...");
if fs::metadata(menu_conf_path).is_ok() { if fs::metadata(menu_conf_path).is_ok() {
let menu_conf = fs::read_to_string(menu_conf_path).expect(&format!("Could not remove {}", menu_conf_path)); let menu_conf = fs::read_to_string(menu_conf_path)
.expect(&format!("Could not remove {}", menu_conf_path));
if let Ok(menu_conf_json) = serde_json::from_str::<MenuJsonStruct>(&menu_conf) { if let Ok(menu_conf_json) = serde_json::from_str::<MenuJsonStruct>(&menu_conf) {
unsafe { unsafe {
MENU = menu_conf_json.menu; MENU = menu_conf_json.menu;
@ -117,7 +118,10 @@ pub fn main() {
} }
} else { } else {
warn!("Previous menu found but is invalid. Deleting..."); warn!("Previous menu found but is invalid. Deleting...");
fs::remove_file(menu_conf_path).expect(&format!("{} has invalid schema but could not be deleted!", menu_conf_path)); fs::remove_file(menu_conf_path).expect(&format!(
"{} has invalid schema but could not be deleted!",
menu_conf_path
));
} }
} else { } else {
info!("No previous menu file found."); info!("No previous menu file found.");
@ -127,7 +131,8 @@ pub fn main() {
info!("Checking for previous button combo settings in training_modpack.toml..."); info!("Checking for previous button combo settings in training_modpack.toml...");
if fs::metadata(combo_path).is_ok() { if fs::metadata(combo_path).is_ok() {
info!("Previous button combo settings found. Loading..."); info!("Previous button combo settings found. Loading...");
let combo_conf = fs::read_to_string(combo_path).expect(&format!("Could not read {}", combo_path)); let combo_conf =
fs::read_to_string(combo_path).expect(&format!("Could not read {}", combo_path));
if button_config::validate_config(&combo_conf) { if button_config::validate_config(&combo_conf) {
button_config::save_all_btn_config_from_toml(&combo_conf); button_config::save_all_btn_config_from_toml(&combo_conf);
} else { } else {
@ -159,7 +164,11 @@ pub fn main() {
); );
let url = format!("{host}{path}"); let url = format!("{host}{path}");
minreq::post(url).with_json(&event).expect("Failed to send info to firebase").send().ok(); minreq::post(url)
.with_json(&event)
.expect("Failed to send info to firebase")
.send()
.ok();
} }
} }
}); });

View file

@ -2,8 +2,8 @@ use crate::common::{
is_training_mode, menu, FIGHTER_MANAGER_ADDR, ITEM_MANAGER_ADDR, STAGE_MANAGER_ADDR, is_training_mode, menu, FIGHTER_MANAGER_ADDR, ITEM_MANAGER_ADDR, STAGE_MANAGER_ADDR,
}; };
use crate::hitbox_visualizer; use crate::hitbox_visualizer;
use crate::training::character_specific::items;
use crate::logging::*; use crate::logging::*;
use crate::training::character_specific::items;
use skyline::hooks::{getRegionAddress, InlineCtx, Region}; use skyline::hooks::{getRegionAddress, InlineCtx, Region};
use skyline::nn::hid::*; use skyline::nn::hid::*;
use skyline::nn::ro::LookupSymbol; use skyline::nn::ro::LookupSymbol;