fork/GramFirmware

git clone https://git.julia.blue/fork/GramFirmware

CarVacrebase to configurator818d962

gram
7.1 KiB230 linesraw
1#include "modes/ProjectM.hpp"
2
3#define ANALOG_STICK_MIN 28
4#define ANALOG_STICK_NEUTRAL 128
5#define ANALOG_STICK_MAX 228
6
7ProjectM::ProjectM() : ControllerMode() {
8    _horizontal_socd = false;
9}
10
11void ProjectM::SetConfig(GameModeConfig &config, const ProjectMOptions options) {
12    InputMode::SetConfig(config);
13    _options = options;
14}
15
16void ProjectM::HandleSocd(InputState &inputs) {
17    _horizontal_socd = inputs.lf3 && inputs.lf1;
18    InputMode::HandleSocd(inputs);
19}
20
21void ProjectM::UpdateDigitalOutputs(const InputState &inputs, OutputState &outputs) {
22    outputs.a = inputs.rt1;
23    outputs.b = inputs.rf1;
24    outputs.x = inputs.rf2;
25    outputs.y = inputs.rf6;
26    // True Z press vs macro lightshield + A.
27    if (_options.true_z_press || inputs.lt1) {
28        outputs.buttonR = inputs.rf3;
29    } else {
30        outputs.a = inputs.rt1 || inputs.rf3;
31    }
32    if (inputs.nunchuk_connected) {
33        outputs.triggerLDigital = inputs.nunchuk_z;
34    } else {
35        outputs.triggerLDigital = inputs.lf4;
36    }
37    outputs.triggerRDigital = inputs.rf5;
38    outputs.start = inputs.mb1;
39
40    // Activate D-Pad layer by holding Mod X + Mod Y or Nunchuk C button.
41    if ((inputs.lt1 && inputs.lt2) || inputs.nunchuk_c) {
42        outputs.dpadUp = inputs.rt4;
43        outputs.dpadDown = inputs.rt2;
44        outputs.dpadLeft = inputs.rt3;
45        outputs.dpadRight = inputs.rt5;
46    }
47
48    // Don't override dpad up if it's already pressed using the MX + MY dpad
49    // layer.
50    outputs.dpadUp = outputs.dpadUp || inputs.rf8;
51
52    if (inputs.mb3)
53        outputs.dpadLeft = true;
54    if (inputs.mb2)
55        outputs.dpadRight = true;
56}
57
58void ProjectM::UpdateAnalogOutputs(const InputState &inputs, OutputState &outputs) {
59    UpdateDirections(
60        inputs.lf3, // Left
61        inputs.lf1, // Right
62        inputs.lf2, // Down
63        inputs.rf4, // Up
64        inputs.rt3, // C-Left
65        inputs.rt5, // C-Right
66        inputs.rt2, // C-Down
67        inputs.rt4, // C-Up
68        ANALOG_STICK_MIN,
69        ANALOG_STICK_NEUTRAL,
70        ANALOG_STICK_MAX,
71        outputs
72    );
73
74    bool shield_button_pressed = inputs.lf4 || inputs.rf7;
75
76    if (directions.diagonal) {
77        if (directions.y == 1) {
78            outputs.leftStickX = 128 + (directions.x * 83);
79            outputs.leftStickY = 128 + (directions.y * 93);
80        }
81    }
82
83    /* Mod X */
84    if (inputs.lt1) {
85        if (directions.horizontal) {
86            outputs.leftStickX = 128 + (directions.x * 70);
87        }
88        if (directions.vertical) {
89            outputs.leftStickY = 128 + (directions.y * 60);
90        }
91
92        if (directions.cx != 0) {
93            outputs.rightStickX = 128 + (directions.cx * 65);
94            outputs.rightStickY = 128 + (directions.y * 23);
95        }
96
97        if (directions.diagonal) {
98            // Default MX Diagonal
99            outputs.leftStickX = 128 + (directions.x * 70);
100            outputs.leftStickY = 128 + (directions.y * 34);
101
102            if (inputs.rf1) {
103                outputs.leftStickX = 128 + (directions.x * 85);
104                outputs.leftStickY = 128 + (directions.y * 31);
105            }
106
107            // Airdodge angle
108            if (inputs.rf5) {
109                if (_options.has_custom_airdodge) {
110                    outputs.leftStickX = 128 + (directions.x * _options.custom_airdodge.x);
111                    outputs.leftStickY = 128 + (directions.y * _options.custom_airdodge.y);
112                } else {
113                    outputs.leftStickX = 128 + (directions.x * 82);
114                    outputs.leftStickY = 128 + (directions.y * 35);
115                }
116            }
117
118            if (inputs.rt4) {
119                outputs.leftStickX = 128 + (directions.x * 77);
120                outputs.leftStickY = 128 + (directions.y * 55);
121            }
122
123            if (inputs.rt2) {
124                outputs.leftStickX = 128 + (directions.x * 82);
125                outputs.leftStickY = 128 + (directions.y * 36);
126            }
127
128            if (inputs.rt3) {
129                outputs.leftStickX = 128 + (directions.x * 84);
130                outputs.leftStickY = 128 + (directions.y * 50);
131            }
132
133            if (inputs.rt5) {
134                outputs.leftStickX = 128 + (directions.x * 72);
135                outputs.leftStickY = 128 + (directions.y * 61);
136            }
137        }
138    }
139
140    /* Mod Y */
141    if (inputs.lt2) {
142        if (directions.horizontal) {
143            outputs.leftStickX = 128 + (directions.x * 35);
144        }
145        if (directions.vertical) {
146            outputs.leftStickY = 128 + (directions.y * 70);
147        }
148
149        if (directions.diagonal) {
150            outputs.leftStickX = 128 + (directions.x * 28);
151            outputs.leftStickY = 128 + (directions.y * 58);
152
153            if (inputs.rf1) {
154                outputs.leftStickX = 128 + (directions.x * 28);
155                outputs.leftStickY = 128 + (directions.y * 85);
156            }
157
158            if (inputs.rf5) {
159                outputs.leftStickX = 128 + (directions.x * 51);
160                outputs.leftStickY = 128 + (directions.y * 82);
161            }
162
163            if (inputs.rt4) {
164                outputs.leftStickX = 128 + (directions.x * 55);
165                outputs.leftStickY = 128 + (directions.y * 77);
166            }
167
168            if (inputs.rt2) {
169                outputs.leftStickX = 128 + (directions.x * 34);
170                outputs.leftStickY = 128 + (directions.y * 82);
171            }
172
173            if (inputs.rt3) {
174                outputs.leftStickX = 128 + (directions.x * 40);
175                outputs.leftStickY = 128 + (directions.y * 84);
176            }
177
178            if (inputs.rt5) {
179                outputs.leftStickX = 128 + (directions.x * 62);
180                outputs.leftStickY = 128 + (directions.y * 72);
181            }
182        }
183    }
184
185    // C-stick ASDI Slideoff angle overrides any other C-stick modifiers (such as
186    // angled fsmash).
187    // We don't apply this for c-up + c-left/c-right in case we want to implement
188    // C-stick nair somehow.
189    if (directions.cx != 0 && directions.cy == -1) {
190        // 3000 9875 = 30 78
191        outputs.rightStickX = 128 + (directions.cx * 35);
192        outputs.rightStickY = 128 + (directions.cy * 98);
193    }
194
195    // Horizontal SOCD overrides X-axis modifiers (for ledgedash maximum jump
196    // trajectory).
197    if (!_options.disable_ledgedash_socd_override && _horizontal_socd && !directions.vertical &&
198        !shield_button_pressed) {
199        outputs.leftStickX = 128 + (directions.x * 100);
200    }
201
202    if (inputs.rf7) {
203        outputs.triggerRAnalog = 49;
204    }
205
206    // Send lightshield input if we are using Z = lightshield + A macro.
207    if (inputs.rf3 && !(inputs.lt1 || _options.true_z_press)) {
208        outputs.triggerRAnalog = 49;
209    }
210
211    if (outputs.triggerLDigital) {
212        outputs.triggerLAnalog = 140;
213    }
214
215    if (outputs.triggerRDigital) {
216        outputs.triggerRAnalog = 140;
217    }
218
219    // Shut off C-stick when using D-Pad layer.
220    if ((inputs.lt1 && inputs.lt2) || inputs.nunchuk_c) {
221        outputs.rightStickX = 128;
222        outputs.rightStickY = 128;
223    }
224
225    // Nunchuk overrides left stick.
226    if (inputs.nunchuk_connected) {
227        outputs.leftStickX = inputs.nunchuk_x;
228        outputs.leftStickY = inputs.nunchuk_y;
229    }
230}