From ca721bd933c990d57ff185276817556b2e8ca043 Mon Sep 17 00:00:00 2001 From: jugeeya Date: Wed, 13 Dec 2023 17:53:42 -0800 Subject: [PATCH] Debug Display --- src/static/layout.arc | Bin 4204916 -> 4204916 bytes src/training/input_log.rs | 12 ++-- src/training/ui/input_log.rs | 89 +++++++++++++++++++++++++++-- src/training/ui/mod.rs | 2 +- training_mod_consts/src/options.rs | 1 + 5 files changed, 92 insertions(+), 12 deletions(-) diff --git a/src/static/layout.arc b/src/static/layout.arc index da059da6af7cb79273b42fd569b6164d31ca4579..221e79bd330960035261ea8d2e0b299d9fa23880 100644 GIT binary patch delta 1219 zcmYk&U2KzO7zW_y`PS~YTf445Uu!4b*3B}?U^1c3A_S)pV&Y;9AwaV7V;nkgL0CK> z^vTdiLL{jc_AR;t5{LmZ4W!0#K(Y~LVswN?hwjXskN}yx!;lG4#a@>pgiJ zk7pVZz33(<)-#=$e300QZnFIv)AxOUwe3MS`7k#A(mkI%fNpZ{7N!fo-Dw{}?+v1S zx|QkV+`W!r44C}rjp8v&cb8{=C0fVM!9@-ioAx=b+*p)o7ZDw0q9sULL~p??P#IAQ z#$gUzE}{XLg^Zi%Jb229((o`k*>xVfgHSb8^ZyL;Z=bL1VT>6jHOoEolqQb)4Lv3C)w*V%L>X4raKxA_2AP{=}(yY?|0{! zE4-qrj2_d|8~?w{`(#&?qO^l7ayy;O1BLx3yv|_AN>6xvW!o#A{29wPkxBFAS5;WW zQYlk$skl|jRVq{}RjO2~Rccf`Dzz$gDqayGPgjH;nh)PuD8I_ny zqsp@?%T(ejO)AYQEh-6>R+ToD=Twp^%T?M{R;Z*@R;qNUtWsI6(y8*i${Lj}l^0aj bs;pBjvO*$4trHcv)5vgECGsr*_|7ao2N7k2! zfrMm~i=c=U17jkC1YHuMufeF`W1L=n?~2!oQ(OQ z7DrfjWU?sQIN9S|K>wf7ouKv~8vy3Q}N6usX3mWkz+&THA&Wbbw+_NsJt$!xkv+OTvsu`QuCxCPHvM(GcmUn+M7i0ZXk_Di*=-Eyymc;o z%OI_Bg=<8WYNBgLrH6CcCyXI~CecMA>cel1fZITH7FJ*nJTXMiVHKj#Zp0i^#S%?| zF^oF<$u>=Mop&J^A!yk9s=_<(S>uv<7sI9E7N*du&UIA6FxxKOxAxLCME vxK#L%aG7wquvfT3xKjAAaFy^8;cDTd!am_+!ZpIR!hYd8;p1=lMBmguz(DL* diff --git a/src/training/input_log.rs b/src/training/input_log.rs index b47c281..fd56294 100644 --- a/src/training/input_log.rs +++ b/src/training/input_log.rs @@ -137,7 +137,7 @@ impl InputLog { unsafe { match MENU.input_display { InputDisplay::SMASH => self.is_smash_different(other), - InputDisplay::RAW => self.is_raw_different(other), + InputDisplay::RAW | InputDisplay::DEBUG => self.is_raw_different(other), InputDisplay::STATUS => self.is_status_different(other), InputDisplay::NONE => false, _ => panic!("Invalid value in is_different: {}", MENU.input_display), @@ -149,7 +149,7 @@ impl InputLog { unsafe { match MENU.input_display { InputDisplay::SMASH => self.smash_binned_lstick(), - InputDisplay::RAW => self.raw_binned_lstick(), + InputDisplay::RAW | InputDisplay::DEBUG => self.raw_binned_lstick(), InputDisplay::STATUS => (DirectionStrength::None, 0.0), InputDisplay::NONE => panic!("Invalid input display to log"), _ => panic!("Invalid value in binned_lstick: {}", MENU.input_display), @@ -161,7 +161,7 @@ impl InputLog { unsafe { match MENU.input_display { InputDisplay::SMASH => self.smash_binned_rstick(), - InputDisplay::RAW => self.raw_binned_rstick(), + InputDisplay::RAW | InputDisplay::DEBUG => self.raw_binned_rstick(), InputDisplay::STATUS => (DirectionStrength::None, 0.0), InputDisplay::NONE => panic!("Invalid input display to log"), _ => panic!("Invalid value in binned_rstick: {}", MENU.input_display), @@ -173,7 +173,7 @@ impl InputLog { unsafe { match MENU.input_display { InputDisplay::SMASH => self.smash_button_icons(), - InputDisplay::RAW => self.raw_button_icons(), + InputDisplay::RAW | InputDisplay::DEBUG => self.raw_button_icons(), InputDisplay::STATUS => VecDeque::new(), InputDisplay::NONE => panic!("Invalid input display to log"), _ => unreachable!(), @@ -181,7 +181,7 @@ impl InputLog { } } - fn smash_button_icons(&self) -> VecDeque<(&str, ResColor)> { + pub fn smash_button_icons(&self) -> VecDeque<(&str, ResColor)> { self.smash_inputs .buttons .to_vec() @@ -205,7 +205,7 @@ impl InputLog { .collect::>() } - fn raw_button_icons(&self) -> VecDeque<(&str, ResColor)> { + pub fn raw_button_icons(&self) -> VecDeque<(&str, ResColor)> { let buttons = self.raw_inputs.current_buttons; let mut icons = VecDeque::new(); if buttons.a() { diff --git a/src/training/ui/input_log.rs b/src/training/ui/input_log.rs index 49e8cac..736ac7f 100644 --- a/src/training/ui/input_log.rs +++ b/src/training/ui/input_log.rs @@ -1,11 +1,14 @@ +use itertools::Itertools; use std::collections::VecDeque; use skyline::nn::ui2d::*; +use smash::app::{lua_bind::*, utility}; +use smash::lib::lua_const::*; use smash::ui2d::{SmashPane, SmashTextBox}; -use training_mod_consts::{InputDisplay, MENU}; +use training_mod_consts::{FighterId, InputDisplay, MENU}; use crate::{ - common::{consts::status_display_name, menu::QUICK_MENU_ACTIVE}, + common::{consts::status_display_name, menu::QUICK_MENU_ACTIVE, try_get_module_accessor}, training::{ input_log::{ DirectionStrength, InputLog, DRAW_LOG_BASE_IDX, NUM_LOGS, P1_INPUT_LOGS, WHITE, YELLOW, @@ -193,7 +196,15 @@ pub unsafe fn draw(root_pane: &Pane) { .find_pane_by_name_recursive("TrModInputLog") .unwrap(); logs_pane.set_visible( - !QUICK_MENU_ACTIVE && !VANILLA_MENU_ACTIVE && MENU.input_display != InputDisplay::NONE, + !QUICK_MENU_ACTIVE + && !VANILLA_MENU_ACTIVE + && (MENU.input_display != InputDisplay::NONE + && MENU.input_display != InputDisplay::DEBUG), + ); + + let debug_pane = root_pane.find_pane_by_name_recursive("TrModDebug").unwrap(); + debug_pane.set_visible( + !QUICK_MENU_ACTIVE && !VANILLA_MENU_ACTIVE && MENU.input_display == InputDisplay::DEBUG, ); if MENU.input_display == InputDisplay::NONE { return; @@ -205,7 +216,75 @@ pub unsafe fn draw(root_pane: &Pane) { } let logs = &*logs_ptr; - for (log_idx, log) in logs.iter().enumerate() { - draw_log(root_pane, log_idx, log); + if MENU.input_display == InputDisplay::DEBUG { + let module_accessor = try_get_module_accessor(FighterId::Player); + if module_accessor.is_none() { + return; + } + let module_accessor = module_accessor.unwrap(); + + let fighter_kind = utility::get_kind(&mut *module_accessor); + let status = StatusModule::status_kind(module_accessor); + + let status_line = format!( + "Status: {status}", + status = status_display_name(fighter_kind, status) + ); + + let pos_x = PostureModule::pos_x(module_accessor); + let pos_y = PostureModule::pos_y(module_accessor); + let lr = PostureModule::lr(module_accessor); + + let position_line = format!("Position: ({pos_x:.2}, {pos_y:.2}); LR: {lr}"); + + let x_vel = + KineticModule::get_sum_speed_x(module_accessor, *KINETIC_ENERGY_RESERVE_ATTRIBUTE_MAIN); + let y_vel = + KineticModule::get_sum_speed_y(module_accessor, *KINETIC_ENERGY_RESERVE_ATTRIBUTE_MAIN); + + let speed_line = format!("Speed: ({x_vel:.2}, {y_vel:.2})"); + + let first_log = logs.first().unwrap(); + let raw_left_stick_x = first_log.raw_inputs.left_stick_x; + let raw_left_stick_y = first_log.raw_inputs.left_stick_y; + let raw_buttons = first_log.raw_button_icons(); + + let smash_left_stick_x = first_log.smash_inputs.lstick_x; + let smash_left_stick_y = first_log.smash_inputs.lstick_y; + let smash_buttons = first_log.smash_button_icons(); + + let raw_line = format!( + "Raw | Left Stick: ({left_x:.5}, {left_y:.5})\nButtons: {buttons}", + left_x = raw_left_stick_x, + left_y = raw_left_stick_y, + buttons = raw_buttons + .iter() + .sorted_by(|a, b| Ord::cmp(&b.0, &a.0)) + .map(|(name, _color)| name) + .join("|") + ); + + let smash_line = format!( + "Smash | Left Stick: ({left_x}, {left_y})\nButtons: {buttons}", + left_x = smash_left_stick_x, + left_y = smash_left_stick_y, + buttons = smash_buttons + .iter() + .sorted_by(|a, b| Ord::cmp(&b.0, &a.0)) + .map(|(name, _color)| name) + .join("|") + ); + + debug_pane + .find_pane_by_name_recursive("DebugTxt") + .unwrap() + .as_textbox() + .set_text_string(&format!( + "{status_line}\n{position_line}\n{speed_line}\n{raw_line}\n{smash_line}" + )); + } else { + for (log_idx, log) in logs.iter().enumerate() { + draw_log(root_pane, log_idx, log); + } } } diff --git a/src/training/ui/mod.rs b/src/training/ui/mod.rs index 2a6290f..9563c91 100644 --- a/src/training/ui/mod.rs +++ b/src/training/ui/mod.rs @@ -90,7 +90,7 @@ pub unsafe fn handle_draw(layout: *mut Layout, draw_info: u64, cmd_buffer: u64) // in order for us to be able to swap the 'layout.arc' with the current // version of the file in between loads of training mode. #[cfg(feature = "layout_arc_from_file")] -const LAYOUT_ARC_SIZE: usize = (4 * MEBIBYTE) as usize; +const LAYOUT_ARC_SIZE: usize = (5 * MEBIBYTE) as usize; #[cfg(feature = "layout_arc_from_file")] static mut LAYOUT_ARC: &mut [u8; LAYOUT_ARC_SIZE] = &mut [0u8; LAYOUT_ARC_SIZE]; diff --git a/training_mod_consts/src/options.rs b/training_mod_consts/src/options.rs index 1698991..59fa143 100644 --- a/training_mod_consts/src/options.rs +++ b/training_mod_consts/src/options.rs @@ -1042,5 +1042,6 @@ byteflags! { pub SMASH = "Smash Inputs", pub RAW = "Raw Inputs", pub STATUS = "Status Only", + pub DEBUG = "Debug", } }