mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 19:42:55 +08:00
Rename realm persisted properties to avoid casting necessity
This commit is contained in:
parent
9086d75542
commit
fcb4a53f37
@ -45,8 +45,8 @@ namespace osu.Game.Tests.Database
|
|||||||
|
|
||||||
Assert.That(query().Count, Is.EqualTo(3));
|
Assert.That(query().Count, Is.EqualTo(3));
|
||||||
|
|
||||||
Assert.That(query().Where(k => k.Action == (int)GlobalAction.Back).Count, Is.EqualTo(1));
|
Assert.That(query().Where(k => k.ActionInt == (int)GlobalAction.Back).Count, Is.EqualTo(1));
|
||||||
Assert.That(query().Where(k => k.Action == (int)GlobalAction.Select).Count, Is.EqualTo(2));
|
Assert.That(query().Where(k => k.ActionInt == (int)GlobalAction.Select).Count, Is.EqualTo(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
private IQueryable<RealmKeyBinding> query() => realmContextFactory.Context.All<RealmKeyBinding>();
|
private IQueryable<RealmKeyBinding> query() => realmContextFactory.Context.All<RealmKeyBinding>();
|
||||||
@ -58,22 +58,22 @@ namespace osu.Game.Tests.Database
|
|||||||
|
|
||||||
keyBindingStore.Register(testContainer);
|
keyBindingStore.Register(testContainer);
|
||||||
|
|
||||||
var backBinding = query().Single(k => k.Action == (int)GlobalAction.Back);
|
var backBinding = query().Single(k => k.ActionInt == (int)GlobalAction.Back);
|
||||||
|
|
||||||
Assert.That(((IKeyBinding)backBinding).KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.Escape }));
|
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.Escape }));
|
||||||
|
|
||||||
var binding = backBinding;
|
var binding = backBinding;
|
||||||
|
|
||||||
realmContextFactory.Context.Write(() =>
|
realmContextFactory.Context.Write(() =>
|
||||||
{
|
{
|
||||||
((IKeyBinding)binding).KeyCombination = new KeyCombination(InputKey.BackSpace);
|
binding.KeyCombination = new KeyCombination(InputKey.BackSpace);
|
||||||
});
|
});
|
||||||
|
|
||||||
Assert.That(((IKeyBinding)backBinding).KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.BackSpace }));
|
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.BackSpace }));
|
||||||
|
|
||||||
// check still correct after re-query.
|
// check still correct after re-query.
|
||||||
backBinding = query().Single(k => k.Action == (int)GlobalAction.Back);
|
backBinding = query().Single(k => k.ActionInt == (int)GlobalAction.Back);
|
||||||
Assert.That(((IKeyBinding)backBinding).KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.BackSpace }));
|
Assert.That(backBinding.KeyCombination.Keys, Is.EquivalentTo(new[] { InputKey.BackSpace }));
|
||||||
}
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
|
@ -7,7 +7,7 @@ using Realms;
|
|||||||
|
|
||||||
namespace osu.Game.Input.Bindings
|
namespace osu.Game.Input.Bindings
|
||||||
{
|
{
|
||||||
[MapTo("KeyBinding")]
|
[MapTo(nameof(KeyBinding))]
|
||||||
public class RealmKeyBinding : RealmObject, IHasGuidPrimaryKey, IKeyBinding
|
public class RealmKeyBinding : RealmObject, IHasGuidPrimaryKey, IKeyBinding
|
||||||
{
|
{
|
||||||
[PrimaryKey]
|
[PrimaryKey]
|
||||||
@ -17,20 +17,22 @@ namespace osu.Game.Input.Bindings
|
|||||||
|
|
||||||
public int? Variant { get; set; }
|
public int? Variant { get; set; }
|
||||||
|
|
||||||
KeyCombination IKeyBinding.KeyCombination
|
public KeyCombination KeyCombination
|
||||||
{
|
{
|
||||||
get => KeyCombination;
|
get => KeyCombinationString;
|
||||||
set => KeyCombination = value.ToString();
|
set => KeyCombinationString = value.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
object IKeyBinding.Action
|
public object Action
|
||||||
{
|
{
|
||||||
get => Action;
|
get => ActionInt;
|
||||||
set => Action = (int)value;
|
set => ActionInt = (int)value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Action { get; set; }
|
[MapTo(nameof(Action))]
|
||||||
|
public int ActionInt { get; set; }
|
||||||
|
|
||||||
public string KeyCombination { get; set; }
|
[MapTo(nameof(KeyCombination))]
|
||||||
|
public string KeyCombinationString { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,9 +28,9 @@ namespace osu.Game.Input
|
|||||||
/// <returns>A set of display strings for all the user's key configuration for the action.</returns>
|
/// <returns>A set of display strings for all the user's key configuration for the action.</returns>
|
||||||
public IEnumerable<string> GetReadableKeyCombinationsFor(GlobalAction globalAction)
|
public IEnumerable<string> GetReadableKeyCombinationsFor(GlobalAction globalAction)
|
||||||
{
|
{
|
||||||
foreach (var action in RealmFactory.Context.All<RealmKeyBinding>().Where(b => (GlobalAction)b.Action == globalAction))
|
foreach (var action in RealmFactory.Context.All<RealmKeyBinding>().Where(b => (GlobalAction)b.ActionInt == globalAction))
|
||||||
{
|
{
|
||||||
string str = ((IKeyBinding)action).KeyCombination.ReadableString();
|
string str = action.KeyCombination.ReadableString();
|
||||||
|
|
||||||
// even if found, the readable string may be empty for an unbound action.
|
// even if found, the readable string may be empty for an unbound action.
|
||||||
if (str.Length > 0)
|
if (str.Length > 0)
|
||||||
@ -66,7 +66,7 @@ namespace osu.Game.Input
|
|||||||
// compare counts in database vs defaults
|
// compare counts in database vs defaults
|
||||||
foreach (var group in defaults.GroupBy(k => k.Action))
|
foreach (var group in defaults.GroupBy(k => k.Action))
|
||||||
{
|
{
|
||||||
int count = usage.Context.All<RealmKeyBinding>().Count(k => k.RulesetID == rulesetId && k.Variant == variant && k.Action == (int)group.Key);
|
int count = usage.Context.All<RealmKeyBinding>().Count(k => k.RulesetID == rulesetId && k.Variant == variant && k.ActionInt == (int)group.Key);
|
||||||
int aimCount = group.Count();
|
int aimCount = group.Count();
|
||||||
|
|
||||||
if (aimCount <= count)
|
if (aimCount <= count)
|
||||||
@ -78,8 +78,8 @@ namespace osu.Game.Input
|
|||||||
usage.Context.Add(new RealmKeyBinding
|
usage.Context.Add(new RealmKeyBinding
|
||||||
{
|
{
|
||||||
ID = Guid.NewGuid().ToString(),
|
ID = Guid.NewGuid().ToString(),
|
||||||
KeyCombination = insertable.KeyCombination.ToString(),
|
KeyCombinationString = insertable.KeyCombination.ToString(),
|
||||||
Action = (int)insertable.Action,
|
ActionInt = (int)insertable.Action,
|
||||||
RulesetID = rulesetId,
|
RulesetID = rulesetId,
|
||||||
Variant = variant
|
Variant = variant
|
||||||
});
|
});
|
||||||
|
@ -342,8 +342,8 @@ namespace osu.Game
|
|||||||
realm.Context.Add(new RealmKeyBinding
|
realm.Context.Add(new RealmKeyBinding
|
||||||
{
|
{
|
||||||
ID = Guid.NewGuid().ToString(),
|
ID = Guid.NewGuid().ToString(),
|
||||||
KeyCombination = dkb.KeyCombination.ToString(),
|
KeyCombinationString = dkb.KeyCombination.ToString(),
|
||||||
Action = (int)dkb.Action,
|
ActionInt = (int)dkb.Action,
|
||||||
RulesetID = dkb.RulesetID,
|
RulesetID = dkb.RulesetID,
|
||||||
Variant = dkb.Variant
|
Variant = dkb.Variant
|
||||||
});
|
});
|
||||||
|
@ -53,7 +53,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
private FillFlowContainer cancelAndClearButtons;
|
private FillFlowContainer cancelAndClearButtons;
|
||||||
private FillFlowContainer<KeyButton> buttons;
|
private FillFlowContainer<KeyButton> buttons;
|
||||||
|
|
||||||
public IEnumerable<string> FilterTerms => bindings.Select(b => ((IKeyBinding)b).KeyCombination.ReadableString()).Prepend((string)text.Text);
|
public IEnumerable<string> FilterTerms => bindings.Select(b => b.KeyCombination.ReadableString()).Prepend((string)text.Text);
|
||||||
|
|
||||||
public KeyBindingRow(object action, List<RealmKeyBinding> bindings)
|
public KeyBindingRow(object action, List<RealmKeyBinding> bindings)
|
||||||
{
|
{
|
||||||
@ -132,7 +132,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
using (var write = realmFactory.GetForWrite())
|
using (var write = realmFactory.GetForWrite())
|
||||||
{
|
{
|
||||||
var binding = write.Context.Find<RealmKeyBinding>(((IHasGuidPrimaryKey)button.KeyBinding).ID);
|
var binding = write.Context.Find<RealmKeyBinding>(((IHasGuidPrimaryKey)button.KeyBinding).ID);
|
||||||
binding.KeyCombination = button.KeyBinding.KeyCombination;
|
binding.KeyCombinationString = button.KeyBinding.KeyCombinationString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,7 +295,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
using (var write = realmFactory.GetForWrite())
|
using (var write = realmFactory.GetForWrite())
|
||||||
{
|
{
|
||||||
var binding = write.Context.Find<RealmKeyBinding>(((IHasGuidPrimaryKey)bindTarget.KeyBinding).ID);
|
var binding = write.Context.Find<RealmKeyBinding>(((IHasGuidPrimaryKey)bindTarget.KeyBinding).ID);
|
||||||
binding.KeyCombination = bindTarget.KeyBinding.KeyCombination;
|
binding.KeyCombinationString = bindTarget.KeyBinding.KeyCombinationString;
|
||||||
}
|
}
|
||||||
|
|
||||||
bindTarget.IsBinding = false;
|
bindTarget.IsBinding = false;
|
||||||
@ -429,7 +429,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
Margin = new MarginPadding(5),
|
Margin = new MarginPadding(5),
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Text = ((IKeyBinding)keyBinding).KeyCombination.ReadableString(),
|
Text = keyBinding.KeyCombination.ReadableString(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -468,10 +468,8 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
|
|
||||||
public void UpdateKeyCombination(KeyCombination newCombination)
|
public void UpdateKeyCombination(KeyCombination newCombination)
|
||||||
{
|
{
|
||||||
var keyBinding = (IKeyBinding)KeyBinding;
|
KeyBinding.KeyCombination = newCombination;
|
||||||
|
Text.Text = KeyBinding.KeyCombination.ReadableString();
|
||||||
keyBinding.KeyCombination = newCombination;
|
|
||||||
Text.Text = keyBinding.KeyCombination.ReadableString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
int intKey = (int)defaultGroup.Key;
|
int intKey = (int)defaultGroup.Key;
|
||||||
|
|
||||||
// one row per valid action.
|
// one row per valid action.
|
||||||
Add(new KeyBindingRow(defaultGroup.Key, bindings.Where(b => b.Action.Equals(intKey)).ToList())
|
Add(new KeyBindingRow(defaultGroup.Key, bindings.Where(b => b.ActionInt.Equals(intKey)).ToList())
|
||||||
{
|
{
|
||||||
AllowMainMouseButtons = Ruleset != null,
|
AllowMainMouseButtons = Ruleset != null,
|
||||||
Defaults = defaultGroup.Select(d => d.KeyCombination)
|
Defaults = defaultGroup.Select(d => d.KeyCombination)
|
||||||
|
@ -165,13 +165,13 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
|
|
||||||
if (Hotkey != null)
|
if (Hotkey != null)
|
||||||
{
|
{
|
||||||
realmKeyBinding = realmFactory.Context.All<RealmKeyBinding>().FirstOrDefault(rkb => rkb.RulesetID == null && rkb.Action == (int)Hotkey.Value);
|
realmKeyBinding = realmFactory.Context.All<RealmKeyBinding>().FirstOrDefault(rkb => rkb.RulesetID == null && rkb.ActionInt == (int)Hotkey.Value);
|
||||||
|
|
||||||
if (realmKeyBinding != null)
|
if (realmKeyBinding != null)
|
||||||
{
|
{
|
||||||
realmKeyBinding.PropertyChanged += (sender, args) =>
|
realmKeyBinding.PropertyChanged += (sender, args) =>
|
||||||
{
|
{
|
||||||
if (args.PropertyName == nameof(realmKeyBinding.KeyCombination))
|
if (args.PropertyName == nameof(realmKeyBinding.KeyCombinationString))
|
||||||
updateKeyBindingTooltip();
|
updateKeyBindingTooltip();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -223,7 +223,7 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
{
|
{
|
||||||
if (realmKeyBinding != null)
|
if (realmKeyBinding != null)
|
||||||
{
|
{
|
||||||
KeyCombination? binding = ((IKeyBinding)realmKeyBinding).KeyCombination;
|
KeyCombination? binding = realmKeyBinding.KeyCombination;
|
||||||
|
|
||||||
var keyBindingString = binding?.ReadableString();
|
var keyBindingString = binding?.ReadableString();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user