Skip to content

Added EvaluateMagnitude override to Vector3Composite to fix issues with callbacks #1763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 5, 2023

Conversation

Secticide
Copy link
Collaborator

@Secticide Secticide commented Oct 2, 2023

Description

Issue tracker: ISXB-251.

When an action is set to Vector3Composite using keyboard keys would result in started and performed callbacks firing but a cancel callback would only fire when losing focus. This doesn't map to what is explained in the documentation.

The issue was caused by InputActionState.IsActuated returning true consistently for Vector3Composite actions. The result when calling trigger.magnitude was always -1 due to Vector3Composite not overriding EvaluateMagnitude (this was already resolved in Vector2Composite).

Changes made

  • Added EvaluateMagnitude override to Vector3Composite.
  • Added new tests for cancel callback for both Vector3Composite & Vector2Composite
  • Modified both Vector3Composite & Vector2Composite to be more consistent

Notes

While changes have been made to Vector3Composite & Vector2Composite for consistency, they are entirely cosmetic.

@Secticide Secticide self-assigned this Oct 2, 2023
Copy link
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, I would consider removing explicit initialization of ints since known to default to zero implicitly in C# but keep the enum initialisation for clarity? Updating CHANGELOG.md to resolve conflict.

@@ -124,7 +124,7 @@ public class Vector2Composite : InputBindingComposite<Vector2>
/// </code>
/// </example>
/// </remarks>
public Mode mode;
public Mode mode = Mode.DigitalNormalized;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a API/behaviorial change (may not be a valid patch) or is it just a case of explicit initialisation? (fine)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I answer my own question, it seems like its not a change since Mode.DigitalNormalized was assigned value zero which would be equivalent to default(Mode), hence this is better in my opinion since explicit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit, I'm a little sad that Vector2Composite and Vector3Composite both have a Mode enum with the same values (although they have been re-ordered for Vector2) and that the mode defaults are different.

But yes, this is just a cosmetic change for explicitness and consistency.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that inconsistency is indeed sad, something to address when a breaking change can be done.

@@ -8057,6 +8057,39 @@ public void Actions_Vector2Composite_RespectsButtonPressurePoint()
Assert.That(value.Value, Is.EqualTo(Vector2.left));
}

[Test]
[Category("Actions")]
public void Actions_Vector2Composite_WithKeyboardKeys_CancelOnRelease()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent to see you've added tests to cover this functionality which seem to have been missing.

@@ -46,7 +46,7 @@ public class Vector3Composite : InputBindingComposite<Vector3>
/// </remarks>
// ReSharper disable once MemberCanBePrivate.Global
// ReSharper disable once FieldCanBeMadeReadOnly.Global
[InputControl(layout = "Axis")] public int up;
[InputControl(layout = "Axis")] public int up = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure these need explicit initialisation since default(int) is known to be zero in C#?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, in that case I'll change the Vector2Composite to remove the explicit initialisation - just noticed some discrepancies in consistency and wanted to clean them up!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in f15b4fe.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you decide what is best, consistency wins, not a big deal either way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change broke the test API_MinorVersionsHaveNoBreakingChanges on my branch.
It took me a while to trace it here because CI on develop and on this branch both seemed to have passed... 😸

@Secticide Secticide force-pushed the ISXB-251-Action-Vector3-Cancel-Fix branch from f15b4fe to d5eadf9 Compare October 3, 2023 13:47
@Secticide Secticide force-pushed the ISXB-251-Action-Vector3-Cancel-Fix branch from d5eadf9 to ce8785f Compare October 4, 2023 10:47
@ekcoh ekcoh requested a review from Pauliusd01 October 4, 2023 12:54
Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I've basically just checked that the bug is fixed with the user repro project.

@Secticide Secticide merged commit adf4c3c into develop Oct 5, 2023
@Secticide Secticide deleted the ISXB-251-Action-Vector3-Cancel-Fix branch October 5, 2023 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants