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

Make it more intuitive for devs to add new menu items (#709)

* Rework how we set up the menu so we only have to write the fn once

* Clippy warnings
This commit is contained in:
asimon-1 2024-11-20 19:26:51 -08:00 committed by GitHub
parent 858d35142e
commit cb6ca02f3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 595 additions and 742 deletions

View file

@ -139,13 +139,13 @@ fn get_release(beta: bool) -> Result<Release> {
break;
}
}
if beta && beta_release.is_some() {
Ok(beta_release.unwrap())
} else if !beta && stable_release.is_some() {
Ok(stable_release.unwrap())
if beta {
beta_release.ok_or(anyhow!(
"The specified beta release was not found in the GitHub JSON response!"
))
} else {
Err(anyhow!(
"The specified release was not found in the GitHub JSON response!"
stable_release.ok_or(anyhow!(
"The specified stable release was not found in the GitHub JSON response!"
))
}
}

View file

@ -580,8 +580,8 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor)
SaveDamage::RANDOM => {
// Gen random value
let pct: f32 = get_random_float(
read(&MENU).save_damage_limits_player.0 as f32,
read(&MENU).save_damage_limits_player.1 as f32,
read(&MENU).save_damage_limits_player.LOWER as f32,
read(&MENU).save_damage_limits_player.UPPER as f32,
);
set_damage(module_accessor, pct);
}
@ -599,8 +599,8 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor)
SaveDamage::RANDOM => {
// Gen random value
let pct: f32 = get_random_float(
read(&MENU).save_damage_limits_cpu.0 as f32,
read(&MENU).save_damage_limits_cpu.1 as f32,
read(&MENU).save_damage_limits_cpu.UPPER as f32,
read(&MENU).save_damage_limits_cpu.LOWER as f32,
);
set_damage(module_accessor, pct);
}

View file

@ -163,6 +163,7 @@ unsafe fn handle_layout_arc_malloc(ctx: &mut skyline::hooks::InlineCtx) {
.iter()
.enumerate()
.for_each(|(idx, byte)| LAYOUT_ARC[idx] = *byte);
#[allow(static_mut_refs)]
inject_arc = LAYOUT_ARC.as_ptr();
}

File diff suppressed because it is too large Load diff

View file

@ -1,68 +1,98 @@
use crate::TOGGLE_MAX;
use byteflags::*;
use core::f64::consts::PI;
use serde::{Deserialize, Serialize};
#[cfg(feature = "smash")]
use smash::lib::lua_const::*;
use training_mod_tui::{
StatefulSlider, StatefulTable, SubMenu, SubMenuType, Toggle, NX_SUBMENU_COLUMNS,
NX_SUBMENU_ROWS,
};
pub trait SubMenuTrait {
fn to_submenu<'a>(
title: &'a str,
id: &'a str,
help_text: &'a str,
submenu_type: SubMenuType,
) -> SubMenu<'a>;
}
#[macro_export]
macro_rules! impl_toggletrait {
(
$e:ty,
$title:literal,
$id:literal,
$help_text:literal,
$single:literal,
$max:expr,
) => {
paste! {
fn [<to_submenu_ $id>]<'a>() -> SubMenu<'a> {
let submenu_type = if $single { SubMenuType::ToggleSingle } else { SubMenuType::ToggleMultiple };
macro_rules! impl_submenutrait {
($e:ty) => {
impl SubMenuTrait for $e {
fn to_submenu<'a>(
title: &'a str,
id: &'a str,
help_text: &'a str,
submenu_type: SubMenuType,
) -> SubMenu<'a> {
match submenu_type {
SubMenuType::ToggleSingle => {
let value = 0;
let max: u8 = $max;
let toggles_vec: Vec<Toggle> = <$e>::ALL_NAMES
let max = 1;
let toggles_vec: Vec<Toggle> = Self::ALL_NAMES
.iter()
.map(|title| Toggle { title, value, max })
.collect();
SubMenu {
title: $title,
id: $id,
help_text: $help_text,
title: title,
id: id,
help_text: help_text,
submenu_type: submenu_type,
toggles: StatefulTable::with_items(NX_SUBMENU_ROWS, NX_SUBMENU_COLUMNS, toggles_vec),
slider: None
toggles: StatefulTable::with_items(
NX_SUBMENU_ROWS,
NX_SUBMENU_COLUMNS,
toggles_vec,
),
slider: None,
}
}
SubMenuType::ToggleMultiple => {
let value = 0;
let max = TOGGLE_MAX;
let toggles_vec: Vec<Toggle> = Self::ALL_NAMES
.iter()
.map(|title| Toggle { title, value, max })
.collect();
SubMenu {
title: title,
id: id,
help_text: help_text,
submenu_type: submenu_type,
toggles: StatefulTable::with_items(
NX_SUBMENU_ROWS,
NX_SUBMENU_COLUMNS,
toggles_vec,
),
slider: None,
}
}
}
#[macro_export]
macro_rules! impl_slidertrait {
(
$e:ty,
$title:literal,
$id:literal,
$help_text:literal,
) => {
paste! {
fn [<to_submenu_ $id>]<'a>() -> SubMenu<'a> {
SubMenuType::Slider => {
let slider = StatefulSlider {
lower: 0,
upper: 150,
..StatefulSlider::new()
};
SubMenu {
title: $title,
id: $id,
help_text: $help_text,
submenu_type: SubMenuType::Slider,
toggles: StatefulTable::with_items(NX_SUBMENU_ROWS, NX_SUBMENU_COLUMNS, Vec::new()),
slider: Some(slider)
title: title,
id: id,
help_text: help_text,
submenu_type: submenu_type,
toggles: StatefulTable::with_items(
NX_SUBMENU_ROWS,
NX_SUBMENU_COLUMNS,
Vec::new(),
),
slider: Some(slider),
}
}
}
}
}
};
}
pub fn get_random_int(_max: i32) -> i32 {
#[cfg(feature = "smash")]
@ -113,6 +143,8 @@ byteflags! {
}
}
impl_submenutrait!(Direction);
impl Direction {
pub fn into_angle(self) -> Option<f64> {
let index = self.into_index();
@ -161,6 +193,8 @@ byteflags! {
}
}
impl_submenutrait!(LedgeOption);
impl LedgeOption {
pub fn into_status(self) -> Option<i32> {
#[cfg(feature = "smash")]
@ -228,6 +262,8 @@ byteflags! {
}
}
impl_submenutrait!(TechFlags);
// Missed Tech Options
byteflags! {
pub struct MissTechFlags {
@ -238,6 +274,8 @@ byteflags! {
}
}
impl_submenutrait!(MissTechFlags);
byteflags! {
pub struct Shield {
pub NONE = "None",
@ -247,6 +285,8 @@ byteflags! {
}
}
impl_submenutrait!(Shield);
byteflags! {
pub struct SaveStateMirroring {
pub NONE = "None",
@ -255,6 +295,8 @@ byteflags! {
}
}
impl_submenutrait!(SaveStateMirroring);
byteflags! {
pub struct OnOff {
pub ON = "On",
@ -262,6 +304,8 @@ byteflags! {
}
}
impl_submenutrait!(OnOff);
impl OnOff {
pub fn from_val(val: u32) -> Option<Self> {
match val {
@ -315,6 +359,8 @@ byteflags! {
}
}
impl_submenutrait!(Action);
impl Action {
pub fn into_attack_air_kind(self) -> Option<i32> {
#[cfg(feature = "smash")]
@ -363,6 +409,8 @@ byteflags! {
}
}
impl_submenutrait!(AttackAngle);
byteflags! {
pub struct Delay {
pub D0 = "0",
@ -399,6 +447,8 @@ byteflags! {
}
}
impl_submenutrait!(Delay);
impl Delay {
pub fn into_delay(&self) -> u32 {
if *self == Delay::empty() {
@ -477,6 +527,8 @@ byteflags! {
}
}
impl_submenutrait!(MedDelay);
impl MedDelay {
pub fn into_meddelay(&self) -> u32 {
if *self == MedDelay::empty() {
@ -555,6 +607,8 @@ byteflags! {
}
}
impl_submenutrait!(LongDelay);
impl LongDelay {
pub fn into_longdelay(&self) -> u32 {
if *self == LongDelay::empty() {
@ -621,6 +675,8 @@ byteflags! {
}
}
impl_submenutrait!(BuffOption);
impl BuffOption {
pub fn into_int(self) -> Option<i32> {
#[cfg(feature = "smash")]
@ -690,6 +746,8 @@ byteflags! {
}
}
impl_submenutrait!(ThrowOption);
impl ThrowOption {
pub fn into_cmd(self) -> Option<i32> {
#[cfg(feature = "smash")]
@ -717,6 +775,8 @@ byteflags! {
}
}
impl_submenutrait!(BoolFlag);
impl BoolFlag {
pub fn into_bool(self) -> bool {
matches!(self, BoolFlag::TRUE)
@ -732,6 +792,8 @@ byteflags! {
}
}
impl_submenutrait!(SdiFrequency);
impl SdiFrequency {
pub fn into_u32(self) -> u32 {
match self {
@ -753,6 +815,8 @@ byteflags! {
}
}
impl_submenutrait!(ClatterFrequency);
impl ClatterFrequency {
pub fn into_u32(self) -> u32 {
match self {
@ -787,6 +851,8 @@ byteflags! {
}
}
impl_submenutrait!(CharacterItem);
impl CharacterItem {
pub fn as_idx(&self) -> usize {
match *self {
@ -834,6 +900,8 @@ byteflags! {
}
}
impl_submenutrait!(MashTrigger);
impl MashTrigger {
pub const fn default() -> MashTrigger {
// Hit, block, clatter
@ -847,12 +915,21 @@ impl MashTrigger {
}
}
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
pub struct DamagePercent(pub u32, pub u32);
byteflags! {
pub struct DamagePercent {
pub LOWER = "Lower",
pub UPPER = "Upper",
}
}
impl_submenutrait!(DamagePercent);
impl DamagePercent {
pub const fn default() -> DamagePercent {
DamagePercent(0, 150)
DamagePercent {
LOWER: 0,
UPPER: 150,
}
}
}
@ -864,6 +941,8 @@ byteflags! {
}
}
impl_submenutrait!(SaveDamage);
byteflags! {
pub struct SaveStateSlot
{
@ -875,6 +954,8 @@ byteflags! {
}
}
impl_submenutrait!(SaveStateSlot);
impl SaveStateSlot {
pub fn into_idx(&self) -> Option<usize> {
match *self {
@ -898,6 +979,8 @@ byteflags! {
}
}
impl_submenutrait!(RecordSlot);
impl RecordSlot {
pub fn into_idx(&self) -> Option<usize> {
match *self {
@ -921,6 +1004,8 @@ byteflags! {
}
}
impl_submenutrait!(PlaybackSlot);
impl PlaybackSlot {
pub fn into_idx(&self) -> Option<usize> {
match *self {
@ -943,6 +1028,8 @@ byteflags! {
}
}
impl_submenutrait!(HitstunPlayback);
byteflags! {
pub struct RecordTrigger {
pub COMMAND = "Button Combination",
@ -950,6 +1037,8 @@ byteflags! {
}
}
impl_submenutrait!(RecordTrigger);
byteflags! {
pub struct RecordingDuration {
pub F60 = "60",
@ -974,6 +1063,8 @@ byteflags! {
}
}
impl_submenutrait!(RecordingDuration);
impl RecordingDuration {
pub fn into_frames(&self) -> usize {
match *self {
@ -1022,6 +1113,8 @@ byteflags! {
}
}
impl_submenutrait!(ButtonConfig);
byteflags! {
pub struct UpdatePolicy {
pub STABLE = "Stable",
@ -1030,6 +1123,8 @@ byteflags! {
}
}
impl_submenutrait!(UpdatePolicy);
impl UpdatePolicy {
pub const fn default() -> UpdatePolicy {
UpdatePolicy::STABLE
@ -1044,3 +1139,5 @@ byteflags! {
pub STATUS = "Status Only",
}
}
impl_submenutrait!(InputDisplay);