mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 12:35:34 +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:
parent
43f417b53a
commit
a77519c6bd
@ -163,7 +163,7 @@ namespace osu.Game.Database
|
||||
contexts.Value++;
|
||||
return Realm.GetInstance(new RealmConfiguration(storage.GetFullPath($"{database_name}.realm", true))
|
||||
{
|
||||
SchemaVersion = 2,
|
||||
SchemaVersion = 3,
|
||||
MigrationCallback = onMigration
|
||||
});
|
||||
}
|
||||
|
@ -16,17 +16,19 @@ namespace osu.Game.Input.Bindings
|
||||
|
||||
public int? Variant { get; set; }
|
||||
|
||||
public int Action { get; set; }
|
||||
|
||||
public string KeyCombination { get; set; }
|
||||
|
||||
[Ignored]
|
||||
public KeyBinding KeyBinding
|
||||
{
|
||||
get
|
||||
get => new KeyBinding(KeyCombination, Action);
|
||||
set
|
||||
{
|
||||
var split = KeyBindingString.Split(':');
|
||||
return new KeyBinding(split[0], int.Parse(split[1]));
|
||||
KeyCombination = value.KeyCombination.ToString();
|
||||
Action = (int)value.Action;
|
||||
}
|
||||
set => KeyBindingString = $"{value.KeyCombination}:{(int)value.Action}";
|
||||
}
|
||||
|
||||
public string KeyBindingString { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ namespace osu.Game.Input
|
||||
/// Retrieve <see cref="KeyBinding"/>s for the specified action.
|
||||
/// </summary>
|
||||
/// <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();
|
||||
}
|
||||
|
@ -52,8 +52,11 @@ namespace osu.Game.Input
|
||||
public List<KeyBinding> Query(int? rulesetId = null, int? variant = null)
|
||||
=> query(rulesetId, variant).OfType<KeyBinding>().ToList();
|
||||
|
||||
public List<KeyBinding> Query(GlobalAction action)
|
||||
=> query(null, null).Where(dkb => (GlobalAction)dkb.Action == action).OfType<KeyBinding>().ToList();
|
||||
public List<KeyBinding> Query<T>(T action) where T : Enum
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -93,8 +93,13 @@ namespace osu.Game.Input
|
||||
public List<KeyBinding> Query(int? rulesetId = null, int? variant = null)
|
||||
=> query(rulesetId, variant).Select(k => k.KeyBinding).ToList();
|
||||
|
||||
public List<KeyBinding> Query(GlobalAction action)
|
||||
=> query(null, null).Where(rkb => rkb.KeyBindingString.StartsWith($"{(int)action}:", StringComparison.Ordinal)).Select(k => k.KeyBinding).ToList();
|
||||
public List<KeyBinding> Query<T>(T action)
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user