mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 09:23:06 +08:00
Make key binding update method support all kinds of realm object states
This commit is contained in:
parent
05ca016deb
commit
406e640fa9
@ -87,14 +87,22 @@ namespace osu.Game.Input
|
||||
/// <param name="modification">The modification to apply to the key binding.</param>
|
||||
public void Update(IHasGuidPrimaryKey keyBinding, Action<IKeyBinding> modification)
|
||||
{
|
||||
// the incoming instance could already be a live access object.
|
||||
Live<RealmKeyBinding> realmBinding = keyBinding as Live<RealmKeyBinding>;
|
||||
|
||||
using (var realm = ContextFactory.GetForWrite())
|
||||
{
|
||||
RealmKeyBinding realmBinding = keyBinding as RealmKeyBinding;
|
||||
if (realmBinding == null)
|
||||
{
|
||||
// the incoming instance could be a raw realm object.
|
||||
if (!(keyBinding is RealmKeyBinding rkb))
|
||||
// if neither of the above cases succeeded, retrieve a realm object for further processing.
|
||||
rkb = realm.Context.Find<RealmKeyBinding>(keyBinding.ID);
|
||||
|
||||
if (realmBinding?.IsManaged != true)
|
||||
realmBinding = realm.Context.Find<RealmKeyBinding>(keyBinding.ID);
|
||||
realmBinding = new Live<RealmKeyBinding>(rkb, ContextFactory);
|
||||
}
|
||||
|
||||
modification(realmBinding);
|
||||
realmBinding.PerformUpdate(modification);
|
||||
}
|
||||
|
||||
KeyBindingChanged?.Invoke();
|
||||
|
Loading…
Reference in New Issue
Block a user