fork/GramFirmware

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

CarVacrebase to configurator818d962

gram
10.5 KiB297 linesraw
1#include "modes/Melee18Button.hpp"
2
3#define ANALOG_STICK_MIN 48
4#define ANALOG_STICK_NEUTRAL 128
5#define ANALOG_STICK_MAX 208
6
7Melee18Button::Melee18Button(Melee18ButtonOptions options) : ControllerMode() {
8    _options = options;
9    horizontal_socd = false;
10}
11
12void Melee18Button::HandleSocd(InputState &inputs) {
13    horizontal_socd = inputs.lf3 && inputs.lf1;
14    InputMode::HandleSocd(inputs);
15}
16
17void Melee18Button::UpdateDigitalOutputs(const InputState &inputs, OutputState &outputs) {
18    outputs.a = inputs.rt1;
19    outputs.b = inputs.rf1;
20    outputs.x = inputs.rf2;
21    outputs.y = inputs.rf6;
22    outputs.buttonR = inputs.rf3;
23    if (inputs.nunchuk_connected) {
24        // Lightshield with C button.
25        if (inputs.nunchuk_c) {
26            outputs.triggerLAnalog = 49;
27        }
28        outputs.triggerLDigital = inputs.nunchuk_z;
29    } else {
30        outputs.triggerLDigital = inputs.lf4;
31    }
32    outputs.triggerRDigital = inputs.rf5;
33    outputs.start = inputs.mb1;
34
35    // Activate D-Pad layer by holding Mod X + Mod Y.
36    if (inputs.lt1 && inputs.lt2) {
37        outputs.dpadUp = inputs.rt4;
38        outputs.dpadDown = inputs.rt2;
39        outputs.dpadLeft = inputs.rt3;
40        outputs.dpadRight = inputs.rt5;
41    }
42
43    if (inputs.mb3)
44        outputs.dpadLeft = true;
45    if (inputs.mb2)
46        outputs.dpadRight = true;
47}
48
49void Melee18Button::UpdateAnalogOutputs(const InputState &inputs, OutputState &outputs) {
50    // Coordinate calculations to make modifier handling simpler.
51    UpdateDirections(
52        inputs.lf3, // Left
53        inputs.lf1, // Right
54        inputs.lf2, // Down
55        inputs.rf4, // Up
56        inputs.rt3, // C-Left
57        inputs.rt5, // C-Right
58        inputs.rt2, // C-Down
59        inputs.rt4, // C-Up
60        ANALOG_STICK_MIN,
61        ANALOG_STICK_NEUTRAL,
62        ANALOG_STICK_MAX,
63        outputs
64    );
65
66    bool shield_button_pressed = inputs.lf4 || inputs.rf5;
67
68    if (directions.diagonal && directions.y == -1 && _options.crouch_walk_os) {
69        outputs.leftStickX = 128 + (directions.x * 56);
70        outputs.leftStickY = 128 + (directions.y * 55);
71    }
72
73    if (inputs.lt1) {
74        if (directions.horizontal) {
75            outputs.leftStickX = 128 + (directions.x * 53);
76        }
77        if (directions.vertical) {
78            outputs.leftStickY = 128 + (directions.y * 43);
79        }
80
81        // Angled fsmash
82        if (directions.cx != 0) {
83            // 8500 5250 = 68 42
84            outputs.rightStickX = 128 + (directions.cx * 68);
85            outputs.rightStickY = 128 + (directions.y * 42);
86        }
87
88        /* Up B angles */
89        if (directions.diagonal && !shield_button_pressed) {
90            // 22.9638 - 7375 3125 = 59 25
91            outputs.leftStickX = 128 + (directions.x * 59);
92            outputs.leftStickY = 128 + (directions.y * 25);
93            // 27.37104 - 7000 3625 (27.38) = 56 29
94            if (inputs.rt2) {
95                outputs.leftStickX = 128 + (directions.x * 56);
96                outputs.leftStickY = 128 + (directions.y * 29);
97            }
98            // 31.77828 - 7875 4875 (31.76) = 63 39
99            if (inputs.rt3) {
100                outputs.leftStickX = 128 + (directions.x * 63);
101                outputs.leftStickY = 128 + (directions.y * 39);
102            }
103            // 36.18552 - 7000 5125 (36.21) = 56 41
104            if (inputs.rt4) {
105                outputs.leftStickX = 128 + (directions.x * 56);
106                outputs.leftStickY = 128 + (directions.y * 41);
107            }
108            // 40.59276 - 6125 5250 (40.6) = 49 42
109            if (inputs.rt5) {
110                outputs.leftStickX = 128 + (directions.x * 49);
111                outputs.leftStickY = 128 + (directions.y * 42);
112            }
113
114            /* Extended Up B Angles */
115            if (inputs.rf1) {
116                // 22.9638 - 9125 3875 (23.0) = 73 31
117                outputs.leftStickX = 128 + (directions.x * 73);
118                outputs.leftStickY = 128 + (directions.y * 31);
119                // 27.37104 - 8750 4500 (27.2) = 70 36
120                if (inputs.rt2) {
121                    outputs.leftStickX = 128 + (directions.x * 70);
122                    outputs.leftStickY = 128 + (directions.y * 36);
123                }
124                // 31.77828 - 8500 5250 (31.7) = 68 42
125                if (inputs.rt3) {
126                    outputs.leftStickX = 128 + (directions.x * 68);
127                    outputs.leftStickY = 128 + (directions.y * 42);
128                }
129                // 36.18552 - 7375 5375 (36.1) = 59 43
130                if (inputs.rt4) {
131                    outputs.leftStickX = 128 + (directions.x * 59);
132                    outputs.leftStickY = 128 + (directions.y * 43);
133                }
134                // 40.59276 - 6375 5375 (40.1) = 51 43
135                if (inputs.rt5) {
136                    outputs.leftStickX = 128 + (directions.x * 51);
137                    outputs.leftStickY = 128 + (directions.y * 43);
138                }
139            }
140        }
141    }
142
143    if (inputs.lt2) {
144        if (directions.horizontal) {
145            outputs.leftStickX = 128 + (directions.x * 27);
146        }
147        if (directions.vertical) {
148            outputs.leftStickY = 128 + (directions.y * 59);
149        }
150
151        // Turnaround neutral B nerf
152        if (inputs.rf1) {
153            outputs.leftStickX = 128 + (directions.x * 80);
154        }
155
156        /* Up B angles */
157        if (directions.diagonal && !shield_button_pressed) {
158            // 67.0362 - 3125 7375 = 25 59
159            outputs.leftStickX = 128 + (directions.x * 25);
160            outputs.leftStickY = 128 + (directions.y * 59);
161            // 62.62896 - 3625 7000 (62.62) = 29 56
162            if (inputs.rt2) {
163                outputs.leftStickX = 128 + (directions.x * 29);
164                outputs.leftStickY = 128 + (directions.y * 56);
165            }
166            // 58.22172 - 4875 7875 (58.24) = 39 63
167            if (inputs.rt3) {
168                outputs.leftStickX = 128 + (directions.x * 39);
169                outputs.leftStickY = 128 + (directions.y * 63);
170            }
171            // 53.81448 - 5125 7000 (53.79) = 41 56
172            if (inputs.rt4) {
173                outputs.leftStickX = 128 + (directions.x * 41);
174                outputs.leftStickY = 128 + (directions.y * 56);
175            }
176            // 49.40724 - 6375 7625 (50.10) = 51 61
177            if (inputs.rt5) {
178                outputs.leftStickX = 128 + (directions.x * 51);
179                outputs.leftStickY = 128 + (directions.y * 61);
180            }
181
182            /* Extended Up B Angles */
183            if (inputs.rf1) {
184                // 67.0362 - 3875 9125 = 31 73
185                outputs.leftStickX = 128 + (directions.x * 31);
186                outputs.leftStickY = 128 + (directions.y * 73);
187                // 62.62896 - 4500 8750 (62.8) = 36 70
188                if (inputs.rt2) {
189                    outputs.leftStickX = 128 + (directions.x * 36);
190                    outputs.leftStickY = 128 + (directions.y * 70);
191                }
192                // 58.22172 - 5250 8500 (58.3) = 42 68
193                if (inputs.rt3) {
194                    outputs.leftStickX = 128 + (directions.x * 42);
195                    outputs.leftStickY = 128 + (directions.y * 68);
196                }
197                // 53.81448 - 5875 8000 (53.7) = 47 64
198                if (inputs.rt4) {
199                    outputs.leftStickX = 128 + (directions.x * 47);
200                    outputs.leftStickY = 128 + (directions.y * 64);
201                }
202                // 49.40724 - 5875 7125 (50.49) = 47 57
203                if (inputs.rt5) {
204                    outputs.leftStickX = 128 + (directions.x * 47);
205                    outputs.leftStickY = 128 + (directions.y * 57);
206                }
207            }
208        }
209    }
210
211    if (inputs.lf4) {
212        // L overrides modifiers, both for wavedash nerf and so MX/MY can give midshield/lightshield
213        // without forcing shield tilt.
214        if (directions.horizontal) {
215            outputs.leftStickX = 128 + (directions.x * 80);
216            if (directions.y == 1) {
217                outputs.leftStickX = 128 + (directions.x * 43);
218                outputs.leftStickY = 128 + 43;
219            }
220            if (directions.y == -1) {
221                outputs.leftStickX = 128 + (directions.x * 57);
222                outputs.leftStickY = 128 - 55;
223            }
224        }
225        if (directions.vertical) {
226            outputs.leftStickY = 128 + (directions.y * 80);
227        }
228
229        // L + Mod X = midshield
230        if (inputs.lt1) {
231            outputs.triggerLDigital = false;
232            outputs.triggerRAnalog = 94;
233
234            if (directions.diagonal) {
235                outputs.leftStickX = 128 + (directions.x * 51);
236                outputs.leftStickY = 128 + (directions.y * 30);
237            }
238        }
239        // L + Mod Y = lightshield
240        if (inputs.lt2) {
241            outputs.triggerLDigital = false;
242            outputs.triggerRAnalog = 49;
243
244            if (directions.diagonal) {
245                outputs.leftStickX = 128 + (directions.x * 40);
246                outputs.leftStickY = 128 + (directions.y * 68);
247            }
248        }
249    }
250
251    // Holding R gives special shield tilt and wavedash coordinates.
252    if (inputs.rf5) {
253        if (directions.horizontal) {
254            outputs.leftStickX = 128 + (directions.x * 51);
255        }
256        if (directions.vertical) {
257            outputs.leftStickY = 128 + (directions.y * 43);
258        }
259        if (directions.diagonal) {
260            outputs.leftStickX = 128 + (directions.x * 43);
261            if (inputs.lt1) {
262                outputs.leftStickX = 128 + (directions.x * 51);
263                outputs.leftStickY = 128 + (directions.y * 30);
264            }
265            if (inputs.lt2) {
266                outputs.leftStickX = 128 + (directions.x * 40);
267                outputs.leftStickY = 128 + (directions.y * 68);
268            }
269        }
270    }
271
272    // C-stick ASDI Slideoff angle overrides any other C-stick modifiers (such as
273    // angled fsmash).
274    if (directions.cx != 0 && directions.cy != 0) {
275        // 5250 8500 = 42 68
276        outputs.rightStickX = 128 + (directions.cx * 42);
277        outputs.rightStickY = 128 + (directions.cy * 68);
278    }
279
280    // Horizontal SOCD overrides X-axis modifiers (for ledgedash maximum jump
281    // trajectory).
282    if (!inputs.rf5 && horizontal_socd && !directions.vertical) {
283        outputs.leftStickX = 128 + (directions.x * 80);
284    }
285
286    // Shut off C-stick when using D-Pad layer.
287    if ((inputs.lt1 && inputs.lt2) || inputs.nunchuk_c) {
288        outputs.rightStickX = 128;
289        outputs.rightStickY = 128;
290    }
291
292    // Nunchuk overrides left stick.
293    if (inputs.nunchuk_connected) {
294        outputs.leftStickX = inputs.nunchuk_x;
295        outputs.leftStickY = inputs.nunchuk_y;
296    }
297}