1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +08:00

Store KeyBinding action to its own field in realm

Also improve the Query method for action types by using generic field
This commit is contained in:
Dean Herbert 2021-01-07 16:53:36 +09:00
parent 43f417b53a
commit a77519c6bd
5 changed files with 22 additions and 12 deletions

View File

@ -163,7 +163,7 @@ namespace osu.Game.Database
contexts.Value++; contexts.Value++;
return Realm.GetInstance(new RealmConfiguration(storage.GetFullPath($"{database_name}.realm", true)) return Realm.GetInstance(new RealmConfiguration(storage.GetFullPath($"{database_name}.realm", true))
{ {
SchemaVersion = 2, SchemaVersion = 3,
MigrationCallback = onMigration MigrationCallback = onMigration
}); });
} }

View File

@ -16,17 +16,19 @@ namespace osu.Game.Input.Bindings
public int? Variant { get; set; } public int? Variant { get; set; }
public int Action { get; set; }
public string KeyCombination { get; set; }
[Ignored] [Ignored]
public KeyBinding KeyBinding public KeyBinding KeyBinding
{ {
get get => new KeyBinding(KeyCombination, Action);
set
{ {
var split = KeyBindingString.Split(':'); KeyCombination = value.KeyCombination.ToString();
return new KeyBinding(split[0], int.Parse(split[1])); Action = (int)value.Action;
} }
set => KeyBindingString = $"{value.KeyCombination}:{(int)value.Action}";
} }
public string KeyBindingString { get; set; }
} }
} }

View File

@ -33,7 +33,7 @@ namespace osu.Game.Input
/// Retrieve <see cref="KeyBinding"/>s for the specified action. /// Retrieve <see cref="KeyBinding"/>s for the specified action.
/// </summary> /// </summary>
/// <param name="action">The action to lookup.</param> /// <param name="action">The action to lookup.</param>
List<KeyBinding> Query(GlobalAction action); List<KeyBinding> Query<T>(T action) where T : Enum;
public void Update(KeyBinding buttonKeyBinding) => throw new NotImplementedException(); public void Update(KeyBinding buttonKeyBinding) => throw new NotImplementedException();
} }

View File

@ -52,8 +52,11 @@ namespace osu.Game.Input
public List<KeyBinding> Query(int? rulesetId = null, int? variant = null) public List<KeyBinding> Query(int? rulesetId = null, int? variant = null)
=> query(rulesetId, variant).OfType<KeyBinding>().ToList(); => query(rulesetId, variant).OfType<KeyBinding>().ToList();
public List<KeyBinding> Query(GlobalAction action) public List<KeyBinding> Query<T>(T action) where T : Enum
=> query(null, null).Where(dkb => (GlobalAction)dkb.Action == action).OfType<KeyBinding>().ToList(); {
int lookup = (int)(object)action;
return query(null, null).Where(rkb => (int)rkb.Action == lookup).OfType<KeyBinding>().ToList();
}
private void insertDefaults(IEnumerable<KeyBinding> defaults, int? rulesetId = null, int? variant = null) private void insertDefaults(IEnumerable<KeyBinding> defaults, int? rulesetId = null, int? variant = null)
{ {

View File

@ -93,8 +93,13 @@ namespace osu.Game.Input
public List<KeyBinding> Query(int? rulesetId = null, int? variant = null) public List<KeyBinding> Query(int? rulesetId = null, int? variant = null)
=> query(rulesetId, variant).Select(k => k.KeyBinding).ToList(); => query(rulesetId, variant).Select(k => k.KeyBinding).ToList();
public List<KeyBinding> Query(GlobalAction action) public List<KeyBinding> Query<T>(T action)
=> query(null, null).Where(rkb => rkb.KeyBindingString.StartsWith($"{(int)action}:", StringComparison.Ordinal)).Select(k => k.KeyBinding).ToList(); where T : Enum
{
int lookup = (int)(object)action;
return query(null, null).Where(rkb => rkb.Action == lookup).Select(k => k.KeyBinding).ToList();
}
public void Update(KeyBinding keyBinding) public void Update(KeyBinding keyBinding)
{ {