1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-27 20:34:03 +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 {
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 configs = [conf.open_menu, conf.save_state, conf.load_state];
let bad_keys = configs

View file

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

View file

@ -1,64 +1,67 @@
use skyline_web::DialogOk;
use std::fs;
use crate::logging::*;
pub const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION");
const VERSION_FILE_PATH: &str = "sd:/TrainingModpack/version.txt";
enum VersionCheck {
Current,
NoFile,
Update,
}
fn is_current_version(fpath: &str) -> VersionCheck {
// Create a blank version file if it doesn't exists
if fs::metadata(fpath).is_err() {
fs::File::create(fpath).expect("Could not create version file!");
return VersionCheck::NoFile;
}
if fs::read_to_string(fpath).unwrap_or("".to_string()) == CURRENT_VERSION {
VersionCheck::Current
} else {
VersionCheck::Update
}
}
fn record_current_version(fpath: &str) {
// Write the current version to the version file
fs::write(fpath, CURRENT_VERSION).expect("Could not record current version!")
}
pub fn version_check() {
match is_current_version(VERSION_FILE_PATH) {
VersionCheck::Current => {
// Version is current, no need to take any action
}
VersionCheck::Update => {
// Display dialog box on launch if changing versions
DialogOk::ok(
format!(
"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\
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)
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.json").unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu.json"));
fs::remove_file("sd:/TrainingModpack/training_modpack_menu_defaults.conf").unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu_defaults.conf"));
record_current_version(VERSION_FILE_PATH);
}
VersionCheck::NoFile => {
// Display dialog box on fresh installation
DialogOk::ok(
format!(
"Thank you for installing version {CURRENT_VERSION} of the Training Modpack.\n\n\
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);
}
}
}
use crate::logging::*;
use skyline_web::DialogOk;
use std::fs;
pub const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION");
const VERSION_FILE_PATH: &str = "sd:/TrainingModpack/version.txt";
enum VersionCheck {
Current,
NoFile,
Update,
}
fn is_current_version(fpath: &str) -> VersionCheck {
// Create a blank version file if it doesn't exists
if fs::metadata(fpath).is_err() {
fs::File::create(fpath).expect("Could not create version file!");
return VersionCheck::NoFile;
}
if fs::read_to_string(fpath).unwrap_or("".to_string()) == CURRENT_VERSION {
VersionCheck::Current
} else {
VersionCheck::Update
}
}
fn record_current_version(fpath: &str) {
// Write the current version to the version file
fs::write(fpath, CURRENT_VERSION).expect("Could not record current version!")
}
pub fn version_check() {
match is_current_version(VERSION_FILE_PATH) {
VersionCheck::Current => {
// Version is current, no need to take any action
}
VersionCheck::Update => {
// Display dialog box on launch if changing versions
DialogOk::ok(
format!(
"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\
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)
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.json")
.unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu.json"));
fs::remove_file("sd:/TrainingModpack/training_modpack_menu_defaults.conf")
.unwrap_or_else(|_| error!("Couldn't remove training_modpack_menu_defaults.conf"));
record_current_version(VERSION_FILE_PATH);
}
VersionCheck::NoFile => {
// Display dialog box on fresh installation
DialogOk::ok(
format!(
"Thank you for installing version {CURRENT_VERSION} of the Training Modpack.\n\n\
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 training;
mod logging;
#[cfg(test)]
mod test;
mod logging;
use crate::common::*;
use crate::events::{Event, EVENT_QUEUE};
@ -32,11 +32,11 @@ use skyline::libc::mkdir;
use skyline::nro::{self, NroInfo};
use std::fs;
use crate::logging::*;
use crate::menu::quick_menu_loop;
#[cfg(feature = "web_session_preload")]
use crate::menu::web_session_loop;
use training_mod_consts::{MenuJsonStruct, OnOff};
use crate::logging::*;
fn nro_main(nro: &NroInfo<'_>) {
if nro.module.isLoaded {
@ -108,7 +108,8 @@ pub fn main() {
let menu_conf_path = "sd:/TrainingModpack/training_modpack_menu.json";
info!("Checking for previous menu in training_modpack_menu.json...");
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) {
unsafe {
MENU = menu_conf_json.menu;
@ -117,7 +118,10 @@ pub fn main() {
}
} else {
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 {
info!("No previous menu file found.");
@ -127,7 +131,8 @@ pub fn main() {
info!("Checking for previous button combo settings in training_modpack.toml...");
if fs::metadata(combo_path).is_ok() {
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) {
button_config::save_all_btn_config_from_toml(&combo_conf);
} else {
@ -159,7 +164,11 @@ pub fn main() {
);
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,
};
use crate::hitbox_visualizer;
use crate::training::character_specific::items;
use crate::logging::*;
use crate::training::character_specific::items;
use skyline::hooks::{getRegionAddress, InlineCtx, Region};
use skyline::nn::hid::*;
use skyline::nn::ro::LookupSymbol;