fork/GramFirmware

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

Skywalker1127Add files via upload007edc4

WASD_NeutralSOCD
10.4 KiB280 linesraw
1#include "modes/Melee20Button.hpp"
2
3#define ANALOG_STICK_MIN 48
4#define ANALOG_STICK_NEUTRAL 128
5#define ANALOG_STICK_MAX 208
6
7Melee20Button::Melee20Button(socd::SocdType socd_type, Melee20ButtonOptions options) {
8    _socd_pair_count = 4;
9    _socd_pairs = new socd::SocdPair[_socd_pair_count]{
10        socd::SocdPair{&InputState::left,    &InputState::right,   socd_type},
11        socd::SocdPair{ &InputState::down,   &InputState::up,      socd_type},
12        socd::SocdPair{ &InputState::c_left, &InputState::c_right, socd_type},
13        socd::SocdPair{ &InputState::c_down, &InputState::c_up,    socd_type},
14    };
15
16    _options = options;
17    _horizontal_socd = false;
18}
19
20void Melee20Button::HandleSocd(InputState &inputs) {
21    _horizontal_socd = inputs.left && inputs.right;
22    InputMode::HandleSocd(inputs);
23}
24
25void Melee20Button::UpdateDigitalOutputs(InputState &inputs, OutputState &outputs) {
26    outputs.a = inputs.a;
27    outputs.b = inputs.b;
28    outputs.x = inputs.x;
29    outputs.y = inputs.y;
30    outputs.buttonR = inputs.z;
31    if (inputs.nunchuk_connected) {
32        outputs.triggerLDigital = inputs.nunchuk_z;
33    } else {
34        outputs.triggerLDigital = inputs.l;
35    }
36    outputs.triggerRDigital = inputs.r;
37    outputs.start = inputs.start;
38
39    // Activate D-Pad layer by holding Mod X + Mod Y or Nunchuk C button.
40    if ((inputs.mod_x && inputs.mod_y) || inputs.up2) {
41        outputs.dpadUp = inputs.c_up;
42        outputs.dpadDown = inputs.c_down;
43        outputs.dpadLeft = inputs.c_left;
44        outputs.dpadRight = inputs.c_right;
45    }
46
47    if (inputs.select)
48        outputs.dpadLeft = true;
49    if (inputs.home)
50        outputs.dpadRight = true;
51}
52
53void Melee20Button::UpdateAnalogOutputs(InputState &inputs, OutputState &outputs) {
54    // Coordinate calculations to make modifier handling simpler.
55    UpdateDirections(
56        inputs.left,
57        inputs.right,
58        inputs.down,
59        inputs.up,
60        inputs.c_left,
61        inputs.c_right,
62        inputs.c_down,
63        inputs.c_up,
64        ANALOG_STICK_MIN,
65        ANALOG_STICK_NEUTRAL,
66        ANALOG_STICK_MAX,
67        outputs
68    );
69
70    bool shield_button_pressed = inputs.l || inputs.r || inputs.lightshield || inputs.midshield;
71    if (directions.diagonal) {
72        // q1/2 = 7000 7000
73        outputs.leftStickX = 128 + (directions.x * 56);
74        outputs.leftStickY = 128 + (directions.y * 56);
75        // L, R, LS, and MS + q3/4 = 7000 6875 (For vanilla shield drop. Gives 44.5
76        // degree wavedash). Also used as default q3/4 diagonal if crouch walk option select is
77        // enabled.
78        if (directions.y == -1 && (shield_button_pressed || _options.crouch_walk_os)) {
79            outputs.leftStickX = 128 + (directions.x * 56);
80            outputs.leftStickY = 128 + (directions.y * 55);
81        }
82    }
83
84    if (inputs.mod_x) {
85        // MX + Horizontal (even if shield is held) = 6625 = 53
86        if (directions.horizontal) {
87            outputs.leftStickX = 128 + (directions.x * 53);
88        }
89        // MX + Vertical (even if shield is held) = 5375 = 43
90        if (directions.vertical) {
91            outputs.leftStickY = 128 + (directions.y * 43);
92        }
93        if (directions.diagonal && shield_button_pressed) {
94            // MX + L, R, LS, and MS + q1/2/3/4 = 6375 3750 = 51 30
95            outputs.leftStickX = 128 + (directions.x * 51);
96            outputs.leftStickY = 128 + (directions.y * 30);
97        }
98
99        /* Up B angles */
100        if (directions.diagonal && !shield_button_pressed) {
101            // 22.9638 - 7375 3125 = 59 25
102            outputs.leftStickX = 128 + (directions.x * 59);
103            outputs.leftStickY = 128 + (directions.y * 25);
104            // 27.37104 - 7000 3625 (27.38) = 56 29
105            if (inputs.c_down) {
106                outputs.leftStickX = 128 + (directions.x * 56);
107                outputs.leftStickY = 128 + (directions.y * 29);
108            }
109            // 31.77828 - 7875 4875 (31.76) = 63 39
110            if (inputs.c_left) {
111                outputs.leftStickX = 128 + (directions.x * 63);
112                outputs.leftStickY = 128 + (directions.y * 39);
113            }
114            // 36.18552 - 7000 5125 (36.21) = 56 41
115            if (inputs.c_up) {
116                outputs.leftStickX = 128 + (directions.x * 56);
117                outputs.leftStickY = 128 + (directions.y * 41);
118            }
119            // 40.59276 - 6125 5250 (40.6) = 49 42
120            if (inputs.c_right) {
121                outputs.leftStickX = 128 + (directions.x * 49);
122                outputs.leftStickY = 128 + (directions.y * 42);
123            }
124
125            /* Extended Up B Angles */
126            if (inputs.b) {
127                // 22.9638 - 9125 3875 (23.0) = 73 31
128                outputs.leftStickX = 128 + (directions.x * 73);
129                outputs.leftStickY = 128 + (directions.y * 31);
130                // 27.37104 - 8750 4500 (27.2) = 70 36
131                if (inputs.c_down) {
132                    outputs.leftStickX = 128 + (directions.x * 70);
133                    outputs.leftStickY = 128 + (directions.y * 36);
134                }
135                // 31.77828 - 8500 5250 (31.7) = 68 42
136                if (inputs.c_left) {
137                    outputs.leftStickX = 128 + (directions.x * 68);
138                    outputs.leftStickY = 128 + (directions.y * 42);
139                }
140                // 36.18552 - 7375 5375 (36.1) = 59 43
141                if (inputs.c_up) {
142                    outputs.leftStickX = 128 + (directions.x * 59);
143                    outputs.leftStickY = 128 + (directions.y * 43);
144                }
145                // 40.59276 - 6375 5375 (40.1) = 51 43
146                if (inputs.c_right) {
147                    outputs.leftStickX = 128 + (directions.x * 51);
148                    outputs.leftStickY = 128 + (directions.y * 43);
149                }
150            }
151        }
152
153        // Angled fsmash
154        if (directions.cx != 0) {
155            // 8500 5250 = 68 42
156            outputs.rightStickX = 128 + (directions.cx * 68);
157            outputs.rightStickY = 128 + (directions.y * 42);
158        }
159    }
160
161    if (inputs.mod_y) {
162        // MY + Horizontal (even if shield is held) = 3375 = 27
163        if (directions.horizontal) {
164            outputs.leftStickX = 128 + (directions.x * 27);
165        }
166        // MY + Vertical (even if shield is held) = 7375 = 59
167        if (directions.vertical) {
168            outputs.leftStickY = 128 + (directions.y * 59);
169        }
170        if (directions.diagonal && shield_button_pressed) {
171            // MY + L, R, LS, and MS + q1/2 = 4750 8750 = 38 70
172            outputs.leftStickX = 128 + (directions.x * 38);
173            outputs.leftStickY = 128 + (directions.y * 70);
174            // MY + L, R, LS, and MS + q3/4 = 5000 8500 = 40 68
175            if (directions.y == -1) {
176                outputs.leftStickX = 128 + (directions.x * 40);
177                outputs.leftStickY = 128 + (directions.y * 68);
178            }
179        }
180
181        // Turnaround neutral B nerf
182        if (inputs.b) {
183            outputs.leftStickX = 128 + (directions.x * 80);
184        }
185
186        /* Up B angles */
187        if (directions.diagonal && !shield_button_pressed) {
188            // 67.0362 - 3125 7375 = 25 59
189            outputs.leftStickX = 128 + (directions.x * 25);
190            outputs.leftStickY = 128 + (directions.y * 59);
191            // 62.62896 - 3625 7000 (62.62) = 29 56
192            if (inputs.c_down) {
193                outputs.leftStickX = 128 + (directions.x * 29);
194                outputs.leftStickY = 128 + (directions.y * 56);
195            }
196            // 58.22172 - 4875 7875 (58.24) = 39 63
197            if (inputs.c_left) {
198                outputs.leftStickX = 128 + (directions.x * 39);
199                outputs.leftStickY = 128 + (directions.y * 63);
200            }
201            // 53.81448 - 5125 7000 (53.79) = 41 56
202            if (inputs.c_up) {
203                outputs.leftStickX = 128 + (directions.x * 41);
204                outputs.leftStickY = 128 + (directions.y * 56);
205            }
206            // 49.40724 - 6375 7625 (50.10) = 51 61
207            if (inputs.c_right) {
208                outputs.leftStickX = 128 + (directions.x * 51);
209                outputs.leftStickY = 128 + (directions.y * 61);
210            }
211
212            /* Extended Up B Angles */
213            if (inputs.b) {
214                // 67.0362 - 3875 9125 = 31 73
215                outputs.leftStickX = 128 + (directions.x * 31);
216                outputs.leftStickY = 128 + (directions.y * 73);
217                // 62.62896 - 4500 8750 (62.8) = 36 70
218                if (inputs.c_down) {
219                    outputs.leftStickX = 128 + (directions.x * 36);
220                    outputs.leftStickY = 128 + (directions.y * 70);
221                }
222                // 58.22172 - 5250 8500 (58.3) = 42 68
223                if (inputs.c_left) {
224                    outputs.leftStickX = 128 + (directions.x * 42);
225                    outputs.leftStickY = 128 + (directions.y * 68);
226                }
227                // 53.81448 - 5875 8000 (53.7) = 47 64
228                if (inputs.c_up) {
229                    outputs.leftStickX = 128 + (directions.x * 47);
230                    outputs.leftStickY = 128 + (directions.y * 64);
231                }
232                // 49.40724 - 5875 7125 (50.49) = 47 57
233                if (inputs.c_right) {
234                    outputs.leftStickX = 128 + (directions.x * 47);
235                    outputs.leftStickY = 128 + (directions.y * 57);
236                }
237            }
238        }
239    }
240
241    // C-stick ASDI Slideoff angle overrides any other C-stick modifiers (such as
242    // angled fsmash).
243    if (directions.cx != 0 && directions.cy != 0) {
244        // 5250 8500 = 42 68
245        outputs.rightStickX = 128 + (directions.cx * 42);
246        outputs.rightStickY = 128 + (directions.cy * 68);
247    }
248
249    // Horizontal SOCD overrides X-axis modifiers (for ledgedash maximum jump
250    // trajectory).
251    if (_horizontal_socd && !directions.vertical) {
252        outputs.leftStickX = 128 + (directions.x * 80);
253    }
254
255    if (inputs.lightshield) {
256        outputs.triggerRAnalog = 49;
257    }
258    if (inputs.midshield) {
259        outputs.triggerRAnalog = 94;
260    }
261
262    if (outputs.triggerLDigital) {
263        outputs.triggerLAnalog = 140;
264    }
265    if (outputs.triggerRDigital) {
266        outputs.triggerRAnalog = 140;
267    }
268
269    // Shut off C-stick when using D-Pad layer.
270    if ((inputs.mod_x && inputs.mod_y) || inputs.up2) {
271        outputs.rightStickX = 128;
272        outputs.rightStickY = 128;
273    }
274
275    // Nunchuk overrides left stick.
276    if (inputs.nunchuk_connected) {
277        outputs.leftStickX = inputs.nunchuk_x;
278        outputs.leftStickY = inputs.nunchuk_y;
279    }
280}