1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-24 02:44:17 +00:00

[Build] Clippy Fixes (#554)

* Add slots as menu options, randomize playback slots

* Clippy Fixes
This commit is contained in:
jugeeya 2023-08-02 11:09:02 -07:00 committed by GitHub
parent 3a40d46fca
commit 822db3969f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 50 additions and 44 deletions

View file

@ -40,10 +40,13 @@ pub struct Uuid {
impl Uuid {
pub fn to_str(&self) -> String {
use std::fmt::Write;
self.data
.iter()
.map(|i| format!("{i:02x}"))
.collect::<String>()
.fold(String::new(), |mut output, b| {
let _ = write!(output, "{b:02x}");
output
})
}
}

View file

@ -31,7 +31,7 @@ pub fn is_training_mode() -> bool {
true
}
pub fn get_category(module_accessor: &mut app::BattleObjectModuleAccessor) -> i32 {
pub fn get_category(module_accessor: &app::BattleObjectModuleAccessor) -> i32 {
(module_accessor.info >> 28) as u8 as i32
}
@ -51,7 +51,7 @@ pub fn get_module_accessor(fighter_id: FighterId) -> *mut app::BattleObjectModul
}
}
pub fn is_fighter(module_accessor: &mut app::BattleObjectModuleAccessor) -> bool {
pub fn is_fighter(module_accessor: &app::BattleObjectModuleAccessor) -> bool {
get_category(module_accessor) == BATTLE_OBJECT_CATEGORY_FIGHTER
}

View file

@ -63,7 +63,7 @@ fn update_frame_advantage(new_frame_adv: i32) {
b: 8,
a: 255,
},
x if x == 0 => ResColor {
0 => ResColor {
r: 0,
g: 0,
b: 0,

View file

@ -45,7 +45,7 @@ pub unsafe fn handle_correct_damage_vector_common(
original!()(fighter, arg1)
}
unsafe fn mod_handle_di(fighter: &mut L2CFighterCommon, _arg1: L2CValue) {
unsafe fn mod_handle_di(fighter: &L2CFighterCommon, _arg1: L2CValue) {
if MENU.di_state == Direction::empty() {
return;
}

View file

@ -2,6 +2,7 @@ use smash::app::{BattleObjectModuleAccessor, lua_bind::*, utility};
use smash::lib::lua_const::*;
use lazy_static::lazy_static;
use parking_lot::Mutex;
use std::cmp::Ordering;
use crate::training::input_recording::structures::*;
use crate::common::consts::{RecordTrigger, HitstunPlayback, FighterId};
use crate::common::{MENU, get_module_accessor, is_in_hitstun, is_in_shieldstun};
@ -164,6 +165,9 @@ fn into_transition_term(starting_status: StartingStatus) -> i32 {
}
pub unsafe fn get_command_flag_cat(module_accessor: &mut BattleObjectModuleAccessor) {
// Allow this because sometimes we want to make sure our NNSDK doesn't have
// an erroneous definition
#[allow(clippy::unnecessary_cast)]
let entry_id_int =
WorkModule::get_int(module_accessor, *FIGHTER_INSTANCE_WORK_ID_INT_ENTRY_ID) as i32;
let fighter_kind = utility::get_kind(module_accessor);
@ -191,14 +195,12 @@ pub unsafe fn get_command_flag_cat(module_accessor: &mut BattleObjectModuleAcces
// may need to move this to another func
if INPUT_RECORD == Record || INPUT_RECORD == Playback {
if INPUT_RECORD_FRAME >= FINAL_RECORD_FRAME - 1 {
INPUT_RECORD = None;
POSSESSION = Player;
INPUT_RECORD_FRAME = 0;
if mash::is_playback_queued() {
mash::reset();
}
if (INPUT_RECORD == Record || INPUT_RECORD == Playback) && INPUT_RECORD_FRAME >= FINAL_RECORD_FRAME - 1 {
INPUT_RECORD = None;
POSSESSION = Player;
INPUT_RECORD_FRAME = 0;
if mash::is_playback_queued() {
mash::reset();
}
}
}
@ -288,7 +290,7 @@ pub unsafe fn is_end_standby() -> bool {
let clamped_rstick_x = ((first_frame_input.rstick_x as f32) * STICK_CLAMP_MULTIPLIER).clamp(-1.0, 1.0);
let clamped_rstick_y = ((first_frame_input.rstick_y as f32) * STICK_CLAMP_MULTIPLIER).clamp(-1.0, 1.0);
let buttons_pressed = first_frame_input.buttons != Buttons::NONE;
let buttons_pressed = first_frame_input.buttons.is_empty();
let lstick_movement = clamped_lstick_x.abs() >= STICK_NEUTRAL || clamped_lstick_y.abs() >= STICK_NEUTRAL;
let rstick_movement = clamped_rstick_x.abs() >= STICK_NEUTRAL || clamped_rstick_y.abs() >= STICK_NEUTRAL;
lstick_movement || rstick_movement || buttons_pressed
@ -305,7 +307,7 @@ unsafe fn handle_final_input_mapping(
arg: bool
) {
// go through the original mapping function first
let _ret = original!()(mappings, player_idx, out, controller_struct, arg);
original!()(mappings, player_idx, out, controller_struct, arg);
if player_idx == 0 { // if player 1
if INPUT_RECORD == Record {
// check for standby before starting action:
@ -345,13 +347,13 @@ unsafe fn set_cpu_controls(p_data: *mut *mut u8) {
}
if INPUT_RECORD == Pause {
if LOCKOUT_FRAME > 0 {
LOCKOUT_FRAME -= 1;
} else if LOCKOUT_FRAME == 0 {
INPUT_RECORD = Record;
POSSESSION = Standby;
} else {
println!("LOCKOUT_FRAME OUT OF BOUNDS");
match LOCKOUT_FRAME.cmp(&0) {
Ordering::Greater => LOCKOUT_FRAME -= 1,
Ordering::Equal => {
INPUT_RECORD = Record;
POSSESSION = Standby;
},
Ordering::Less => println!("LOCKOUT_FRAME OUT OF BOUNDS")
}
}

View file

@ -36,7 +36,7 @@ impl ControlModuleInternal {
pub fn _clear(&mut self) { // Try to nullify controls so we can't control player 1 during recording
self.stick_x = 0.0;
self.stick_y = 0.0;
self.buttons = Buttons::NONE;
self.buttons = Buttons::empty();
self.clamped_lstick_x = 0.0;
self.clamped_lstick_y = 0.0;
self.clamped_rstick_x = 0.0;
@ -162,7 +162,6 @@ pub struct ControllerMapping {
//type Buttons = u32; // may need to actually implement (like label and such)? Not for now though
bitflags! {
pub struct Buttons: u32 {
const NONE = 0x0; // does adding this cause problems?
const ATTACK = 0x1;
const SPECIAL = 0x2;
const JUMP = 0x4;
@ -251,7 +250,7 @@ pub struct MappedInputs {
impl MappedInputs { // pub needed?
pub fn default() -> MappedInputs {
MappedInputs {
buttons: Buttons::NONE,
buttons: Buttons::empty(),
lstick_x: 0,
lstick_y: 0,
rstick_x: 0,

View file

@ -89,7 +89,7 @@ fn get_ledge_option() -> Option<Action> {
override_action = None;
}
}
return override_action.or(regular_action);
override_action.or(regular_action)
}
}
@ -110,6 +110,9 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor
let flag_cliff =
WorkModule::is_flag(module_accessor, *FIGHTER_INSTANCE_WORK_ID_FLAG_CATCH_CLIFF);
let current_frame = MotionModule::frame(module_accessor) as i32;
// Allow this because sometimes we want to make sure our NNSDK doesn't have
// an erroneous definition
#[allow(clippy::unnecessary_cast)]
let status_kind = StatusModule::status_kind(module_accessor) as i32;
let should_buffer_playback = (LEDGE_DELAY == 0) && (current_frame == 13); // 18 - 5 of buffer
let should_buffer;
@ -159,9 +162,8 @@ pub unsafe fn force_option(module_accessor: &mut app::BattleObjectModuleAccessor
StatusModule::change_status_request_from_script(module_accessor, status, true);
}
let ledge_option: Option<Action> = get_ledge_option();
if ledge_option.is_some() {
mash::external_buffer_menu_mash(ledge_option.unwrap());
if let Some(ledge_option) = get_ledge_option() {
mash::external_buffer_menu_mash(ledge_option);
}
}
@ -198,8 +200,10 @@ pub fn get_command_flag_cat(module_accessor: &mut app::BattleObjectModuleAccesso
unsafe {
let current_frame = MotionModule::frame(module_accessor) as i32;
// Frame 18 is right before actionability for cliff catch
#[allow(clippy::unnecessary_cast)]
let just_grabbed_ledge = (StatusModule::status_kind(module_accessor) as i32 == *FIGHTER_STATUS_KIND_CLIFF_CATCH) && current_frame == 18;
// Needs to be a frame earlier for lasso grabs
#[allow(clippy::unnecessary_cast)]
let just_lassoed_ledge = (StatusModule::status_kind(module_accessor) as i32 == *FIGHTER_STATUS_KIND_CLIFF_WAIT) && current_frame == 17;
// Begin recording on ledge if this is the recording trigger
if (just_grabbed_ledge || just_lassoed_ledge) && MENU.record_trigger == RecordTrigger::Ledge && !input_record::is_standby() {

View file

@ -377,7 +377,7 @@ unsafe fn perform_action(module_accessor: &mut app::BattleObjectModuleAccessor)
}
Action::PLAYBACK => {
// Because these status changes take place after we would receive input from the controller, we need to queue input playback 1 frame before we can act
return 0; // We don't ever want to explicitly provide any command flags here; if we're trying to do input recording, the playback handles it all
0 // We don't ever want to explicitly provide any command flags here; if we're trying to do input recording, the playback handles it all
}
_ => get_attack_flag(module_accessor, action),
}

View file

@ -40,7 +40,7 @@ pub unsafe fn handle_change_status(
}
unsafe fn mod_handle_change_status(
fighter: &mut L2CFighterBase,
fighter: &L2CFighterBase,
status_kind: &mut L2CValue,
unk: &mut L2CValue,
) {

View file

@ -69,7 +69,7 @@ pub unsafe fn parse_anim_transform(anim_transform: &mut AnimTransform, layout_na
}
}
pub unsafe fn draw(root_pane: &mut Pane, layout_name: &str) {
pub unsafe fn draw(root_pane: &Pane, layout_name: &str) {
// Update percentage display as soon as possible on death
if is_training_mode() && is_ready_go() && layout_name == "info_melee" {
for player_name in &["p1", "p2"] {

View file

@ -21,7 +21,7 @@ macro_rules! display_txt_fmt {
};
}
pub unsafe fn draw(root_pane: &mut Pane) {
pub unsafe fn draw(root_pane: &Pane) {
let notification_idx = 0;
let queue = &mut ui::notifications::QUEUE;

View file

@ -71,7 +71,7 @@ lazy_static! {
]);
}
unsafe fn render_submenu_page(app: &App, root_pane: &mut Pane) {
unsafe fn render_submenu_page(app: &App, root_pane: &Pane) {
let tab_selected = app.tab_selected();
let tab = app.menu_items.get(tab_selected).unwrap();
let submenu_ids = app.submenu_ids();
@ -113,9 +113,8 @@ unsafe fn render_submenu_page(app: &App, root_pane: &mut Pane) {
// corresponds with a particular button to be visible.
submenu_ids.iter().for_each(|id| {
let pane = menu_button.find_pane_by_name_recursive(id);
match pane {
Some(p) => p.set_visible(id == &submenu.submenu_id),
None => (),
if let Some(p) = pane {
p.set_visible(id == &submenu.submenu_id);
}
});
@ -156,7 +155,7 @@ unsafe fn render_submenu_page(app: &App, root_pane: &mut Pane) {
});
}
unsafe fn render_toggle_page(app: &App, root_pane: &mut Pane) {
unsafe fn render_toggle_page(app: &App, root_pane: &Pane) {
let (_title, _help_text, mut sub_menu_str_lists) = app.sub_menu_strs_and_states();
(0..sub_menu_str_lists.len()).for_each(|list_section| {
let sub_menu_str = sub_menu_str_lists[list_section].0.clone();
@ -194,9 +193,8 @@ unsafe fn render_toggle_page(app: &App, root_pane: &mut Pane) {
submenu_ids.iter().for_each(|id| {
let pane = menu_button.find_pane_by_name_recursive(id);
match pane {
Some(p) => p.set_visible(false),
None => (),
if let Some(p) = pane {
p.set_visible(false);
}
});
@ -234,7 +232,7 @@ unsafe fn render_toggle_page(app: &App, root_pane: &mut Pane) {
});
}
unsafe fn render_slider_page(app: &App, root_pane: &mut Pane) {
unsafe fn render_slider_page(app: &App, root_pane: &Pane) {
let (title, _help_text, gauge_vals) = app.sub_menu_strs_for_slider();
let selected_min = gauge_vals.selected_min;
let selected_max = gauge_vals.selected_max;
@ -347,7 +345,7 @@ unsafe fn render_slider_page(app: &App, root_pane: &mut Pane) {
});
}
pub unsafe fn draw(root_pane: &mut Pane) {
pub unsafe fn draw(root_pane: &Pane) {
// Update menu display
// Grabbing lock as read-only, essentially
let app = &*crate::common::menu::QUICK_MENU_APP.data_ptr();