Skip to content

Commit

Permalink
Add feature to force the state of stage hazards
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatNintendoNerd committed Sep 3, 2024
1 parent e7d71df commit 5c4d9e4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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<StageID>,

/// The collection of stage identifiers assigned specialized stage hazards parameters.
#[serde(default)]
pub gimmick_param: HashMap<StageID, GimmickParam>,
}

impl Config {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
1 change: 1 addition & 0 deletions src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/service.rs
Original file line number Diff line number Diff line change
@@ -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::*;
21 changes: 21 additions & 0 deletions src/service/gimmick.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 5c4d9e4

Please sign in to comment.