mirror of
https://github.com/ppy/osu.git
synced 2024-09-22 03:27:24 +08:00
Don't query database on keypress
This commit is contained in:
parent
4f392a867a
commit
1a7e23b5c1
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace osu.Game.Input.Bindings
|
namespace osu.Game.Input.Bindings
|
||||||
{
|
{
|
||||||
@ -44,11 +45,15 @@ namespace osu.Game.Input.Bindings
|
|||||||
private void load(KeyBindingStore keyBindings)
|
private void load(KeyBindingStore keyBindings)
|
||||||
{
|
{
|
||||||
store = keyBindings;
|
store = keyBindings;
|
||||||
|
store.KeyBindingChanged += ReloadMappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ReloadMappings()
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
KeyBindings = store.Query(ruleset?.ID, variant);
|
base.Dispose(isDisposing);
|
||||||
|
store.KeyBindingChanged -= ReloadMappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void ReloadMappings() => KeyBindings = store.Query(ruleset?.ID, variant).ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ namespace osu.Game.Input
|
|||||||
{
|
{
|
||||||
public class KeyBindingStore : DatabaseBackedStore
|
public class KeyBindingStore : DatabaseBackedStore
|
||||||
{
|
{
|
||||||
|
public event Action KeyBindingChanged;
|
||||||
|
|
||||||
public KeyBindingStore(Func<OsuDbContext> getContext, RulesetStore rulesets, Storage storage = null)
|
public KeyBindingStore(Func<OsuDbContext> getContext, RulesetStore rulesets, Storage storage = null)
|
||||||
: base(getContext, storage)
|
: base(getContext, storage)
|
||||||
{
|
{
|
||||||
@ -59,7 +61,8 @@ namespace osu.Game.Input
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
context.SaveChanges(transaction);
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +82,8 @@ namespace osu.Game.Input
|
|||||||
var context = GetContext();
|
var context = GetContext();
|
||||||
context.Update(keyBinding);
|
context.Update(keyBinding);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
|
KeyBindingChanged?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user