Input stuff - #4804
Conversation
- ButtonOverrideAdapter -> OverrideAdapter because it isn't just for buttons - ClickyVirtualPadController -> ClickyController because it is not related to the Virtual Pad tool
…d apply for two frames instead of one
…not need to know how to use it fix: Soft/Hard reset menu items did not work if Lua was calling `joypad.set` from `onframestart` event.
…ocumented behavior.
|
I've tested this fix and it works perfectly. My mouse movements no longer override lua script's X/Y positions, and I don't have to manually unbind Touch X and Touch Y whenever I want to run a lua script that does touch inputs. |
| } | ||
|
|
||
| public void SetAnalog(IReadOnlyDictionary<string, int?> controls, int? controller = null) | ||
| public void SetAnalog(IReadOnlyDictionary<string, int> controls, int? controller = null) |
There was a problem hiding this comment.
The implementation looks like it would work with int?, so can you leave the signature as-is until next release? Better yet, have both as overloads and mark the nullable one [Obsolete].
|
|
||
| [LuaMethodExample("joypad.setanalog( { [ \"Tilt X\" ] = -63, [ \"Tilt Y\" ] = 127 } );")] | ||
| [LuaMethod("setanalog", "Sets the given analog controls to their provided values as autoholds. Set axes to the empty string to clear individual holds.")] | ||
| [LuaMethod("setanalog", "Sets the given analog controls to their provided values for the current frame, as if the inputs came from the user. Any analog inputs previously set but missing from the given table will be unset.")] |
There was a problem hiding this comment.
This also needs a deprecation cycle. Might need to resort to renaming it.
There was a problem hiding this comment.
New method could be named set_analog since that's a good name change anyway.
| { | ||
| foreach (var kvp in expected) | ||
| { | ||
| Assert.IsTrue(actual.TryGetValue(kvp.Key, out object value), $"Expected to find key {kvp.Key} but did not."); |
There was a problem hiding this comment.
| Assert.IsTrue(actual.TryGetValue(kvp.Key, out object value), $"Expected to find key {kvp.Key} but did not."); | |
| Assert.IsTrue(actual.TryGetValue(kvp.Key, out var value), $"Expected to find key {kvp.Key} but did not."); |
There was a problem hiding this comment.
var is generally a bad idea, since it provides less information to the reader. Code is easier to read and understand when type names are visible.
This PR changes both
JoypadApi.SetAnalogoverloads, so that they behave similarly to theSetmethods for buttons. This means (1) usingOverrideAdapterinstead of the sticky controller [fixes the Lua issue observed in #4766], (2) changing the way analog values are unset in the dictionary overload is by passing a dictionary without the relevant keys [allowing it to set neutral axis values], and (3) for Lua, throwing an exception if the input value cannot be converted to an int [instead of silently failing].The documentation for the set methods are updated to include "as if the inputs came from the user". This implies that #4769 is indented behavior; auto-fire will obviously work when the button is not otherwise held. Sticky holds and autofires will also interact with buttons held by
joypad.set. But this implication is probably not very obvious and better documentation may still be beneficial. Alternatively, we might want to change the behavior.It also fixes the behavior of the set methods when called from the frame start event, adds tests, and cleans up some code a little bit.
Check if completed: