From 5c4d9e4a5faba3204e6482ae2209fbb86f54401b Mon Sep 17 00:00:00 2001 From: ThatNintendoNerd Date: Mon, 2 Sep 2024 23:21:18 -0700 Subject: [PATCH] Add feature to force the state of stage hazards --- src/config.rs | 8 +++++++- src/hooks.rs | 1 + src/service.rs | 2 ++ src/service/gimmick.rs | 21 +++++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/service/gimmick.rs diff --git a/src/config.rs b/src/config.rs index 23b1fc0..97ce5c8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,7 +7,7 @@ use serde::Deserialize; use smash_stage::app::StageID; use walkdir::WalkDir; -use crate::service::GravityParam; +use crate::service::{GimmickParam, GravityParam}; /// The container for deserializable plugin settings. #[derive(Default, Deserialize)] @@ -31,6 +31,10 @@ pub struct Config { /// The collection of stage identifiers which should discard all specialized programming. #[serde(default)] pub discard_stage_code: Vec, + + /// The collection of stage identifiers assigned specialized stage hazards parameters. + #[serde(default)] + pub gimmick_param: HashMap, } impl Config { @@ -99,6 +103,7 @@ impl Config { gravity_param, stage_additional_settings, discard_stage_code, + gimmick_param, } = other; self.new_dynamic_collisions.extend(new_dynamic_collisions); @@ -107,5 +112,6 @@ impl Config { self.stage_additional_settings .extend(stage_additional_settings); self.discard_stage_code.extend(discard_stage_code); + self.gimmick_param.extend(gimmick_param); } } diff --git a/src/hooks.rs b/src/hooks.rs index 68601cf..90866d1 100644 --- a/src/hooks.rs +++ b/src/hooks.rs @@ -22,6 +22,7 @@ fn is_flat_stage(stage_id: StageID) -> bool { #[skyline::hook(offset = Offsets::get().set_stage_random_settings)] fn set_stage_random_settings(stage_parameter: &mut GlobalStageParameter, seed: u32) { service::try_set_stage_additional_settings(stage_parameter); + service::try_set_gimmick_param(stage_parameter); original!()(stage_parameter, seed); } diff --git a/src/service.rs b/src/service.rs index 6de2d93..2e8ca01 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1,7 +1,9 @@ +mod gimmick; mod gravity; mod ground; mod settings; +pub(crate) use gimmick::*; pub(crate) use gravity::*; pub(crate) use ground::*; pub(crate) use settings::*; diff --git a/src/service/gimmick.rs b/src/service/gimmick.rs new file mode 100644 index 0000000..2487d53 --- /dev/null +++ b/src/service/gimmick.rs @@ -0,0 +1,21 @@ +use serde::Deserialize; +use smash_stage::app::GlobalStageParameter; + +use crate::config::Config; + +/// The parameters for stage hazards. +#[derive(Deserialize)] +pub struct GimmickParam { + /// Determines if stage hazards should be enabled. + #[serde(default)] + is_gimmick: bool, +} + +/// Updates the parameters for stage hazards if the given stage identifier is assigned specialized parameters. +pub fn try_set_gimmick_param(stage_parameter: &mut GlobalStageParameter) { + let stage_id = stage_parameter.stage_id(); + + if let Some(param) = Config::get().gimmick_param.get(&stage_id) { + stage_parameter.is_gimmick = param.is_gimmick; + } +}