mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Move score download logic out of ScoreManager
This commit is contained in:
parent
716543b5b3
commit
a2ab9f457d
@ -42,7 +42,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
|
||||
dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory));
|
||||
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
|
||||
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, null, ContextFactory, Scheduler));
|
||||
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, ContextFactory, Scheduler));
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
dependencies.Cache(rulesetStore = new RulesetStore(ContextFactory));
|
||||
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, ContextFactory, rulesetStore, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
|
||||
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, null, ContextFactory, Scheduler));
|
||||
dependencies.Cache(scoreManager = new ScoreManager(rulesetStore, () => beatmapManager, LocalStorage, ContextFactory, Scheduler));
|
||||
|
||||
beatmapInfo = beatmapManager.Import(new ImportTask(TestResources.GetQuickTestBeatmapForImport())).Result.Value.Beatmaps[0];
|
||||
|
||||
|
@ -15,6 +15,9 @@ namespace osu.Game.Online
|
||||
[Resolved(CanBeNull = true)]
|
||||
protected ScoreManager? Manager { get; private set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
protected ScoreModelDownloader? Downloader { get; private set; }
|
||||
|
||||
private ArchiveDownloadRequest<IScoreInfo>? attachedRequest;
|
||||
|
||||
public ScoreDownloadTracker(ScoreInfo trackedItem)
|
||||
@ -25,7 +28,7 @@ namespace osu.Game.Online
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load()
|
||||
{
|
||||
if (Manager == null)
|
||||
if (Manager == null || Downloader == null)
|
||||
return;
|
||||
|
||||
// Used to interact with manager classes that don't support interface types. Will eventually be replaced.
|
||||
@ -38,10 +41,10 @@ namespace osu.Game.Online
|
||||
if (Manager.IsAvailableLocally(scoreInfo))
|
||||
UpdateState(DownloadState.LocallyAvailable);
|
||||
else
|
||||
attachDownload(Manager.GetExistingDownload(scoreInfo));
|
||||
attachDownload(Downloader.GetExistingDownload(scoreInfo));
|
||||
|
||||
Manager.DownloadBegan += downloadBegan;
|
||||
Manager.DownloadFailed += downloadFailed;
|
||||
Downloader.DownloadBegan += downloadBegan;
|
||||
Downloader.DownloadFailed += downloadFailed;
|
||||
Manager.ItemUpdated += itemUpdated;
|
||||
Manager.ItemRemoved += itemRemoved;
|
||||
}
|
||||
@ -119,10 +122,14 @@ namespace osu.Game.Online
|
||||
base.Dispose(isDisposing);
|
||||
attachDownload(null);
|
||||
|
||||
if (Downloader != null)
|
||||
{
|
||||
Downloader.DownloadBegan -= downloadBegan;
|
||||
Downloader.DownloadFailed -= downloadFailed;
|
||||
}
|
||||
|
||||
if (Manager != null)
|
||||
{
|
||||
Manager.DownloadBegan -= downloadBegan;
|
||||
Manager.DownloadFailed -= downloadFailed;
|
||||
Manager.ItemUpdated -= itemUpdated;
|
||||
Manager.ItemRemoved -= itemRemoved;
|
||||
}
|
||||
|
@ -657,6 +657,8 @@ namespace osu.Game
|
||||
BeatmapManager.PostImport = items => PresentBeatmap(items.First().Value);
|
||||
|
||||
BeatmapDownloader.PostNotification = n => Notifications.Post(n);
|
||||
ScoreDownloader.PostNotification = n => Notifications.Post(n);
|
||||
|
||||
ScoreManager.PostNotification = n => Notifications.Post(n);
|
||||
ScoreManager.PostImport = items => PresentScore(items.First().Value);
|
||||
|
||||
|
@ -100,6 +100,8 @@ namespace osu.Game
|
||||
|
||||
protected ScoreManager ScoreManager { get; private set; }
|
||||
|
||||
protected ScoreModelDownloader ScoreDownloader { get; private set; }
|
||||
|
||||
protected SkinManager SkinManager { get; private set; }
|
||||
|
||||
protected RulesetStore RulesetStore { get; private set; }
|
||||
@ -234,10 +236,12 @@ namespace osu.Game
|
||||
dependencies.Cache(fileStore = new FileStore(contextFactory, Storage));
|
||||
|
||||
// ordering is important here to ensure foreign keys rules are not broken in ModelStore.Cleanup()
|
||||
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, API, contextFactory, Scheduler, Host, () => difficultyCache, LocalConfig));
|
||||
dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, contextFactory, Scheduler, Host, () => difficultyCache, LocalConfig));
|
||||
dependencies.Cache(BeatmapManager = new BeatmapManager(Storage, contextFactory, RulesetStore, API, Audio, Resources, Host, defaultBeatmap, performOnlineLookups: true));
|
||||
|
||||
dependencies.Cache(BeatmapDownloader = new BeatmapModelDownloader(BeatmapManager, API, Host));
|
||||
dependencies.Cache(ScoreDownloader = new ScoreModelDownloader(ScoreManager, API, Host));
|
||||
|
||||
// the following realm components are not actively used yet, but initialised and kept up to date for initial testing.
|
||||
realmRulesetStore = new RealmRulesetStore(realmFactory, Storage);
|
||||
|
||||
|
@ -17,7 +17,6 @@ using osu.Game.Configuration;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.IO;
|
||||
using osu.Game.IO.Archives;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
@ -25,15 +24,14 @@ using osu.Game.Rulesets.Scoring;
|
||||
|
||||
namespace osu.Game.Scoring
|
||||
{
|
||||
public class ScoreManager : IModelManager<ScoreInfo>, IModelImporter<ScoreInfo>, IModelDownloader<IScoreInfo>
|
||||
public class ScoreManager : IModelManager<ScoreInfo>, IModelImporter<ScoreInfo>
|
||||
{
|
||||
private readonly Scheduler scheduler;
|
||||
private readonly Func<BeatmapDifficultyCache> difficulties;
|
||||
private readonly OsuConfigManager configManager;
|
||||
private readonly ScoreModelManager scoreModelManager;
|
||||
private readonly ScoreModelDownloader scoreModelDownloader;
|
||||
|
||||
public ScoreManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, IAPIProvider api, IDatabaseContextFactory contextFactory, Scheduler scheduler,
|
||||
public ScoreManager(RulesetStore rulesets, Func<BeatmapManager> beatmaps, Storage storage, IDatabaseContextFactory contextFactory, Scheduler scheduler,
|
||||
IIpcHost importHost = null, Func<BeatmapDifficultyCache> difficulties = null, OsuConfigManager configManager = null)
|
||||
{
|
||||
this.scheduler = scheduler;
|
||||
@ -41,7 +39,6 @@ namespace osu.Game.Scoring
|
||||
this.configManager = configManager;
|
||||
|
||||
scoreModelManager = new ScoreModelManager(rulesets, beatmaps, storage, contextFactory, importHost);
|
||||
scoreModelDownloader = new ScoreModelDownloader(scoreModelManager, api, importHost);
|
||||
}
|
||||
|
||||
public Score GetScore(ScoreInfo score) => scoreModelManager.GetScore(score);
|
||||
@ -240,11 +237,7 @@ namespace osu.Game.Scoring
|
||||
|
||||
public Action<Notification> PostNotification
|
||||
{
|
||||
set
|
||||
{
|
||||
scoreModelManager.PostNotification = value;
|
||||
scoreModelDownloader.PostNotification = value;
|
||||
}
|
||||
set => scoreModelManager.PostNotification = value;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -342,30 +335,6 @@ namespace osu.Game.Scoring
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IModelDownloader<IScoreInfo>
|
||||
|
||||
public event Action<ArchiveDownloadRequest<IScoreInfo>> DownloadBegan
|
||||
{
|
||||
add => scoreModelDownloader.DownloadBegan += value;
|
||||
remove => scoreModelDownloader.DownloadBegan -= value;
|
||||
}
|
||||
|
||||
public event Action<ArchiveDownloadRequest<IScoreInfo>> DownloadFailed
|
||||
{
|
||||
add => scoreModelDownloader.DownloadFailed += value;
|
||||
remove => scoreModelDownloader.DownloadFailed -= value;
|
||||
}
|
||||
|
||||
public bool Download(IScoreInfo model, bool minimiseDownloadSize) =>
|
||||
scoreModelDownloader.Download(model, minimiseDownloadSize);
|
||||
|
||||
public ArchiveDownloadRequest<IScoreInfo> GetExistingDownload(IScoreInfo model)
|
||||
{
|
||||
return scoreModelDownloader.GetExistingDownload(model);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IPresentImports<ScoreInfo>
|
||||
|
||||
public Action<IEnumerable<ILive<ScoreInfo>>> PostImport
|
||||
|
@ -45,7 +45,7 @@ namespace osu.Game.Screens.Ranking
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(OsuGame game, ScoreManager scores)
|
||||
private void load(OsuGame game, ScoreModelDownloader scores)
|
||||
{
|
||||
InternalChild = shakeContainer = new ShakeContainer
|
||||
{
|
||||
@ -65,7 +65,7 @@ namespace osu.Game.Screens.Ranking
|
||||
break;
|
||||
|
||||
case DownloadState.NotDownloaded:
|
||||
scores.Download(Score.Value, false);
|
||||
scores.Download(Score.Value);
|
||||
break;
|
||||
|
||||
case DownloadState.Importing:
|
||||
|
Loading…
Reference in New Issue
Block a user