mirror of
https://github.com/ppy/osu
synced 2024-12-24 15:53:37 +00:00
Avoid constructor overhead for realm RealmKeyBinding
parameterless constructor
This commit is contained in:
parent
6c10531df2
commit
70cc03fe43
@ -63,23 +63,9 @@ namespace osu.Game.Tests.Database
|
|||||||
using (var realm = realmContextFactory.CreateContext())
|
using (var realm = realmContextFactory.CreateContext())
|
||||||
using (var transaction = realm.BeginWrite())
|
using (var transaction = realm.BeginWrite())
|
||||||
{
|
{
|
||||||
realm.Add(new RealmKeyBinding
|
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.A)));
|
||||||
{
|
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.S)));
|
||||||
Action = GlobalAction.Back,
|
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.D)));
|
||||||
KeyCombination = new KeyCombination(InputKey.A)
|
|
||||||
});
|
|
||||||
|
|
||||||
realm.Add(new RealmKeyBinding
|
|
||||||
{
|
|
||||||
Action = GlobalAction.Back,
|
|
||||||
KeyCombination = new KeyCombination(InputKey.S)
|
|
||||||
});
|
|
||||||
|
|
||||||
realm.Add(new RealmKeyBinding
|
|
||||||
{
|
|
||||||
Action = GlobalAction.Back,
|
|
||||||
KeyCombination = new KeyCombination(InputKey.D)
|
|
||||||
});
|
|
||||||
|
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using Realms;
|
using Realms;
|
||||||
@ -14,7 +15,7 @@ namespace osu.Game.Input.Bindings
|
|||||||
public class RealmKeyBinding : RealmObject, IHasGuidPrimaryKey, IKeyBinding
|
public class RealmKeyBinding : RealmObject, IHasGuidPrimaryKey, IKeyBinding
|
||||||
{
|
{
|
||||||
[PrimaryKey]
|
[PrimaryKey]
|
||||||
public Guid ID { get; set; } = Guid.NewGuid();
|
public Guid ID { get; set; }
|
||||||
|
|
||||||
public string? RulesetName { get; set; }
|
public string? RulesetName { get; set; }
|
||||||
|
|
||||||
@ -38,6 +39,21 @@ 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; } = string.Empty;
|
public string KeyCombinationString { get; set; } = null!;
|
||||||
|
|
||||||
|
public RealmKeyBinding(object action, KeyCombination keyCombination, string? rulesetName = null, int? variant = null)
|
||||||
|
{
|
||||||
|
Action = action;
|
||||||
|
KeyCombination = keyCombination;
|
||||||
|
|
||||||
|
RulesetName = rulesetName;
|
||||||
|
Variant = variant;
|
||||||
|
ID = Guid.NewGuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
[UsedImplicitly] // Realm
|
||||||
|
private RealmKeyBinding()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,13 +92,7 @@ namespace osu.Game.Input
|
|||||||
if (defaultsCount > existingCount)
|
if (defaultsCount > existingCount)
|
||||||
{
|
{
|
||||||
// insert any defaults which are missing.
|
// insert any defaults which are missing.
|
||||||
realm.Add(defaultsForAction.Skip(existingCount).Select(k => new RealmKeyBinding
|
realm.Add(defaultsForAction.Skip(existingCount).Select(k => new RealmKeyBinding(k.Action, k.KeyCombination, rulesetName, variant)));
|
||||||
{
|
|
||||||
KeyCombinationString = k.KeyCombination.ToString(),
|
|
||||||
ActionInt = (int)k.Action,
|
|
||||||
RulesetName = rulesetName,
|
|
||||||
Variant = variant
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
else if (defaultsCount < existingCount)
|
else if (defaultsCount < existingCount)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user