mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 08:22:56 +08:00
Merge pull request #15741 from peppy/realm-ruleset-keybinding-short-name
Switch realm ruleset key bindings to use ruleset's `ShortName` as key
This commit is contained in:
commit
5b88e4d7b5
@ -41,8 +41,9 @@ namespace osu.Game.Database
|
|||||||
/// 8 2021-10-29 Rebind scroll adjust keys to not have control modifier.
|
/// 8 2021-10-29 Rebind scroll adjust keys to not have control modifier.
|
||||||
/// 9 2021-11-04 Converted BeatmapMetadata.Author from string to RealmUser.
|
/// 9 2021-11-04 Converted BeatmapMetadata.Author from string to RealmUser.
|
||||||
/// 10 2021-11-22 Use ShortName instead of RulesetID for ruleset settings.
|
/// 10 2021-11-22 Use ShortName instead of RulesetID for ruleset settings.
|
||||||
|
/// 11 2021-11-22 Use ShortName instead of RulesetID for ruleset key bindings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private const int schema_version = 10;
|
private const int schema_version = 11;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking context creation during blocking periods.
|
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking context creation during blocking periods.
|
||||||
@ -265,6 +266,31 @@ namespace osu.Game.Database
|
|||||||
newItem.RulesetName = rulesetName;
|
newItem.RulesetName = rulesetName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 11:
|
||||||
|
string keyBindingClassName = getMappedOrOriginalName(typeof(RealmKeyBinding));
|
||||||
|
|
||||||
|
var oldKeyBindings = migration.OldRealm.DynamicApi.All(keyBindingClassName);
|
||||||
|
var newKeyBindings = migration.NewRealm.All<RealmKeyBinding>().ToList();
|
||||||
|
|
||||||
|
for (int i = 0; i < newKeyBindings.Count; i++)
|
||||||
|
{
|
||||||
|
dynamic? oldItem = oldKeyBindings.ElementAt(i);
|
||||||
|
var newItem = newKeyBindings.ElementAt(i);
|
||||||
|
|
||||||
|
if (oldItem.RulesetID == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
long rulesetId = oldItem.RulesetID;
|
||||||
|
string? rulesetName = getRulesetShortNameFromLegacyID(rulesetId);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(rulesetName))
|
||||||
|
migration.NewRealm.Remove(newItem);
|
||||||
|
else
|
||||||
|
newItem.RulesetName = rulesetName;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,23 +50,20 @@ namespace osu.Game.Input.Bindings
|
|||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
if (ruleset == null || ruleset.ID.HasValue)
|
string rulesetName = ruleset?.ShortName;
|
||||||
{
|
|
||||||
int? rulesetId = ruleset?.ID;
|
|
||||||
|
|
||||||
realmKeyBindings = realmFactory.Context.All<RealmKeyBinding>()
|
realmKeyBindings = realmFactory.Context.All<RealmKeyBinding>()
|
||||||
.Where(b => b.RulesetID == rulesetId && b.Variant == variant);
|
.Where(b => b.RulesetName == rulesetName && b.Variant == variant);
|
||||||
|
|
||||||
realmSubscription = realmKeyBindings
|
realmSubscription = realmKeyBindings
|
||||||
.SubscribeForNotifications((sender, changes, error) =>
|
.SubscribeForNotifications((sender, changes, error) =>
|
||||||
{
|
{
|
||||||
// first subscription ignored as we are handling this in LoadComplete.
|
// first subscription ignored as we are handling this in LoadComplete.
|
||||||
if (changes == null)
|
if (changes == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ReloadMappings();
|
ReloadMappings();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ using osu.Framework.Input.Bindings;
|
|||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using Realms;
|
using Realms;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace osu.Game.Input.Bindings
|
namespace osu.Game.Input.Bindings
|
||||||
{
|
{
|
||||||
[MapTo(nameof(KeyBinding))]
|
[MapTo(nameof(KeyBinding))]
|
||||||
@ -14,7 +16,7 @@ namespace osu.Game.Input.Bindings
|
|||||||
[PrimaryKey]
|
[PrimaryKey]
|
||||||
public Guid ID { get; set; } = Guid.NewGuid();
|
public Guid ID { get; set; } = Guid.NewGuid();
|
||||||
|
|
||||||
public int? RulesetID { get; set; }
|
public string? RulesetName { get; set; }
|
||||||
|
|
||||||
public int? Variant { get; set; }
|
public int? Variant { get; set; }
|
||||||
|
|
||||||
@ -34,6 +36,6 @@ namespace osu.Game.Input.Bindings
|
|||||||
public int ActionInt { get; set; }
|
public int ActionInt { get; set; }
|
||||||
|
|
||||||
[MapTo(nameof(KeyCombination))]
|
[MapTo(nameof(KeyCombination))]
|
||||||
public string KeyCombinationString { get; set; }
|
public string KeyCombinationString { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ namespace osu.Game.Input
|
|||||||
|
|
||||||
using (var context = realmFactory.CreateContext())
|
using (var context = realmFactory.CreateContext())
|
||||||
{
|
{
|
||||||
foreach (var action in context.All<RealmKeyBinding>().Where(b => b.RulesetID == null && (GlobalAction)b.ActionInt == globalAction))
|
foreach (var action in context.All<RealmKeyBinding>().Where(b => string.IsNullOrEmpty(b.RulesetName) && (GlobalAction)b.ActionInt == globalAction))
|
||||||
{
|
{
|
||||||
string str = keyCombinationProvider.GetReadableString(action.KeyCombination);
|
string str = keyCombinationProvider.GetReadableString(action.KeyCombination);
|
||||||
|
|
||||||
@ -69,20 +69,20 @@ namespace osu.Game.Input
|
|||||||
{
|
{
|
||||||
var instance = ruleset.CreateInstance();
|
var instance = ruleset.CreateInstance();
|
||||||
foreach (int variant in instance.AvailableVariants)
|
foreach (int variant in instance.AvailableVariants)
|
||||||
insertDefaults(realm, existingBindings, instance.GetDefaultKeyBindings(variant), ruleset.ID, variant);
|
insertDefaults(realm, existingBindings, instance.GetDefaultKeyBindings(variant), ruleset.ShortName, variant);
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertDefaults(Realm realm, List<RealmKeyBinding> existingBindings, IEnumerable<IKeyBinding> defaults, int? rulesetId = null, int? variant = null)
|
private void insertDefaults(Realm realm, List<RealmKeyBinding> existingBindings, IEnumerable<IKeyBinding> defaults, string? rulesetName = null, int? variant = null)
|
||||||
{
|
{
|
||||||
// compare counts in database vs defaults for each action type.
|
// compare counts in database vs defaults for each action type.
|
||||||
foreach (var defaultsForAction in defaults.GroupBy(k => k.Action))
|
foreach (var defaultsForAction in defaults.GroupBy(k => k.Action))
|
||||||
{
|
{
|
||||||
// avoid performing redundant queries when the database is empty and needs to be re-filled.
|
// avoid performing redundant queries when the database is empty and needs to be re-filled.
|
||||||
int existingCount = existingBindings.Count(k => k.RulesetID == rulesetId && k.Variant == variant && k.ActionInt == (int)defaultsForAction.Key);
|
int existingCount = existingBindings.Count(k => k.RulesetName == rulesetName && k.Variant == variant && k.ActionInt == (int)defaultsForAction.Key);
|
||||||
|
|
||||||
if (defaultsForAction.Count() <= existingCount)
|
if (defaultsForAction.Count() <= existingCount)
|
||||||
continue;
|
continue;
|
||||||
@ -92,7 +92,7 @@ namespace osu.Game.Input
|
|||||||
{
|
{
|
||||||
KeyCombinationString = k.KeyCombination.ToString(),
|
KeyCombinationString = k.KeyCombination.ToString(),
|
||||||
ActionInt = (int)k.Action,
|
ActionInt = (int)k.Action,
|
||||||
RulesetID = rulesetId,
|
RulesetName = rulesetName,
|
||||||
Variant = variant
|
Variant = variant
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -524,7 +524,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
|
|
||||||
public void UpdateKeyCombination(KeyCombination newCombination)
|
public void UpdateKeyCombination(KeyCombination newCombination)
|
||||||
{
|
{
|
||||||
if (KeyBinding.RulesetID != null && !RealmKeyBindingStore.CheckValidForGameplay(newCombination))
|
if (KeyBinding.RulesetName != null && !RealmKeyBindingStore.CheckValidForGameplay(newCombination))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
KeyBinding.KeyCombination = newCombination;
|
KeyBinding.KeyCombination = newCombination;
|
||||||
|
@ -32,12 +32,12 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(RealmContextFactory realmFactory)
|
private void load(RealmContextFactory realmFactory)
|
||||||
{
|
{
|
||||||
int? rulesetId = Ruleset?.ID;
|
string rulesetName = Ruleset?.ShortName;
|
||||||
|
|
||||||
List<RealmKeyBinding> bindings;
|
List<RealmKeyBinding> bindings;
|
||||||
|
|
||||||
using (var realm = realmFactory.CreateContext())
|
using (var realm = realmFactory.CreateContext())
|
||||||
bindings = realm.All<RealmKeyBinding>().Where(b => b.RulesetID == rulesetId && b.Variant == variant).Detach();
|
bindings = realm.All<RealmKeyBinding>().Where(b => b.RulesetName == rulesetName && b.Variant == variant).Detach();
|
||||||
|
|
||||||
foreach (var defaultGroup in Defaults.GroupBy(d => d.Action))
|
foreach (var defaultGroup in Defaults.GroupBy(d => d.Action))
|
||||||
{
|
{
|
||||||
|
@ -207,7 +207,7 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
{
|
{
|
||||||
if (Hotkey == null) return;
|
if (Hotkey == null) return;
|
||||||
|
|
||||||
var realmKeyBinding = realmFactory.Context.All<RealmKeyBinding>().FirstOrDefault(rkb => rkb.RulesetID == null && rkb.ActionInt == (int)Hotkey.Value);
|
var realmKeyBinding = realmFactory.Context.All<RealmKeyBinding>().FirstOrDefault(rkb => rkb.RulesetName == null && rkb.ActionInt == (int)Hotkey.Value);
|
||||||
|
|
||||||
if (realmKeyBinding != null)
|
if (realmKeyBinding != null)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user