Skip to content

Commit

Permalink
feat: add Melee and PM mode config options
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyHaystack committed Jun 9, 2024
1 parent ac0e9b3 commit 374f912
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 27 deletions.
8 changes: 8 additions & 0 deletions HAL/pico/include/config_defaults.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ const Config default_config = {
},
.default_backend_config = 1,
.default_usb_backend_config = 1,
.melee_options = {
.crouch_walk_os = false,
.disable_ledgedash_socd_override = false,
},
.project_m_options = {
.true_z_press = false,
.disable_ledgedash_socd_override = false,
},
};

// clang-format on
Expand Down
9 changes: 3 additions & 6 deletions include/modes/Melee20Button.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@

#include <config.pb.h>

typedef struct {
bool crouch_walk_os = false;
} Melee20ButtonOptions;

class Melee20Button : public ControllerMode {
public:
Melee20Button(Melee20ButtonOptions options = {});
Melee20Button();
void SetConfig(GameModeConfig &config, const MeleeOptions options);

protected:
void UpdateDigitalOutputs(const InputState &inputs, OutputState &outputs);
void UpdateAnalogOutputs(const InputState &inputs, OutputState &outputs);

private:
Melee20ButtonOptions _options;
MeleeOptions _options;
bool _horizontal_socd;

void HandleSocd(InputState &inputs);
Expand Down
13 changes: 8 additions & 5 deletions include/modes/ProjectM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
#include "core/ControllerMode.hpp"
#include "core/state.hpp"

typedef struct {
bool true_z_press = false;
bool ledgedash_max_jump_traj = true;
} ProjectMOptions;
#include <config.pb.h>

// typedef struct {
// bool true_z_press = false;
// bool ledgedash_max_jump_traj = true;
// } ProjectMOptions;

class ProjectM : public ControllerMode {
public:
ProjectM(ProjectMOptions options = {});
ProjectM();
void SetConfig(GameModeConfig &config, const ProjectMOptions options);

private:
ProjectMOptions _options;
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ custom_nanopb_options =
--error-on-unmatched
lib_deps =
nanopb/Nanopb@^0.4.8
https://github.com/JonnyHaystack/HayBox-proto#703e11f
https://github.com/JonnyHaystack/HayBox-proto#f37657b

[avr_base]
platform = atmelavr
Expand Down
8 changes: 4 additions & 4 deletions src/core/mode_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#include <config.pb.h>

Melee20Button melee_mode({ .crouch_walk_os = false });
ProjectM projectm_mode({ .true_z_press = false, .ledgedash_max_jump_traj = true });
Melee20Button melee_mode;
ProjectM projectm_mode;
Ultimate ultimate_mode;
FgcMode fgc_mode;
RivalsOfAether rivals_mode;
Expand Down Expand Up @@ -49,11 +49,11 @@ void set_mode(CommunicationBackend *backend, KeyboardMode *mode) {
void set_mode(CommunicationBackend *backend, GameModeConfig &mode_config, Config &config) {
switch (mode_config.mode_id) {
case MODE_MELEE:
melee_mode.SetConfig(mode_config);
melee_mode.SetConfig(mode_config, config.melee_options);
set_mode(backend, &melee_mode);
break;
case MODE_PROJECT_M:
projectm_mode.SetConfig(mode_config);
projectm_mode.SetConfig(mode_config, config.project_m_options);
set_mode(backend, &projectm_mode);
break;
case MODE_ULTIMATE:
Expand Down
24 changes: 18 additions & 6 deletions src/modes/Melee20Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
#define ANALOG_STICK_NEUTRAL 128
#define ANALOG_STICK_MAX 208

Melee20Button::Melee20Button(Melee20ButtonOptions options) : ControllerMode() {
_options = options;
Melee20Button::Melee20Button() : ControllerMode() {
_horizontal_socd = false;
}

void Melee20Button::SetConfig(GameModeConfig &config, const MeleeOptions options) {
InputMode::SetConfig(config);
_options = options;
}

void Melee20Button::HandleSocd(InputState &inputs) {
_horizontal_socd = inputs.lf3 && inputs.lf1;
InputMode::HandleSocd(inputs);
Expand Down Expand Up @@ -73,6 +77,7 @@ void Melee20Button::UpdateAnalogOutputs(const InputState &inputs, OutputState &o
}
}

/* Mod X */
if (inputs.lt1) {
// MX + Horizontal (even if shield is held) = 6625 = 53
if (directions.horizontal) {
Expand All @@ -83,9 +88,15 @@ void Melee20Button::UpdateAnalogOutputs(const InputState &inputs, OutputState &o
outputs.leftStickY = 128 + (directions.y * 43);
}
if (directions.diagonal && shield_button_pressed) {
// MX + L, R, LS, and MS + q1/2/3/4 = 6375 3750 = 51 30
outputs.leftStickX = 128 + (directions.x * 51);
outputs.leftStickY = 128 + (directions.y * 30);
// Use custom airdodge angle if set, otherwise B0XX standard default.
if (_options.has_custom_airdodge) {
outputs.leftStickX = 128 + (directions.x * _options.custom_airdodge.x);
outputs.leftStickY = 128 + (directions.y * _options.custom_airdodge.y);
} else {
// MX + L, R, LS, and MS + q1/2/3/4 = 6375 3750 = 51 30
outputs.leftStickX = 128 + (directions.x * 51);
outputs.leftStickY = 128 + (directions.y * 30);
}
}

/* Up B angles */
Expand Down Expand Up @@ -150,6 +161,7 @@ void Melee20Button::UpdateAnalogOutputs(const InputState &inputs, OutputState &o
}
}

/* Mod Y */
if (inputs.lt2) {
// MY + Horizontal (even if shield is held) = 3375 = 27
if (directions.horizontal) {
Expand Down Expand Up @@ -240,7 +252,7 @@ void Melee20Button::UpdateAnalogOutputs(const InputState &inputs, OutputState &o

// Horizontal SOCD overrides X-axis modifiers (for ledgedash maximum jump
// trajectory).
if (_horizontal_socd && !directions.vertical) {
if (!_options.disable_ledgedash_socd_override && _horizontal_socd && !directions.vertical) {
outputs.leftStickX = 128 + (directions.x * 80);
}

Expand Down
23 changes: 18 additions & 5 deletions src/modes/ProjectM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
#define ANALOG_STICK_NEUTRAL 128
#define ANALOG_STICK_MAX 228

ProjectM::ProjectM(ProjectMOptions options) : ControllerMode() {
_options = options;
ProjectM::ProjectM() : ControllerMode() {
_horizontal_socd = false;
}

void ProjectM::SetConfig(GameModeConfig &config, const ProjectMOptions options) {
InputMode::SetConfig(config);
_options = options;
}

void ProjectM::HandleSocd(InputState &inputs) {
_horizontal_socd = inputs.lf3 && inputs.lf1;
InputMode::HandleSocd(inputs);
Expand Down Expand Up @@ -76,6 +80,7 @@ void ProjectM::UpdateAnalogOutputs(const InputState &inputs, OutputState &output
}
}

/* Mod X */
if (inputs.lt1) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * 70);
Expand All @@ -90,6 +95,7 @@ void ProjectM::UpdateAnalogOutputs(const InputState &inputs, OutputState &output
}

if (directions.diagonal) {
// Default MX Diagonal
outputs.leftStickX = 128 + (directions.x * 70);
outputs.leftStickY = 128 + (directions.y * 34);

Expand All @@ -98,9 +104,15 @@ void ProjectM::UpdateAnalogOutputs(const InputState &inputs, OutputState &output
outputs.leftStickY = 128 + (directions.y * 31);
}

// Airdodge angle
if (inputs.rf5) {
outputs.leftStickX = 128 + (directions.x * 82);
outputs.leftStickY = 128 + (directions.y * 35);
if (_options.has_custom_airdodge) {
outputs.leftStickX = 128 + (directions.x * _options.custom_airdodge.x);
outputs.leftStickY = 128 + (directions.y * _options.custom_airdodge.y);
} else {
outputs.leftStickX = 128 + (directions.x * 82);
outputs.leftStickY = 128 + (directions.y * 35);
}
}

if (inputs.rt4) {
Expand All @@ -125,6 +137,7 @@ void ProjectM::UpdateAnalogOutputs(const InputState &inputs, OutputState &output
}
}

/* Mod Y */
if (inputs.lt2) {
if (directions.horizontal) {
outputs.leftStickX = 128 + (directions.x * 35);
Expand Down Expand Up @@ -181,7 +194,7 @@ void ProjectM::UpdateAnalogOutputs(const InputState &inputs, OutputState &output

// Horizontal SOCD overrides X-axis modifiers (for ledgedash maximum jump
// trajectory).
if (_options.ledgedash_max_jump_traj && _horizontal_socd && !directions.vertical &&
if (!_options.disable_ledgedash_socd_override && _horizontal_socd && !directions.vertical &&
!shield_button_pressed) {
outputs.leftStickX = 128 + (directions.x * 100);
}
Expand Down

0 comments on commit 374f912

Please sign in to comment.