mirror of
https://github.com/ppy/osu.git
synced 2025-03-04 04:02:59 +08:00
Cache and consume IRulesetStore
where feasible
This commit is contained in:
parent
15db1372aa
commit
e75e209053
@ -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(() =>
|
||||||
|
@ -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()
|
||||||
|
@ -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()
|
||||||
|
@ -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(() =>
|
||||||
|
@ -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()
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -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; }
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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)
|
||||||
|
@ -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;
|
||||||
|
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -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));
|
||||||
|
|
||||||
|
@ -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 =>
|
||||||
{
|
{
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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; }
|
||||||
|
@ -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;
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user