mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 08:43:01 +08:00
Add IRulesetStore
to allow for transitional usage in upcoming manager classes
This commit is contained in:
parent
7084ef5245
commit
675ecb603f
@ -45,9 +45,9 @@ namespace osu.Game.Tests.Database
|
||||
{
|
||||
var rulesets = new RealmRulesetStore(realmFactory, storage);
|
||||
|
||||
Assert.IsTrue((rulesets.AvailableRulesets.First() as RealmRuleset)?.IsManaged == false);
|
||||
Assert.IsTrue((rulesets.GetRuleset(0) as RealmRuleset)?.IsManaged == false);
|
||||
Assert.IsTrue((rulesets.GetRuleset("mania") as RealmRuleset)?.IsManaged == false);
|
||||
Assert.IsTrue(rulesets.AvailableRulesets.First().IsManaged == false);
|
||||
Assert.IsTrue(rulesets.GetRuleset(0)?.IsManaged == false);
|
||||
Assert.IsTrue(rulesets.GetRuleset("mania")?.IsManaged == false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
31
osu.Game/Rulesets/IRulesetStore.cs
Normal file
31
osu.Game/Rulesets/IRulesetStore.cs
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.Collections.Generic;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace osu.Game.Rulesets
|
||||
{
|
||||
public interface IRulesetStore
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieve a ruleset using a known ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ruleset's internal ID.</param>
|
||||
/// <returns>A ruleset, if available, else null.</returns>
|
||||
IRulesetInfo? GetRuleset(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a ruleset using a known short name.
|
||||
/// </summary>
|
||||
/// <param name="shortName">The ruleset's short name.</param>
|
||||
/// <returns>A ruleset, if available, else null.</returns>
|
||||
IRulesetInfo? GetRuleset(string shortName);
|
||||
|
||||
/// <summary>
|
||||
/// All available rulesets.
|
||||
/// </summary>
|
||||
IEnumerable<IRulesetInfo> AvailableRulesets { get; }
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ using osu.Game.Database;
|
||||
|
||||
namespace osu.Game.Rulesets
|
||||
{
|
||||
public class RulesetStore : DatabaseBackedStore, IDisposable
|
||||
public class RulesetStore : DatabaseBackedStore, IRulesetStore, IDisposable
|
||||
{
|
||||
private const string ruleset_library_prefix = "osu.Game.Rulesets";
|
||||
|
||||
@ -236,5 +236,13 @@ namespace osu.Game.Rulesets
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve -= resolveRulesetDependencyAssembly;
|
||||
}
|
||||
|
||||
#region Implementation of IRulesetStore
|
||||
|
||||
IRulesetInfo IRulesetStore.GetRuleset(int id) => GetRuleset(id);
|
||||
IRulesetInfo IRulesetStore.GetRuleset(string shortName) => GetRuleset(shortName);
|
||||
IEnumerable<IRulesetInfo> IRulesetStore.AvailableRulesets => AvailableRulesets;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Stores
|
||||
{
|
||||
public class RealmRulesetStore : IDisposable
|
||||
public class RealmRulesetStore : IRulesetStore, IDisposable
|
||||
{
|
||||
private readonly RealmContextFactory realmFactory;
|
||||
|
||||
@ -29,9 +29,9 @@ namespace osu.Game.Stores
|
||||
/// <summary>
|
||||
/// All available rulesets.
|
||||
/// </summary>
|
||||
public IEnumerable<IRulesetInfo> AvailableRulesets => availableRulesets;
|
||||
public IEnumerable<RealmRuleset> AvailableRulesets => availableRulesets;
|
||||
|
||||
private readonly List<IRulesetInfo> availableRulesets = new List<IRulesetInfo>();
|
||||
private readonly List<RealmRuleset> availableRulesets = new List<RealmRuleset>();
|
||||
|
||||
public RealmRulesetStore(RealmContextFactory realmFactory, Storage? storage = null)
|
||||
{
|
||||
@ -64,14 +64,14 @@ namespace osu.Game.Stores
|
||||
/// </summary>
|
||||
/// <param name="id">The ruleset's internal ID.</param>
|
||||
/// <returns>A ruleset, if available, else null.</returns>
|
||||
public IRulesetInfo? GetRuleset(int id) => AvailableRulesets.FirstOrDefault(r => r.OnlineID == id);
|
||||
public RealmRuleset? GetRuleset(int id) => AvailableRulesets.FirstOrDefault(r => r.OnlineID == id);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a ruleset using a known short name.
|
||||
/// </summary>
|
||||
/// <param name="shortName">The ruleset's short name.</param>
|
||||
/// <returns>A ruleset, if available, else null.</returns>
|
||||
public IRulesetInfo? GetRuleset(string shortName) => AvailableRulesets.FirstOrDefault(r => r.ShortName == shortName);
|
||||
public RealmRuleset? GetRuleset(string shortName) => AvailableRulesets.FirstOrDefault(r => r.ShortName == shortName);
|
||||
|
||||
private Assembly? resolveRulesetDependencyAssembly(object? sender, ResolveEventArgs args)
|
||||
{
|
||||
@ -258,5 +258,13 @@ namespace osu.Game.Stores
|
||||
{
|
||||
AppDomain.CurrentDomain.AssemblyResolve -= resolveRulesetDependencyAssembly;
|
||||
}
|
||||
|
||||
#region Implementation of IRulesetStore
|
||||
|
||||
IRulesetInfo? IRulesetStore.GetRuleset(int id) => GetRuleset(id);
|
||||
IRulesetInfo? IRulesetStore.GetRuleset(string shortName) => GetRuleset(shortName);
|
||||
IEnumerable<IRulesetInfo> IRulesetStore.AvailableRulesets => AvailableRulesets;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user