mirror of
https://github.com/ppy/osu
synced 2024-12-23 23:33:36 +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 transaction = realm.BeginWrite())
|
||||
{
|
||||
realm.Add(new RealmKeyBinding
|
||||
{
|
||||
Action = GlobalAction.Back,
|
||||
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)
|
||||
});
|
||||
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.A)));
|
||||
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.S)));
|
||||
realm.Add(new RealmKeyBinding(GlobalAction.Back, new KeyCombination(InputKey.D)));
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Database;
|
||||
using Realms;
|
||||
@ -14,7 +15,7 @@ namespace osu.Game.Input.Bindings
|
||||
public class RealmKeyBinding : RealmObject, IHasGuidPrimaryKey, IKeyBinding
|
||||
{
|
||||
[PrimaryKey]
|
||||
public Guid ID { get; set; } = Guid.NewGuid();
|
||||
public Guid ID { get; set; }
|
||||
|
||||
public string? RulesetName { get; set; }
|
||||
|
||||
@ -38,6 +39,21 @@ namespace osu.Game.Input.Bindings
|
||||
public int ActionInt { get; set; }
|
||||
|
||||
[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)
|
||||
{
|
||||
// insert any defaults which are missing.
|
||||
realm.Add(defaultsForAction.Skip(existingCount).Select(k => new RealmKeyBinding
|
||||
{
|
||||
KeyCombinationString = k.KeyCombination.ToString(),
|
||||
ActionInt = (int)k.Action,
|
||||
RulesetName = rulesetName,
|
||||
Variant = variant
|
||||
}));
|
||||
realm.Add(defaultsForAction.Skip(existingCount).Select(k => new RealmKeyBinding(k.Action, k.KeyCombination, rulesetName, variant)));
|
||||
}
|
||||
else if (defaultsCount < existingCount)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user