Skip to content

Commit

Permalink
add/modify WorldLightFader
Browse files Browse the repository at this point in the history
  • Loading branch information
toasterparty committed Mar 4, 2024
1 parent 892dd36 commit 165ad18
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 44 deletions.
34 changes: 34 additions & 0 deletions schema/randomprime.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4603,6 +4603,40 @@
],
"additionalProperties": false
}
},
"worldLightFaders": {
"description": "Add worldLightFaders to this room. These objects dim the room to the specified level when they receive the `ACTION` script message.",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"$ref": "#/$defs/addModifyId"
},
"layer": {
"$ref": "#/$defs/addModifyLayer"
},
"active": {
"description": "Default active state of the player actor.",
"type": "boolean",
"default": true
},
"fadedLightLevel": {
"description": "Amount to scale light by where 1.0 is unchanged light level.",
"type": "number",
"exclusiveMinimum": 0.0
},
"fadeSpeed": {
"description": "Duration in seconds to execute the fade",
"type": "number",
"exclusiveMinimum": 0.0
}
},
"required": [
"id"
],
"additionalProperties": false
}
}
},
"additionalProperties": false
Expand Down
70 changes: 50 additions & 20 deletions src/add_modify_obj_patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::{
BombSlotConfig,
ControllerActionConfig,
PlayerActorConfig,
WorldLightFaderConfig,
},
pickup_meta::PickupType,
door_meta::DoorType,
Expand Down Expand Up @@ -115,7 +116,7 @@ macro_rules! add_edit_obj_helper {

// modify it
$update_property_data!(obj);

// remove original
scly.layers
.as_mut_vec()[layer_id as usize]
Expand Down Expand Up @@ -192,14 +193,14 @@ pub fn patch_add_streamed_audio<'r>(
}
};
}

macro_rules! update {
($obj:expr) => {
let property_data = $obj.property_data.as_streamed_audio_mut().unwrap();

property_data.audio_file_name = string_to_cstr(config.audio_file_name);
property_data.is_music = config.is_music as u8;

if let Some(active ) = config.active { property_data.active = active as u8 }
if let Some(no_stop_on_deactivate ) = config.no_stop_on_deactivate { property_data.no_stop_on_deactivate = no_stop_on_deactivate as u8 }
if let Some(fade_in_time ) = config.fade_in_time { property_data.fade_in_time = fade_in_time }
Expand Down Expand Up @@ -230,12 +231,12 @@ pub fn patch_add_liquid<'r>(
asset_id: file_id,
asset_type: fourcc,
});

area.add_dependencies(resources, 0, deps_iter);
}

let mut water_obj = water_type.to_obj();
{
{
let water = water_obj.property_data.as_water_mut().unwrap();
water.position[0] = config.position[0];
water.position[1] = config.position[1];
Expand Down Expand Up @@ -525,7 +526,7 @@ pub fn patch_add_special_fn<'r>(
let property_data = $obj.property_data.as_special_function_mut().unwrap();

property_data.type_ = config.type_ as u32;

if let Some(position ) = config.position { property_data.position = position .into() }
if let Some(rotation ) = config.rotation { property_data.rotation = rotation .into() }
if let Some(_ ) = config.unknown1 .as_ref() { property_data.unknown0 = unknown0 }
Expand Down Expand Up @@ -751,10 +752,10 @@ pub fn patch_add_player_hint<'r>(
() => {
structs::PlayerHint {
name: b"my playerhint\0".as_cstr(),

position: [0.0, 0.0, 0.0].into(),
rotation: [0.0, 0.0, 0.0].into(),

active: config.active.unwrap_or(true) as u8,

data: structs::PlayerHintStruct {
Expand Down Expand Up @@ -1160,7 +1161,7 @@ pub fn patch_add_bomb_slot<'r>(
structs::SclyObject {
instance_id: player_hint_id,
property_data: structs::PlayerHint {
name: b"disableboost\0".as_cstr(),
name: b"disableboost\0".as_cstr(),
position: [0.0, 0.0, 0.0].into(),
rotation: [0.0, 0.0, 0.0].into(),
active: 1,
Expand Down Expand Up @@ -1416,6 +1417,35 @@ pub fn patch_add_player_actor<'r>(
add_edit_obj_helper!(area, config.id, config.layer, PlayerActor, new, update);
}

pub fn patch_add_world_light_fader<'r>(
_ps: &mut PatcherState,
area: &mut mlvl_wrapper::MlvlArea,
config: WorldLightFaderConfig,
) -> Result<(), String>
{
macro_rules! new {
() => {
structs::WorldLightFader {
name: b"my world light fader\0".as_cstr(),
active: config.active.unwrap_or(true) as u8,
faded_light_level: config.faded_light_level.unwrap_or(0.2),
fade_speed: config.fade_speed.unwrap_or(0.25),
}
};
}

macro_rules! update {
($obj:expr) => {
let property_data = $obj.property_data.as_world_light_fader_mut().unwrap();
if let Some(active ) = config.active { property_data.active = active as u8 }
if let Some(faded_light_level) = config.faded_light_level { property_data.faded_light_level = faded_light_level }
if let Some(fade_speed ) = config.fade_speed { property_data.fade_speed = fade_speed }
};
}

add_edit_obj_helper!(area, Some(config.id), config.layer, WorldLightFader, new, update);
}

pub fn patch_add_controller_action<'r>(
_ps: &mut PatcherState,
area: &mut mlvl_wrapper::MlvlArea,
Expand All @@ -1440,7 +1470,7 @@ pub fn patch_add_controller_action<'r>(
let property_data = $obj.property_data.as_controller_action_mut().unwrap();

property_data.action = config.action as u32;

if let Some(active ) = config.active {property_data.active = active as u8 }
if let Some(one_shot ) = config.one_shot {property_data.one_shot = one_shot as u8 }
};
Expand Down Expand Up @@ -1753,13 +1783,13 @@ pub fn patch_add_platform<'r>(
instance_id: damaged_block_id,
property_data: structs::Platform {
name: b"myplatform\0".as_cstr(),

position: config.position.into(),
rotation: config.rotation.unwrap_or([0.0, 0.0, 0.0]).into(),
scale: [1.0, 1.0, 1.0].into(),
extent: [0.0, 0.0, 0.0].into(),
scan_offset: [0.0, 0.0, 0.0].into(),

cmdl: ResId::<res_id::CMDL>::new(0x133336F4),

ancs: structs::scly_structs::AncsProp {
Expand Down Expand Up @@ -1791,11 +1821,11 @@ pub fn patch_add_platform<'r>(
xray_cskr: ResId::invalid(), // None
thermal_cmdl: ResId::invalid(), // None
thermal_cskr: ResId::invalid(), // None

unknown0: 1,
unknown1: 1.0,
unknown2: 1.0,

visor_params: structs::scly_structs::VisorParameters {
unknown0: 0,
target_passthrough: 0,
Expand All @@ -1806,18 +1836,18 @@ pub fn patch_add_platform<'r>(
unknown4: 0,
unknown5: 1.0
},

speed: 5.0,
active: 0,

dcln,

health_info: structs::scly_structs::HealthInfo {
health: 1.0,
knockback_resistance: 1.0,
},
damage_vulnerability: vulnerability.clone(),

detect_collision: 0,
unknown4: 1.0,
unknown5: 0,
Expand Down Expand Up @@ -1980,7 +2010,7 @@ pub fn patch_add_platform<'r>(
pitch: 0,
}.into(),
connections: vec![

].into(),
},
structs::SclyObject {
Expand Down
24 changes: 18 additions & 6 deletions src/patch_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ pub struct ControllerActionConfig
pub id: u32,
pub layer: Option<u32>,
pub active: Option<bool>,

pub action: ControllerActionType,

pub one_shot: Option<bool>,
Expand Down Expand Up @@ -943,6 +943,17 @@ pub struct SpawnPointConfig
pub items: Option<StartingItems>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct WorldLightFaderConfig
{
pub id: u32,
pub layer: Option<u32>,
pub active: Option<bool>,
pub faded_light_level: Option<f32>,
pub fade_speed: Option<f32>,
}

#[derive(Deserialize, Debug, Default, Clone)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct RoomConfig
Expand Down Expand Up @@ -995,6 +1006,7 @@ pub struct RoomConfig
pub bomb_slots: Option<Vec<BombSlotConfig>>,
pub controller_actions: Option<Vec<ControllerActionConfig>>,
pub player_actors: Option<Vec<PlayerActorConfig>>,
pub world_light_faders: Option<Vec<WorldLightFaderConfig>>,
// Don't forget to update merge_json when adding here
}

Expand Down Expand Up @@ -1417,7 +1429,7 @@ struct PatchConfigPrivate

#[serde(default)]
level_data: HashMap<String, LevelConfig>,

#[serde(default)]
strg: HashMap<String, Vec<String>>, // "<decimal asset ID>": <non-null terminated table of strings>
}
Expand Down Expand Up @@ -1709,7 +1721,7 @@ fn merge_json(config: &mut PatchConfigPrivate, text: &'static str) -> Result<(),
{
let data = serde_json::from_str(text);
let data: PatchConfigPrivate = data.map_err(|e| format!("JSON parse failed: {}", e))?;
config.merge(data);
config.merge(data);

Ok(())
}
Expand All @@ -1727,7 +1739,7 @@ impl PatchConfigPrivate
if level_config.is_none() {
continue;
}
let rooms = &level_config.unwrap().rooms;
let rooms = &level_config.unwrap().rooms;

for (_, room_config) in rooms {
if room_config.special_functions.is_none() {
Expand Down Expand Up @@ -1760,7 +1772,7 @@ impl PatchConfigPrivate
}

layers
}
}

/* Extends the "stuff" added/edited in each room */
pub fn merge(self: &mut Self, other: Self)
Expand Down Expand Up @@ -1958,7 +1970,7 @@ impl PatchConfigPrivate

let mut reader = Reader::new(&input_iso[..]);
let gc_disc: structs::GcDisc = reader.read(());

match (&gc_disc.header.game_identifier(), gc_disc.header.disc_id, gc_disc.header.version) {
(b"GM8E01", 0, 0) => Version::NtscU0_00,
(b"GM8E01", 0, 1) => Version::NtscU0_01,
Expand Down
21 changes: 17 additions & 4 deletions src/patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11919,7 +11919,7 @@ fn patch_final_boss_permadeath<'r>(
message,
target_object_id: special_function_ids[i],
});
}
}
layers[0].objects.as_mut_vec().push(
structs::SclyObject {
instance_id: change_layer_timer_id,
Expand Down Expand Up @@ -12573,7 +12573,7 @@ fn patch_modify_dock<'r>(
let strg_dep: structs::Dependency = strg_id.into();
area.add_dependencies(game_resources, 0, iter::once(strg_dep));
let frme_dep: structs::Dependency = frme_id.into();
area.add_dependencies(game_resources, 0, iter::once(frme_dep));
area.add_dependencies(game_resources, 0, iter::once(frme_dep));
}

let trigger_id = area.new_object_id_from_layer_name("Default");
Expand Down Expand Up @@ -15533,6 +15533,19 @@ fn build_and_run_patches<'r>(gc_disc: &mut structs::GcDisc<'r>, config: &PatchCo
}
}

if let Some(world_light_faders) = room.world_light_faders.as_ref() {
for config in world_light_faders {
patcher.add_scly_patch(
(pak_name.as_bytes(), room_info.room_id.to_u32()),
move |ps, area| patch_add_world_light_fader(
ps,
area,
config.clone(),
),
);
}
}

if let Some(controller_actions) = room.controller_actions.as_ref() {
for config in controller_actions {
patcher.add_scly_patch(
Expand Down Expand Up @@ -15586,7 +15599,7 @@ fn build_and_run_patches<'r>(gc_disc: &mut structs::GcDisc<'r>, config: &PatchCo
if config.type_ != SpecialFunctionType::CinematicSkip {
continue;
}

if let Some(id) = config.id.as_ref() {
skipper_ids.push(*id);
}
Expand Down Expand Up @@ -16276,7 +16289,7 @@ fn build_and_run_patches<'r>(gc_disc: &mut structs::GcDisc<'r>, config: &PatchCo
// };

// Patch the current room to lead to the new destination room

let scan = match config.door_destination_scans {
false => None,
true => Some((dest_scan_id.clone(), dest_strg_id.clone()))
Expand Down
3 changes: 3 additions & 0 deletions structs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub mod scly_props
pub mod trigger;
pub mod water;
pub mod waypoint;
pub mod world_light_fader;
pub mod world_transporter;

// "Generic" edit update
Expand Down Expand Up @@ -165,6 +166,7 @@ pub mod scly_props
pub use self::trigger::*;
pub use self::water::*;
pub use self::waypoint::*;
pub use self::world_light_fader::*;
pub use self::world_transporter::*;

// "Generic" edit update
Expand Down Expand Up @@ -265,6 +267,7 @@ pub use scly_props::trigger::*;
pub use scly_props::water::*;
pub use scly_props::waypoint::*;
pub use scly_props::world_transporter::*;
pub use scly_props::world_light_fader::*;

// bosses
pub use scly_props::beetle::*;
Expand Down
Loading

0 comments on commit 165ad18

Please sign in to comment.