Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug Display #658

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified src/static/layout.arc
Binary file not shown.
12 changes: 6 additions & 6 deletions src/training/input_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -173,15 +173,15 @@ 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!(),
}
}
}

fn smash_button_icons(&self) -> VecDeque<(&str, ResColor)> {
pub fn smash_button_icons(&self) -> VecDeque<(&str, ResColor)> {
self.smash_inputs
.buttons
.to_vec()
Expand All @@ -205,7 +205,7 @@ impl InputLog {
.collect::<VecDeque<(&str, ResColor)>>()
}

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() {
Expand Down
89 changes: 84 additions & 5 deletions src/training/ui/input_log.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/training/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
1 change: 1 addition & 0 deletions training_mod_consts/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,5 +1042,6 @@ byteflags! {
pub SMASH = "Smash Inputs",
pub RAW = "Raw Inputs",
pub STATUS = "Status Only",
pub DEBUG = "Debug",
}
}