|
30 | 30 | // in terms of complexity. |
31 | 31 | partial class CoreTests |
32 | 32 | { |
| 33 | + [Test] |
| 34 | + [Category("Actions")] |
| 35 | + public void Actions_WhenShortcutsDisabled_AllConflictingActionsTrigger() |
| 36 | + { |
| 37 | + var keyboard = InputSystem.AddDevice<Keyboard>(); |
| 38 | + |
| 39 | + var map1 = new InputActionMap("map1"); |
| 40 | + var action1 = map1.AddAction(name: "action1"); |
| 41 | + action1.AddCompositeBinding("2DVector") |
| 42 | + .With("Up", "<Keyboard>/w") |
| 43 | + .With("Down", "<Keyboard>/s") |
| 44 | + .With("Left", "<Keyboard>/a") |
| 45 | + .With("Right", "<Keyboard>/d"); |
| 46 | + |
| 47 | + var map2 = new InputActionMap("map2"); |
| 48 | + var action2 = map2.AddAction(name: "action2"); |
| 49 | + action2.AddCompositeBinding("2DVector") |
| 50 | + .With("Up", "<Keyboard>/w") |
| 51 | + .With("Down", "<Keyboard>/s") |
| 52 | + .With("Left", "<Keyboard>/a") |
| 53 | + .With("Right", "<Keyboard>/d"); |
| 54 | + var action3 = map2.AddAction(name: "action3", binding: "<Keyboard>/w"); |
| 55 | + |
| 56 | + map1.Enable(); |
| 57 | + map2.Enable(); |
| 58 | + |
| 59 | + Press(keyboard.wKey); |
| 60 | + |
| 61 | + // All Actions were triggered |
| 62 | + Assert.That(action1.WasPerformedThisFrame()); |
| 63 | + Assert.That(action2.WasPerformedThisFrame()); |
| 64 | + Assert.That(action3.WasPerformedThisFrame()); |
| 65 | + } |
| 66 | + |
33 | 67 | // Premise: Binding the same control multiple times in different ways from multiple concurrently active |
34 | 68 | // actions should result in the input system figuring out which *one* action gets to act on the input. |
35 | 69 | [Test] |
36 | 70 | [Category("Actions")] |
37 | 71 | [TestCase(true)] |
38 | 72 | [TestCase(false)] |
39 | | - public void Actions_CanConsumeInput(bool legacyComposites) |
| 73 | + public void Actions_WhenShortcutsEnabled_CanConsumeInput(bool legacyComposites) |
40 | 74 | { |
| 75 | + InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kDisableShortcutSupport, false); |
| 76 | + |
41 | 77 | var keyboard = InputSystem.AddDevice<Keyboard>(); |
42 | 78 |
|
43 | 79 | var map = new InputActionMap(); |
@@ -124,13 +160,11 @@ public void Actions_CanConsumeInput(bool legacyComposites) |
124 | 160 | Assert.That(!action3.WasPerformedThisFrame()); |
125 | 161 | } |
126 | 162 |
|
127 | | - // For now, maintain a kill switch for the new behavior for users to have an out where the |
128 | | - // the behavior is simply breaking their project. |
129 | 163 | [Test] |
130 | 164 | [Category("Actions")] |
131 | | - public void Actions_CanDisableShortcutSupport() |
| 165 | + public void Actions_ShortcutSupportDisabledByDefault() |
132 | 166 | { |
133 | | - InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kDisableShortcutSupport, true); |
| 167 | + Assert.That(InputSystem.settings.IsFeatureEnabled(InputFeatureNames.kDisableShortcutSupport), Is.True); |
134 | 168 |
|
135 | 169 | var keyboard = InputSystem.AddDevice<Keyboard>(); |
136 | 170 |
|
@@ -216,8 +250,10 @@ public void Actions_CanBindMultipleShortcutSequencesBasedOnSameModifiers() |
216 | 250 | [TestCase("leftShift", "leftAlt", "space", true)] |
217 | 251 | [TestCase("leftShift", null, "space", false)] |
218 | 252 | [TestCase("leftShift", "leftAlt", "space", false)] |
219 | | - public void Actions_PressingShortcutSequenceInWrongOrder_DoesNotTriggerShortcut(string modifier1, string modifier2, string binding, bool legacyComposites) |
| 253 | + public void Actions_WhenShortcutsEnabled_PressingShortcutSequenceInWrongOrder_DoesNotTriggerShortcut(string modifier1, string modifier2, string binding, bool legacyComposites) |
220 | 254 | { |
| 255 | + InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kDisableShortcutSupport, false); |
| 256 | + |
221 | 257 | var keyboard = InputSystem.AddDevice<Keyboard>(); |
222 | 258 |
|
223 | 259 | var action = new InputAction(); |
@@ -292,8 +328,10 @@ public void Actions_PressingShortcutSequenceInWrongOrder_DoesNotTriggerShortcut_ |
292 | 328 |
|
293 | 329 | [Test] |
294 | 330 | [Category("Actions")] |
295 | | - public void Actions_CanHaveShortcutsWithButtonsUsingInitialStateChecks() |
| 331 | + public void Actions_WhenShortcutsAreEnabled_CanHaveShortcutsWithButtonsUsingInitialStateChecks() |
296 | 332 | { |
| 333 | + InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kDisableShortcutSupport, false); |
| 334 | + |
297 | 335 | var keyboard = InputSystem.AddDevice<Keyboard>(); |
298 | 336 |
|
299 | 337 | var map = new InputActionMap(); |
@@ -3052,7 +3090,7 @@ public void Actions_CanRecordActions_AndReadValueAsObject() |
3052 | 3090 | action2.Disable(); |
3053 | 3091 | Set(gamepad.leftTrigger, 0.234f); |
3054 | 3092 |
|
3055 | | - Assert.That(trace, Performed(action2, value: -0.123f).AndThen(Performed(action1, value: 0.123f))); |
| 3093 | + Assert.That(trace, Performed(action1, value: 0.123f).AndThen(Performed(action2, value: -0.123f))); |
3056 | 3094 | } |
3057 | 3095 | } |
3058 | 3096 |
|
@@ -10158,6 +10196,68 @@ public void Actions_WithMultipleCompositeBindings_WithoutEvaluateMagnitude_Works |
10158 | 10196 | Assert.That(values[0].Position, Is.EqualTo(new Vector2(1, 1))); |
10159 | 10197 | } |
10160 | 10198 |
|
| 10199 | + // FIX: This test is currently checking if shortcut support is enabled by testing that the unwanted behaviour exists. |
| 10200 | + // This test should be repurposed once that behaviour is fixed. |
| 10201 | + [Test] |
| 10202 | + [Category("Actions")] |
| 10203 | + [TestCase(true)] |
| 10204 | + [TestCase(false)] |
| 10205 | + public void Actions_ImprovedShortcutSupport_ConsumesWASD(bool shortcutsEnabled) |
| 10206 | + { |
| 10207 | + InputSystem.settings.SetInternalFeatureFlag(InputFeatureNames.kDisableShortcutSupport, !shortcutsEnabled); |
| 10208 | + |
| 10209 | + var keyboard = InputSystem.AddDevice<Keyboard>(); |
| 10210 | + |
| 10211 | + var map1 = new InputActionMap("map1"); |
| 10212 | + var action1 = map1.AddAction(name: "action1"); |
| 10213 | + action1.AddCompositeBinding("2DVector") |
| 10214 | + .With("Up", "<Keyboard>/w") |
| 10215 | + .With("Down", "<Keyboard>/s") |
| 10216 | + .With("Left", "<Keyboard>/a") |
| 10217 | + .With("Right", "<Keyboard>/d"); |
| 10218 | + |
| 10219 | + var map2 = new InputActionMap("map2"); |
| 10220 | + var action2 = map2.AddAction(name: "action2"); |
| 10221 | + action2.AddCompositeBinding("2DVector") |
| 10222 | + .With("Up", "<Keyboard>/w") |
| 10223 | + .With("Down", "<Keyboard>/s") |
| 10224 | + .With("Left", "<Keyboard>/a") |
| 10225 | + .With("Right", "<Keyboard>/d"); |
| 10226 | + var action3 = map2.AddAction(name: "action3", binding: "<Keyboard>/w"); |
| 10227 | + |
| 10228 | + var asset = ScriptableObject.CreateInstance<InputActionAsset>(); |
| 10229 | + asset.AddActionMap(map1); |
| 10230 | + asset.AddActionMap(map2); |
| 10231 | + |
| 10232 | + map1.Enable(); |
| 10233 | + LogAssert.NoUnexpectedReceived(); |
| 10234 | + |
| 10235 | + map2.Enable(); |
| 10236 | + |
| 10237 | + int action1Count = 0; |
| 10238 | + int action2Count = 0; |
| 10239 | + int action3Count = 0; |
| 10240 | + action1.started += ctx => action1Count++; |
| 10241 | + action2.started += ctx => action2Count++; |
| 10242 | + action3.started += ctx => action3Count++; |
| 10243 | + |
| 10244 | + Press(keyboard.wKey); |
| 10245 | + if (shortcutsEnabled) |
| 10246 | + { |
| 10247 | + // First action with the most bindings is the ONLY one to trigger |
| 10248 | + Assert.That(action1Count, Is.EqualTo(1)); |
| 10249 | + Assert.That(action2Count, Is.EqualTo(0)); |
| 10250 | + Assert.That(action3Count, Is.EqualTo(0)); |
| 10251 | + } |
| 10252 | + else |
| 10253 | + { |
| 10254 | + // All actions were triggered |
| 10255 | + Assert.That(action1Count, Is.EqualTo(1)); |
| 10256 | + Assert.That(action2Count, Is.EqualTo(1)); |
| 10257 | + Assert.That(action3Count, Is.EqualTo(1)); |
| 10258 | + } |
| 10259 | + } |
| 10260 | + |
10161 | 10261 | [Test] |
10162 | 10262 | [Category("Actions")] |
10163 | 10263 | [Ignore("TODO")] |
|
0 commit comments