Skip to content

Commit

Permalink
Add/Modify controllerActions (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMiguel211 authored Feb 8, 2024
1 parent 10002e1 commit d1f6a55
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 0 deletions.
105 changes: 105 additions & 0 deletions schema/randomprime.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4456,6 +4456,111 @@
],
"additionalProperties": false
}
},
"controllerActions": {
"description": "Add ControllerAction objects in this room. It will send a signal upon press and release, entering the `OPEN` and `CLOSED` state respectively.",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"$ref": "#/$defs/addModifyId"
},
"layer": {
"$ref": "#/$defs/addModifyLayer"
},
"active": {
"description": "Default active state of the ControllerAction object.",
"type": "boolean",
"default": true
},
"action": {
"description": "Select an action that matches the desired button on the controller. Example: `Morph` is the X button. (Note that the majority of these are unused or share the same button)",
"type": "string",
"enum": [
"Forward",
"Backward",
"TurnLeft",
"TurnRight",
"StrafeLeft",
"StrafeRight",
"LookLeft",
"LookRight",
"LookUp",
"LookDown",
"JumpOrBoost",
"FireOrBomb",
"MissileOrPowerBomb",
"Morph",
"AimUp",
"AimDown",
"CycleBeamUp",
"CycleBeamDown",
"CycleItem",
"PowerBeam",
"IceBeam",
"WaveBeam",
"PlasmaBeam",
"ToggleHolster",
"OrbitClose",
"OrbitFar",
"OrbitObject",
"OrbitSelect",
"OrbitConfirm",
"OrbitLeft",
"OrbitRight",
"OrbitUp",
"OrbitDown",
"LookHold1",
"LookHold2",
"LookZoomIn",
"LookZoomOut",
"AimHold",
"MapCircleUp",
"MapCircleDown",
"MapCircleLeft",
"MapCircleRight",
"MapMoveForward",
"MapMoveBack",
"MapMoveLeft",
"MapMoveRight",
"MapZoomIn",
"MapZoomOut",
"SpiderBall",
"ChaseCamera",
"XRayVisor",
"ThermoVisor",
"EnviroVisor",
"NoVisor",
"VisorMenu",
"VisorUp",
"VisorDown",
"Unknown1",
"Unknown2",
"UseShield",
"ScanItem",
"Unknown3",
"Unknown4",
"Unknown5",
"Unknown6",
"PreviousPauseScreen",
"NextPauseScreen",
"Unknown7",
"None"
]
},
"oneShot": {
"description": "Specify if the object will deactivate after being used",
"type": "boolean",
"default": false
}
},
"required": [
"id",
"action"
],
"additionalProperties": false
}
}
},
"additionalProperties": false
Expand Down
34 changes: 34 additions & 0 deletions src/add_modify_obj_patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::{
PlayerHintConfig,
FogConfig,
BombSlotConfig,
ControllerActionConfig,
},
pickup_meta::PickupType,
door_meta::DoorType,
Expand Down Expand Up @@ -1312,6 +1313,39 @@ pub fn patch_add_bomb_slot<'r>(
Ok(())
}

pub fn patch_add_controller_action<'r>(
_ps: &mut PatcherState,
area: &mut mlvl_wrapper::MlvlArea,
config: ControllerActionConfig,
)
-> Result<(), String>
{

macro_rules! new {
() => {
structs::ControllerAction {
name: b"my ctrlaction\0".as_cstr(),
active: config.active.unwrap_or(true) as u8,
action: config.action as u32,
one_shot: config.one_shot.unwrap_or(false) as u8,
}
};
}

macro_rules! update {
($obj:expr) => {
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 }
};
}

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

pub fn patch_add_platform<'r>(
_ps: &mut PatcherState,
area: &mut mlvl_wrapper::MlvlArea<'r, '_, '_, '_>,
Expand Down
89 changes: 89 additions & 0 deletions src/patch_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,93 @@ pub enum EnviornmentalEffect {
Bubbles,
}

#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq)]
#[serde(deny_unknown_fields)]
pub enum ControllerActionType {
Forward = 0,
Backward,
TurnLeft,
TurnRight,
StrafeLeft,
StrafeRight,
LookLeft,
LookRight,
LookUp,
LookDown,
JumpOrBoost,
FireOrBomb,
MissileOrPowerBomb,
Morph,
AimUp,
AimDown,
CycleBeamUp,
CycleBeamDown,
CycleItem,
PowerBeam,
IceBeam,
WaveBeam,
PlasmaBeam,
ToggleHolster,
OrbitClose,
OrbitFar,
OrbitObject,
OrbitSelect,
OrbitConfirm,
OrbitLeft,
OrbitRight,
OrbitUp,
OrbitDown,
LookHold1,
LookHold2,
LookZoomIn,
LookZoomOut,
AimHold,
MapCircleUp,
MapCircleDown,
MapCircleLeft,
MapCircleRight,
MapMoveForward,
MapMoveBack,
MapMoveLeft,
MapMoveRight,
MapZoomIn,
MapZoomOut,
SpiderBall,
ChaseCamera,
XRayVisor,
ThermoVisor,
EnviroVisor,
NoVisor,
VisorMenu,
VisorUp,
VisorDown,
Unknown1,
Unknown2,
UseShield,
ScanItem,
Unknown3,
Unknown4,
Unknown5,
Unknown6,
PreviousPauseScreen,
NextPauseScreen,
Unknown7,
None,
}

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

pub action: ControllerActionType,

pub one_shot: Option<bool>,
}

#[derive(Debug, Serialize, Deserialize, Copy, Clone, Eq, PartialEq)]
#[allow(non_camel_case_types)]
pub enum ConnectionState {
Expand Down Expand Up @@ -896,6 +983,7 @@ pub struct RoomConfig
pub player_hints: Option<Vec<PlayerHintConfig>>,
pub distance_fogs: Option<Vec<FogConfig>>,
pub bomb_slots: Option<Vec<BombSlotConfig>>,
pub controller_actions: Option<Vec<ControllerActionConfig>>,
// Don't forget to update merge_json when adding here
}

Expand Down Expand Up @@ -1733,6 +1821,7 @@ impl PatchConfigPrivate
extend_option_vec!(player_hints , self_room_config, other_room_config);
extend_option_vec!(distance_fogs , self_room_config, other_room_config);
extend_option_vec!(bomb_slots , self_room_config, other_room_config);
extend_option_vec!(controller_actions, self_room_config, other_room_config);

if let Some(other_layers) = &other_room_config.layers {
if self_room_config.layers.is_none() {
Expand Down
13 changes: 13 additions & 0 deletions src/patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15521,6 +15521,19 @@ fn build_and_run_patches<'r>(gc_disc: &mut structs::GcDisc<'r>, config: &PatchCo
}
}

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

if room.streamed_audios.is_some() {
for config in room.streamed_audios.as_ref().unwrap() {
patcher.add_scly_patch(
Expand Down
3 changes: 3 additions & 0 deletions structs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub mod scly_props
pub mod camera_filter_keyframe;
pub mod camera_hint_trigger;
pub mod camera_hint;
pub mod controller_action;
pub mod counter;
pub mod damageable_trigger;
pub mod distance_fog;
Expand Down Expand Up @@ -134,6 +135,7 @@ pub mod scly_props
pub use self::camera_filter_keyframe::*;
pub use self::camera_hint_trigger::*;
pub use self::camera_hint::*;
pub use self::controller_action::*;
pub use self::counter::*;
pub use self::damageable_trigger::*;
pub use self::distance_fog::*;
Expand Down Expand Up @@ -231,6 +233,7 @@ pub use scly_props::camera_blur_keyframe::*;
pub use scly_props::camera_filter_keyframe::*;
pub use scly_props::camera_hint_trigger::*;
pub use scly_props::camera_hint::*;
pub use scly_props::controller_action::*;
pub use scly_props::counter::*;
pub use scly_props::damageable_trigger::*;
pub use scly_props::distance_fog::*;
Expand Down
1 change: 1 addition & 0 deletions structs/src/scly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ build_scly_property!(
CameraFilterKeyframe, is_camera_filter_keyframe, as_camera_filter_keyframe, as_camera_filter_keyframe_mut,
CameraHint, is_camera_hint, as_camera_hint, as_camera_hint_mut,
CameraHintTrigger, is_camera_hint_trigger, as_camera_hint_trigger, as_camera_hint_trigger_mut,
ControllerAction, is_controller_action, as_controller_action, as_controller_action_mut,
Counter, is_counter, as_counter, as_counter_mut,
DamageableTrigger, is_damageable_trigger, as_damageable_trigger, as_damageable_trigger_mut,
DistanceFog, is_distance_fog, as_distance_fog, as_distance_fog_mut,
Expand Down
23 changes: 23 additions & 0 deletions structs/src/scly_props/controller_action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use auto_struct_macros::auto_struct;

use reader_writer::CStr;
use crate::SclyPropertyData;

#[auto_struct(Readable, Writable)]
#[derive(Debug, Clone)]
pub struct ControllerAction<'r>
{
#[auto_struct(expect = 4)]
pub prop_count: u32,

pub name: CStr<'r>,

pub active: u8,
pub action: u32,
pub one_shot: u8,
}

impl<'r> SclyPropertyData for ControllerAction<'r>
{
const OBJECT_TYPE: u8 = 0x55;
}

0 comments on commit d1f6a55

Please sign in to comment.