1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-03 22:02:57 +08:00

Cache and consume IRulesetStore where feasible

This commit is contained in:
Dean Herbert 2021-12-03 18:14:44 +09:00
parent 15db1372aa
commit e75e209053
19 changed files with 40 additions and 28 deletions

View File

@ -20,7 +20,7 @@ namespace osu.Game.Tests.Visual.Menus
private TestToolbar toolbar; private TestToolbar toolbar;
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private IRulesetStore rulesets { get; set; }
[SetUp] [SetUp]
public void SetUp() => Schedule(() => public void SetUp() => Schedule(() =>

View File

@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.Online
} }
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private IRulesetStore rulesets { get; set; }
[Test] [Test]
public void TestMultipleRulesetsBeatmapSet() public void TestMultipleRulesetsBeatmapSet()

View File

@ -30,7 +30,7 @@ namespace osu.Game.Tests.Visual.Online
} }
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private IRulesetStore rulesets { get; set; }
[Test] [Test]
public void TestLoading() public void TestLoading()

View File

@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Online
private TestUserListPanel evast; private TestUserListPanel evast;
[Resolved] [Resolved]
private RulesetStore rulesetStore { get; set; } private IRulesetStore rulesetStore { get; set; }
[SetUp] [SetUp]
public void SetUp() => Schedule(() => public void SetUp() => Schedule(() =>

View File

@ -21,7 +21,7 @@ namespace osu.Game.Tests.Visual.Ranking
public class TestSceneContractedPanelMiddleContent : OsuTestScene public class TestSceneContractedPanelMiddleContent : OsuTestScene
{ {
[Resolved] [Resolved]
private RulesetStore rulesetStore { get; set; } private IRulesetStore rulesetStore { get; set; }
[Test] [Test]
public void TestShowPanel() public void TestShowPanel()

View File

@ -19,7 +19,7 @@ namespace osu.Game.Tournament.Tests.Components
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private IRulesetStore rulesets { get; set; }
private FillFlowContainer<TournamentBeatmapPanel> fillFlow; private FillFlowContainer<TournamentBeatmapPanel> fillFlow;

View File

@ -21,7 +21,7 @@ namespace osu.Game.Tournament.Components
private readonly string modAcronym; private readonly string modAcronym;
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private IRulesetStore rulesets { get; set; }
public TournamentModIcon(string modAcronym) public TournamentModIcon(string modAcronym)
{ {

View File

@ -28,7 +28,7 @@ namespace osu.Game.Tournament.IPC
protected IAPIProvider API { get; private set; } protected IAPIProvider API { get; private set; }
[Resolved] [Resolved]
protected RulesetStore Rulesets { get; private set; } protected IRulesetStore Rulesets { get; private set; }
[Resolved] [Resolved]
private GameHost host { get; set; } private GameHost host { get; set; }

View File

@ -25,7 +25,7 @@ namespace osu.Game.Beatmaps
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private IRulesetStore rulesets { get; set; }
[Resolved] [Resolved]
private Bindable<RulesetInfo> ruleset { get; set; } private Bindable<RulesetInfo> ruleset { get; set; }
@ -35,7 +35,7 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
private int? requestedUserId; private int? requestedUserId;
private readonly Dictionary<RulesetInfo, double> recommendedDifficultyMapping = new Dictionary<RulesetInfo, double>(); private readonly Dictionary<IRulesetInfo, double> recommendedDifficultyMapping = new Dictionary<IRulesetInfo, double>();
private readonly IBindable<APIState> apiState = new Bindable<APIState>(); private readonly IBindable<APIState> apiState = new Bindable<APIState>();
@ -101,7 +101,7 @@ namespace osu.Game.Beatmaps
/// Rulesets ordered descending by their respective recommended difficulties. /// Rulesets ordered descending by their respective recommended difficulties.
/// The currently selected ruleset will always be first. /// The currently selected ruleset will always be first.
/// </returns> /// </returns>
private IEnumerable<RulesetInfo> orderedRulesets private IEnumerable<IRulesetInfo> orderedRulesets
{ {
get get
{ {

View File

@ -86,7 +86,7 @@ namespace osu.Game.Beatmaps.Drawables
} }
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private IRulesetStore rulesets { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)

View File

@ -9,7 +9,7 @@ namespace osu.Game.Online.API.Requests
public class GetUserRequest : APIRequest<APIUser> public class GetUserRequest : APIRequest<APIUser>
{ {
public readonly string Lookup; public readonly string Lookup;
public readonly RulesetInfo Ruleset; public readonly IRulesetInfo Ruleset;
private readonly LookupType lookupType; private readonly LookupType lookupType;
/// <summary> /// <summary>
@ -24,7 +24,7 @@ namespace osu.Game.Online.API.Requests
/// </summary> /// </summary>
/// <param name="userId">The user to get.</param> /// <param name="userId">The user to get.</param>
/// <param name="ruleset">The ruleset to get the user's info for.</param> /// <param name="ruleset">The ruleset to get the user's info for.</param>
public GetUserRequest(long? userId = null, RulesetInfo ruleset = null) public GetUserRequest(long? userId = null, IRulesetInfo ruleset = null)
{ {
Lookup = userId.ToString(); Lookup = userId.ToString();
lookupType = LookupType.Id; lookupType = LookupType.Id;
@ -36,7 +36,7 @@ namespace osu.Game.Online.API.Requests
/// </summary> /// </summary>
/// <param name="username">The user to get.</param> /// <param name="username">The user to get.</param>
/// <param name="ruleset">The ruleset to get the user's info for.</param> /// <param name="ruleset">The ruleset to get the user's info for.</param>
public GetUserRequest(string username = null, RulesetInfo ruleset = null) public GetUserRequest(string username = null, IRulesetInfo ruleset = null)
{ {
Lookup = username; Lookup = username;
lookupType = LookupType.Username; lookupType = LookupType.Username;

View File

@ -94,7 +94,7 @@ namespace osu.Game.Online.Multiplayer
protected IAPIProvider API { get; private set; } = null!; protected IAPIProvider API { get; private set; } = null!;
[Resolved] [Resolved]
protected RulesetStore Rulesets { get; private set; } = null!; protected IRulesetStore Rulesets { get; private set; } = null!;
[Resolved] [Resolved]
private UserLookupCache userLookupCache { get; set; } = null!; private UserLookupCache userLookupCache { get; set; } = null!;
@ -706,6 +706,9 @@ namespace osu.Game.Online.Multiplayer
var apiBeatmap = await GetAPIBeatmap(item.BeatmapID).ConfigureAwait(false); var apiBeatmap = await GetAPIBeatmap(item.BeatmapID).ConfigureAwait(false);
var ruleset = Rulesets.GetRuleset(item.RulesetID); var ruleset = Rulesets.GetRuleset(item.RulesetID);
Debug.Assert(ruleset != null);
var rulesetInstance = ruleset.CreateInstance(); var rulesetInstance = ruleset.CreateInstance();
var playlistItem = new PlaylistItem var playlistItem = new PlaylistItem

View File

@ -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 System.Diagnostics;
using System.Linq; using System.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -79,11 +80,13 @@ namespace osu.Game.Online.Rooms
public void MarkInvalid() => valid.Value = false; public void MarkInvalid() => valid.Value = false;
public void MapObjects(RulesetStore rulesets) public void MapObjects(IRulesetStore rulesets)
{ {
Beatmap.Value ??= apiBeatmap; Beatmap.Value ??= apiBeatmap;
Ruleset.Value ??= rulesets.GetRuleset(RulesetID); Ruleset.Value ??= rulesets.GetRuleset(RulesetID);
Debug.Assert(Ruleset.Value != null);
Ruleset rulesetInstance = Ruleset.Value.CreateInstance(); Ruleset rulesetInstance = Ruleset.Value.CreateInstance();
if (allowedModsBacking != null) if (allowedModsBacking != null)

View File

@ -196,6 +196,7 @@ namespace osu.Game
runMigrations(); runMigrations();
dependencies.Cache(RulesetStore = new RulesetStore(contextFactory, Storage)); dependencies.Cache(RulesetStore = new RulesetStore(contextFactory, Storage));
dependencies.CacheAs<IRulesetStore>(RulesetStore);
dependencies.Cache(realmFactory = new RealmContextFactory(Storage, "client", contextFactory)); dependencies.Cache(realmFactory = new RealmContextFactory(Storage, "client", contextFactory));

View File

@ -47,7 +47,7 @@ namespace osu.Game.Overlays.BeatmapSet
} }
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private IRulesetStore rulesets { get; set; }
private void onRulesetChanged(ValueChangedEvent<IRulesetInfo> ruleset) private void onRulesetChanged(ValueChangedEvent<IRulesetInfo> ruleset)
{ {
@ -57,8 +57,13 @@ namespace osu.Game.Overlays.BeatmapSet
if (ruleset.NewValue == null) if (ruleset.NewValue == null)
return; return;
var rulesetInstance = rulesets.GetRuleset(ruleset.NewValue.OnlineID)?.CreateInstance();
if (rulesetInstance == null)
return;
modsContainer.Add(new ModButton(new ModNoMod())); modsContainer.Add(new ModButton(new ModNoMod()));
modsContainer.AddRange(rulesets.GetRuleset(ruleset.NewValue.OnlineID).CreateInstance().AllMods.Where(m => m.UserPlayable).Select(m => new ModButton(m))); modsContainer.AddRange(rulesetInstance.AllMods.Where(m => m.UserPlayable).Select(m => new ModButton(m)));
modsContainer.ForEach(button => modsContainer.ForEach(button =>
{ {

View File

@ -25,7 +25,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private IRulesetStore rulesets { get; set; }
private readonly APIRecentActivity activity; private readonly APIRecentActivity activity;

View File

@ -28,7 +28,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
private readonly Bindable<Room> joinedRoom = new Bindable<Room>(); private readonly Bindable<Room> joinedRoom = new Bindable<Room>();
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private IRulesetStore rulesets { get; set; }
[Resolved] [Resolved]
private BeatmapManager beatmaps { get; set; } private BeatmapManager beatmaps { get; set; }

View File

@ -35,7 +35,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private IRulesetStore rulesets { get; set; }
private SpriteIcon crown; private SpriteIcon crown;
@ -185,7 +185,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
const double fade_time = 50; const double fade_time = 50;
// Todo: Should use the room's selected item to determine ruleset. // Todo: Should use the room's selected item to determine ruleset.
var ruleset = rulesets.GetRuleset(0).CreateInstance(); var ruleset = rulesets.GetRuleset(0)?.CreateInstance();
int? currentModeRank = User.User?.RulesetsStatistics?.GetValueOrDefault(ruleset.ShortName)?.GlobalRank; int? currentModeRank = User.User?.RulesetsStatistics?.GetValueOrDefault(ruleset.ShortName)?.GlobalRank;
userRankText.Text = currentModeRank != null ? $"#{currentModeRank.Value:N0}" : string.Empty; userRankText.Text = currentModeRank != null ? $"#{currentModeRank.Value:N0}" : string.Empty;

View File

@ -29,9 +29,9 @@ namespace osu.Game.Users
{ {
public IBeatmapInfo BeatmapInfo { get; } public IBeatmapInfo BeatmapInfo { get; }
public RulesetInfo Ruleset { get; } public IRulesetInfo Ruleset { get; }
protected InGame(IBeatmapInfo beatmapInfo, RulesetInfo ruleset) protected InGame(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset)
{ {
BeatmapInfo = beatmapInfo; BeatmapInfo = beatmapInfo;
Ruleset = ruleset; Ruleset = ruleset;
@ -42,7 +42,7 @@ namespace osu.Game.Users
public class InMultiplayerGame : InGame public class InMultiplayerGame : InGame
{ {
public InMultiplayerGame(IBeatmapInfo beatmapInfo, RulesetInfo ruleset) public InMultiplayerGame(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset)
: base(beatmapInfo, ruleset) : base(beatmapInfo, ruleset)
{ {
} }
@ -52,7 +52,7 @@ namespace osu.Game.Users
public class InPlaylistGame : InGame public class InPlaylistGame : InGame
{ {
public InPlaylistGame(IBeatmapInfo beatmapInfo, RulesetInfo ruleset) public InPlaylistGame(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset)
: base(beatmapInfo, ruleset) : base(beatmapInfo, ruleset)
{ {
} }
@ -60,7 +60,7 @@ namespace osu.Game.Users
public class InSoloGame : InGame public class InSoloGame : InGame
{ {
public InSoloGame(IBeatmapInfo beatmapInfo, RulesetInfo ruleset) public InSoloGame(IBeatmapInfo beatmapInfo, IRulesetInfo ruleset)
: base(beatmapInfo, ruleset) : base(beatmapInfo, ruleset)
{ {
} }