1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-20 08:54:15 +00:00

Mirrored save states (#216)

* Add mirrored save states to menu and save_states.rs

* Update LongDelay.into_string()

* Add missing submenus

* Add mirrored save states to menu and save_states.rs

* Fix outdated reference to MENU_STRUCT

* Change MIRROR_STATE type from bool to f32

* Move should_mirror call

* Add to_url_param() for SaveStateMirroring

* Fix Facing Direction mirroring bug

Co-authored-by: asimon-1 <asimon1@protonmail.com>
Co-authored-by: jugeeya <jugeeya@live.com>
This commit is contained in:
asimon-1 2021-08-01 12:53:00 -07:00 committed by GitHub
parent 91348ed6cd
commit b57cf538f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 3 deletions

View file

@ -265,6 +265,33 @@ impl Shield {
}
}
// Save State Mirroring
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, FromPrimitive)]
pub enum SaveStateMirroring {
None = 0,
Alternate = 1,
Random = 2,
}
impl SaveStateMirroring {
fn into_string(self) -> String {
match self {
SaveStateMirroring::None => "None",
SaveStateMirroring::Alternate => "Alternate",
SaveStateMirroring::Random => "Random",
}.to_string()
}
fn to_url_param(&self) -> String {
match self {
SaveStateMirroring::None => "0",
SaveStateMirroring::Alternate => "1",
SaveStateMirroring::Random => "2",
}.to_string()
}
}
// Defensive States
bitflags! {
pub struct Defensive : u32 {
@ -710,6 +737,7 @@ url_params! {
pub full_hop: BoolFlag,
pub input_delay: i32,
pub save_damage: OnOff,
pub save_state_mirroring: SaveStateMirroring,
}
}
@ -752,6 +780,8 @@ impl TrainingModpackMenu {
(stage_hazards = OnOff::from_val(val))
(tech_state = TechFlags::from_bits(val))
(save_damage = OnOff::from_val(val))
(save_state_mirroring = num::FromPrimitive::from_u32(val))
);
}
}

View file

@ -276,6 +276,18 @@ pub unsafe fn write_menu() {
[].to_vec()
);
overall_menu.add_sub_menu(
"Mirroring",
"save_state_mirroring",
MENU.save_state_mirroring as usize,
[
("None", SaveStateMirroring::None as usize),
("Alternate", SaveStateMirroring::Alternate as usize),
("Random", SaveStateMirroring::Random as usize),
].to_vec(),
[].to_vec()
);
// Slider menus
overall_menu.add_sub_menu(
"Input Delay",

View file

@ -33,6 +33,7 @@ pub static mut MENU: consts::TrainingModpackMenu = consts::TrainingModpackMenu {
full_hop: BoolFlag::empty(),
input_delay: 0,
save_damage: OnOff::On,
save_state_mirroring: SaveStateMirroring::None,
};
pub static mut FIGHTER_MANAGER_ADDR: usize = 0;

View file

@ -1,6 +1,8 @@
use crate::common::consts::FighterId;
use crate::common::consts::OnOff;
use crate::common::consts::SaveStateMirroring;
use crate::common::MENU;
use crate::common::get_random_int;
use crate::training::reset;
use smash::app::{self, lua_bind::*};
use smash::hash40;
@ -41,6 +43,17 @@ use SaveState::*;
static mut SAVE_STATE_PLAYER: SavedState = default_save_state!();
static mut SAVE_STATE_CPU: SavedState = default_save_state!();
static mut MIRROR_STATE: f32 = 1.0;
// MIRROR_STATE == 1 -> Do not mirror
// MIRROR_STATE == -1 -> Do Mirror
pub unsafe fn should_mirror() -> f32 {
match MENU.save_state_mirroring {
SaveStateMirroring::None => 1.0,
SaveStateMirroring::Alternate => -1.0 * MIRROR_STATE,
SaveStateMirroring::Random => {([-1.0, 1.0])[get_random_int(2) as usize]},
}
}
pub unsafe fn get_param_int(
_module_accessor: &mut app::BattleObjectModuleAccessor,
@ -107,7 +120,7 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor)
SAVE_STATE_PLAYER.state = KillPlayer;
SAVE_STATE_CPU.state = KillPlayer;
}
MIRROR_STATE = should_mirror();
reset::on_reset();
return;
}
@ -146,12 +159,13 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor)
KineticModule::clear_speed_all(module_accessor);
let pos = Vector3f {
x: save_state.x,
x: MIRROR_STATE * save_state.x,
y: save_state.y,
z: 0.0,
};
let lr = MIRROR_STATE * save_state.lr;
PostureModule::set_pos(module_accessor, &pos);
PostureModule::set_lr(module_accessor, save_state.lr);
PostureModule::set_lr(module_accessor, lr);
if save_state.situation_kind == SITUATION_KIND_GROUND {
if status != FIGHTER_STATUS_KIND_WAIT {
@ -201,6 +215,7 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor)
if ControlModule::check_button_on(module_accessor, *CONTROL_PAD_BUTTON_CATCH)
&& ControlModule::check_button_trigger(module_accessor, *CONTROL_PAD_BUTTON_APPEAL_LW)
{
MIRROR_STATE = 1.0;
SAVE_STATE_PLAYER.state = Save;
SAVE_STATE_CPU.state = Save;
}