1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-01-20 09:20:13 +00:00

Restrict menu opening multiple times in rapid succession (#245)

Co-authored-by: asimon-1 <asimon1@protonmail.com>
This commit is contained in:
asimon-1 2021-08-27 16:38:23 -07:00 committed by GitHub
parent cd01730af3
commit 3fef1a78df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View file

@ -6,6 +6,17 @@ use smash::lib::lua_const::*;
use skyline_web::{Background, BootDisplay, Webpage};
use ramhorns::{Template, Content};
use strum::IntoEnumIterator;
use crate::training::frame_counter;
static mut FRAME_COUNTER_INDEX: usize = 0;
const MENU_LOCKOUT_FRAMES: u32 = 5;
pub fn init() {
unsafe {
FRAME_COUNTER_INDEX = frame_counter::register_counter();
}
}
#[derive(Content)]
struct Slider {
@ -245,8 +256,19 @@ pub fn set_menu_from_url(s: &str) {
}
pub unsafe fn menu_condition(module_accessor: &mut smash::app::BattleObjectModuleAccessor) -> bool {
ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_SPECIAL) &&
ControlModule::check_button_on_trriger(module_accessor, *CONTROL_PAD_BUTTON_APPEAL_HI)
// Only check for button combination if the counter is 0 (not locked out)
match frame_counter::get_frame_count(FRAME_COUNTER_INDEX) {
0 => {
ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_SPECIAL) &&
ControlModule::check_button_on_trriger(module_accessor, *CONTROL_PAD_BUTTON_APPEAL_HI)
},
1..MENU_LOCKOUT_FRAMES => false,
_ => {
// Waited longer than the lockout time, reset the counter so the menu can be opened again
frame_counter::full_reset(FRAME_COUNTER_INDEX);
false
}
}
}
pub unsafe fn write_menu() {
@ -318,6 +340,8 @@ pub unsafe fn write_menu() {
}
pub unsafe fn spawn_menu() {
frame_counter::reset_frame_count(FRAME_COUNTER_INDEX);
frame_counter::start_counting(FRAME_COUNTER_INDEX);
let fname = "training_menu.html";
let params = MENU.to_url_params();
let page_response = Webpage::new()

View file

@ -12,12 +12,12 @@ pub mod sdi;
pub mod shield;
pub mod tech;
pub mod ledge;
pub mod frame_counter;
mod air_dodge_direction;
mod attack_angle;
mod character_specific;
mod fast_fall;
mod frame_counter;
mod full_hop;
mod input_delay;
mod input_record;