Skip to content
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

Clear pre-existing bindings of same key combination to single action #25152

Merged
merged 9 commits into from Oct 17, 2023

Conversation

bdach
Copy link
Collaborator

@bdach bdach commented Oct 16, 2023

This PR enforces the rules set in #25105 backwards to users' existing configs. If duplicate bindings are detected in the user's config, they will receive the following notification once the migration has completed:

osu_2023-10-16_21-32-09

Additionally, to curb funny business like somebody downloading realm studio to edit the db directly, ruleset key binding containers do the key combination uniqueness check separately, and will silently refuse to use key combinations bound to multiple actions. The precedent in behaviour here is #12933.

I am not bothering to do this for GlobalActionContainer because it doesn't feel as important. I will bother to do it if it is deemed important.

@bdach bdach added realm deals with local realm database area:settings labels Oct 16, 2023
@bdach bdach self-assigned this Oct 16, 2023
}

[Test]
public void TestDuplicateBindingsAllowedIfBoundToSameAction()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This test could seem like it's exercising an edge case, except for the part where catch actually would get caught on this:

new KeyBinding(InputKey.Shift, CatchAction.Dash),
new KeyBinding(InputKey.Shift, CatchAction.Dash),

which would cause default dash bindings to become spontaneously completely unbound.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I do wonder if the default for catch should be InputKey.None for the second (to create an extra binding but have no default)...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, but I believe such a change would not apply retroactively to existing configs (unless I specifically include it in the migration I guess).

Copy link
Sponsor Member

@peppy peppy Oct 17, 2023

Choose a reason for hiding this comment

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

This does seem to work on a quick test. Shall we change it while we're here?

diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs
index efd4b46782..63dc01d0d0 100644
--- a/osu.Game.Rulesets.Catch/CatchRuleset.cs
+++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs
@@ -54,7 +54,7 @@ public class CatchRuleset : Ruleset, ILegacyRuleset
             new KeyBinding(InputKey.X, CatchAction.MoveRight),
             new KeyBinding(InputKey.Right, CatchAction.MoveRight),
             new KeyBinding(InputKey.Shift, CatchAction.Dash),
-            new KeyBinding(InputKey.Shift, CatchAction.Dash),
+            new KeyBinding(InputKey.None, CatchAction.Dash),
         };
 
         public override IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods)

Or alternatively,

diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs
index efd4b46782..ee2d3ec2ea 100644
--- a/osu.Game.Rulesets.Catch/CatchRuleset.cs
+++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs
@@ -53,8 +53,8 @@ public class CatchRuleset : Ruleset, ILegacyRuleset
             new KeyBinding(InputKey.Left, CatchAction.MoveLeft),
             new KeyBinding(InputKey.X, CatchAction.MoveRight),
             new KeyBinding(InputKey.Right, CatchAction.MoveRight),
-            new KeyBinding(InputKey.Shift, CatchAction.Dash),
-            new KeyBinding(InputKey.Shift, CatchAction.Dash),
+            new KeyBinding(InputKey.LShift, CatchAction.Dash),
+            new KeyBinding(InputKey.RShift, CatchAction.Dash),
         };
 
         public override IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods)

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

As pointed out on twitch chat, we should likely have the defaults match stable, which would make it:

diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs
index efd4b46782..9ceb78893e 100644
--- a/osu.Game.Rulesets.Catch/CatchRuleset.cs
+++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs
@@ -54,7 +54,7 @@ public class CatchRuleset : Ruleset, ILegacyRuleset
             new KeyBinding(InputKey.X, CatchAction.MoveRight),
             new KeyBinding(InputKey.Right, CatchAction.MoveRight),
             new KeyBinding(InputKey.Shift, CatchAction.Dash),
-            new KeyBinding(InputKey.Shift, CatchAction.Dash),
+            new KeyBinding(InputKey.MouseLeft, CatchAction.Dash),
         };
 
         public override IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods)

I think it's fine to leave your test and logic in place as it's probably not going to harm anything. Up to you.

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've applied the last diff, and also added backwards migration on top (4cfc95c). I initially wasn't gonna bother but not doing so breaks revert-to-default for reasons I'd rather not have to fix so I decided that I might as well migrate over.

Comment on lines +1057 to +1058
Logger.Log($"{countCleared} of your keybinding(s) have been cleared due to being bound to multiple actions. "
+ "Please choose new unique ones in the settings panel.", level: LogLevel.Important);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

LogLevel.Important is a bit of a cheap way to post a notification via the OsuGame logger new entry flow without introducing a dependency on NotificationOverlay.

@peppy peppy self-requested a review October 17, 2023 05:45
Copy link
Sponsor Member

@peppy peppy left a comment

Choose a reason for hiding this comment

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

As commented.

@peppy peppy self-requested a review October 17, 2023 08:16
@peppy peppy enabled auto-merge October 17, 2023 08:17
@peppy peppy disabled auto-merge October 17, 2023 08:49
@peppy peppy merged commit d9fc532 into ppy:master Oct 17, 2023
9 of 11 checks passed
@bdach bdach deleted the key-binding-deduplication branch October 17, 2023 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:settings realm deals with local realm database size/L
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Swells in osu!taiko are cheeseable by binding don and kat to same key
2 participants