mirror of
https://github.com/ppy/osu
synced 2024-12-30 19:02:27 +00:00
Remove unused EF class and unnecessary interface
This commit is contained in:
parent
fc55d67c66
commit
536e7229d0
@ -74,7 +74,7 @@ namespace osu.Game.Tests.Visual
|
||||
typeof(FileStore),
|
||||
typeof(ScoreManager),
|
||||
typeof(BeatmapManager),
|
||||
typeof(IKeyBindingStore),
|
||||
typeof(RealmKeyBindingStore),
|
||||
typeof(SettingsStore),
|
||||
typeof(RulesetConfigCache),
|
||||
typeof(OsuColour),
|
||||
|
@ -21,7 +21,7 @@ namespace osu.Game.Input.Bindings
|
||||
private readonly int? variant;
|
||||
|
||||
[Resolved]
|
||||
private IKeyBindingStore store { get; set; }
|
||||
private RealmKeyBindingStore store { get; set; }
|
||||
|
||||
public override IEnumerable<IKeyBinding> DefaultKeyBindings => ruleset.CreateInstance().GetDefaultKeyBindings(variant ?? 0);
|
||||
|
||||
|
@ -1,41 +0,0 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Input.Bindings;
|
||||
|
||||
namespace osu.Game.Input
|
||||
{
|
||||
public interface IKeyBindingStore
|
||||
{
|
||||
event Action KeyBindingChanged;
|
||||
|
||||
void Register(KeyBindingContainer container);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all user-defined key combinations (in a format that can be displayed) for a specific action.
|
||||
/// </summary>
|
||||
/// <param name="globalAction">The action to lookup.</param>
|
||||
/// <returns>A set of display strings for all the user's key configuration for the action.</returns>
|
||||
IEnumerable<string> GetReadableKeyCombinationsFor(GlobalAction globalAction);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve <see cref="DatabasedKeyBinding"/>s for a specified ruleset/variant content.
|
||||
/// </summary>
|
||||
/// <param name="rulesetId">The ruleset's internal ID.</param>
|
||||
/// <param name="variant">An optional variant.</param>
|
||||
/// <returns></returns>
|
||||
List<IKeyBinding> Query(int? rulesetId = null, int? variant = null);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve <see cref="IKeyBinding"/>s for the specified action.
|
||||
/// </summary>
|
||||
/// <param name="action">The action to lookup.</param>
|
||||
List<IKeyBinding> Query<T>(T action) where T : Enum;
|
||||
|
||||
void Update(IHasGuidPrimaryKey keyBinding, Action<IKeyBinding> modification);
|
||||
}
|
||||
}
|
@ -1,122 +0,0 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Input
|
||||
{
|
||||
public class KeyBindingStore : DatabaseBackedStore, IKeyBindingStore
|
||||
{
|
||||
public event Action KeyBindingChanged;
|
||||
|
||||
public KeyBindingStore(DatabaseContextFactory contextFactory, RulesetStore rulesets, Storage storage = null)
|
||||
: base(contextFactory, storage)
|
||||
{
|
||||
using (ContextFactory.GetForWrite())
|
||||
{
|
||||
foreach (var info in rulesets.AvailableRulesets)
|
||||
{
|
||||
var ruleset = info.CreateInstance();
|
||||
foreach (var variant in ruleset.AvailableVariants)
|
||||
insertDefaults(ruleset.GetDefaultKeyBindings(variant), info.ID, variant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Register(KeyBindingContainer container) => insertDefaults(container.DefaultKeyBindings);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all user-defined key combinations (in a format that can be displayed) for a specific action.
|
||||
/// </summary>
|
||||
/// <param name="globalAction">The action to lookup.</param>
|
||||
/// <returns>A set of display strings for all the user's key configuration for the action.</returns>
|
||||
public IEnumerable<string> GetReadableKeyCombinationsFor(GlobalAction globalAction)
|
||||
{
|
||||
foreach (var action in query().Where(b => (GlobalAction)b.Action == globalAction))
|
||||
{
|
||||
string str = action.KeyCombination.ReadableString();
|
||||
|
||||
// even if found, the readable string may be empty for an unbound action.
|
||||
if (str.Length > 0)
|
||||
yield return str;
|
||||
}
|
||||
}
|
||||
|
||||
public List<IKeyBinding> Query(int? rulesetId = null, int? variant = null)
|
||||
=> query(rulesetId, variant).OfType<IKeyBinding>().ToList();
|
||||
|
||||
public List<IKeyBinding> Query<T>(T action) where T : Enum
|
||||
{
|
||||
int lookup = (int)(object)action;
|
||||
return query(null, null).Where(rkb => (int)rkb.Action == lookup).OfType<IKeyBinding>().ToList();
|
||||
}
|
||||
|
||||
public void Update(IHasGuidPrimaryKey keyBinding, Action<IKeyBinding> modification)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void insertDefaults(IEnumerable<IKeyBinding> defaults, int? rulesetId = null, int? variant = null)
|
||||
{
|
||||
using (var usage = ContextFactory.GetForWrite())
|
||||
{
|
||||
// compare counts in database vs defaults
|
||||
foreach (var group in defaults.GroupBy(k => k.Action))
|
||||
{
|
||||
int count = query(rulesetId, variant).Count(k => (int)k.Action == (int)group.Key);
|
||||
int aimCount = group.Count();
|
||||
|
||||
if (aimCount <= count)
|
||||
continue;
|
||||
|
||||
foreach (var insertable in group.Skip(count).Take(aimCount - count))
|
||||
{
|
||||
// insert any defaults which are missing.
|
||||
usage.Context.DatabasedKeyBinding.Add(new DatabasedKeyBinding
|
||||
{
|
||||
KeyCombination = insertable.KeyCombination,
|
||||
Action = insertable.Action,
|
||||
RulesetID = rulesetId,
|
||||
Variant = variant
|
||||
});
|
||||
|
||||
// required to ensure stable insert order (https://github.com/dotnet/efcore/issues/11686)
|
||||
usage.Context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve <see cref="DatabasedKeyBinding"/>s for a specified ruleset/variant content.
|
||||
/// </summary>
|
||||
/// <param name="rulesetId">The ruleset's internal ID.</param>
|
||||
/// <param name="variant">An optional variant.</param>
|
||||
/// <returns></returns>
|
||||
private List<DatabasedKeyBinding> query(int? rulesetId = null, int? variant = null) =>
|
||||
ContextFactory.Get().DatabasedKeyBinding.Where(b => b.RulesetID == rulesetId && b.Variant == variant).ToList();
|
||||
|
||||
public void Update(DatabasedKeyBinding keyBinding)
|
||||
{
|
||||
using (ContextFactory.GetForWrite())
|
||||
{
|
||||
var dbKeyBinding = keyBinding;
|
||||
Refresh(ref dbKeyBinding);
|
||||
|
||||
if (dbKeyBinding.KeyCombination.Equals(keyBinding.KeyCombination))
|
||||
return;
|
||||
|
||||
dbKeyBinding.KeyCombination = keyBinding.KeyCombination;
|
||||
}
|
||||
|
||||
KeyBindingChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Input
|
||||
{
|
||||
public class RealmKeyBindingStore : RealmBackedStore, IKeyBindingStore
|
||||
public class RealmKeyBindingStore : RealmBackedStore
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired whenever any key binding change occurs, across all rulesets and types.
|
||||
@ -63,8 +63,7 @@ namespace osu.Game.Input
|
||||
/// <param name="rulesetId">An optional ruleset ID. If null, global bindings are returned.</param>
|
||||
/// <param name="variant">An optional ruleset variant. If null, the no-variant bindings are returned.</param>
|
||||
/// <returns>A list of all key bindings found for the query, detached from the database.</returns>
|
||||
public List<IKeyBinding> Query(int? rulesetId = null, int? variant = null)
|
||||
=> query(rulesetId, variant).ToList().Select(r => r.Detach()).ToList<IKeyBinding>();
|
||||
public List<RealmKeyBinding> Query(int? rulesetId = null, int? variant = null) => query(rulesetId, variant).ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve all key bindings for the provided action type.
|
||||
@ -72,12 +71,12 @@ namespace osu.Game.Input
|
||||
/// <param name="action">The action to lookup.</param>
|
||||
/// <typeparam name="T">The enum type of the action.</typeparam>
|
||||
/// <returns>A list of all key bindings found for the query, detached from the database.</returns>
|
||||
public List<IKeyBinding> Query<T>(T action)
|
||||
public List<RealmKeyBinding> Query<T>(T action)
|
||||
where T : Enum
|
||||
{
|
||||
int lookup = (int)(object)action;
|
||||
|
||||
return query(null, null).Where(rkb => rkb.Action == lookup).ToList().Select(r => r.Detach()).ToList<IKeyBinding>();
|
||||
return query(null, null).Where(rkb => rkb.Action == lookup).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -73,7 +73,7 @@ namespace osu.Game
|
||||
|
||||
protected FileStore FileStore;
|
||||
|
||||
protected IKeyBindingStore KeyBindingStore;
|
||||
protected RealmKeyBindingStore KeyBindingStore;
|
||||
|
||||
protected SettingsStore SettingsStore;
|
||||
|
||||
|
@ -67,7 +67,7 @@ namespace osu.Game.Overlays.KeyBinding
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private IKeyBindingStore store { get; set; }
|
||||
private RealmKeyBindingStore store { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
|
@ -32,7 +32,7 @@ namespace osu.Game.Overlays.KeyBinding
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IKeyBindingStore store)
|
||||
private void load(RealmKeyBindingStore store)
|
||||
{
|
||||
var bindings = store.Query(Ruleset?.ID, variant);
|
||||
|
||||
|
@ -75,7 +75,7 @@ namespace osu.Game.Overlays.Toolbar
|
||||
protected FillFlowContainer Flow;
|
||||
|
||||
[Resolved]
|
||||
private IKeyBindingStore keyBindings { get; set; }
|
||||
private RealmKeyBindingStore keyBindings { get; set; }
|
||||
|
||||
protected ToolbarButton()
|
||||
: base(HoverSampleSet.Loud)
|
||||
|
Loading…
Reference in New Issue
Block a user