diff --git a/osu.Game.Tests/Online/TestSceneBeatmapManager.cs b/osu.Game.Tests/Online/TestSceneBeatmapDownloading.cs similarity index 94% rename from osu.Game.Tests/Online/TestSceneBeatmapManager.cs rename to osu.Game.Tests/Online/TestSceneBeatmapDownloading.cs index fc1b4f224d..4e77973655 100644 --- a/osu.Game.Tests/Online/TestSceneBeatmapManager.cs +++ b/osu.Game.Tests/Online/TestSceneBeatmapDownloading.cs @@ -12,9 +12,9 @@ using osu.Game.Tests.Visual; namespace osu.Game.Tests.Online { [HeadlessTest] - public class TestSceneBeatmapManager : OsuTestScene + public class TestSceneBeatmapDownloading : OsuTestScene { - private BeatmapManager beatmaps; + private BeatmapModelDownloader beatmaps; private ProgressNotification recentNotification; private static readonly BeatmapSetInfo test_db_model = new BeatmapSetInfo @@ -43,7 +43,7 @@ namespace osu.Game.Tests.Online }; [BackgroundDependencyLoader] - private void load(BeatmapManager beatmaps) + private void load(BeatmapModelDownloader beatmaps) { this.beatmaps = beatmaps; diff --git a/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs b/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs index a4c69075be..f5d57240ca 100644 --- a/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs +++ b/osu.Game.Tests/Online/TestSceneOnlinePlayBeatmapAvailabilityTracker.cs @@ -33,6 +33,7 @@ namespace osu.Game.Tests.Online { private RulesetStore rulesets; private TestBeatmapManager beatmaps; + private TestBeatmapModelDownloader beatmapDownloader; private string testBeatmapFile; private BeatmapInfo testBeatmapInfo; @@ -46,6 +47,7 @@ namespace osu.Game.Tests.Online { Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.CacheAs(beatmaps = new TestBeatmapManager(LocalStorage, ContextFactory, rulesets, API, audio, Resources, host, Beatmap.Default)); + Dependencies.CacheAs(beatmapDownloader = new TestBeatmapModelDownloader(beatmaps, API, host)); } [SetUp] @@ -80,13 +82,13 @@ namespace osu.Game.Tests.Online AddAssert("ensure beatmap unavailable", () => !beatmaps.IsAvailableLocally(testBeatmapSet)); addAvailabilityCheckStep("state not downloaded", BeatmapAvailability.NotDownloaded); - AddStep("start downloading", () => beatmaps.Download(testBeatmapSet)); + AddStep("start downloading", () => beatmapDownloader.Download(testBeatmapSet)); addAvailabilityCheckStep("state downloading 0%", () => BeatmapAvailability.Downloading(0.0f)); - AddStep("set progress 40%", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).SetProgress(0.4f)); + AddStep("set progress 40%", () => ((TestDownloadRequest)beatmapDownloader.GetExistingDownload(testBeatmapSet)).SetProgress(0.4f)); addAvailabilityCheckStep("state downloading 40%", () => BeatmapAvailability.Downloading(0.4f)); - AddStep("finish download", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).TriggerSuccess(testBeatmapFile)); + AddStep("finish download", () => ((TestDownloadRequest)beatmapDownloader.GetExistingDownload(testBeatmapSet)).TriggerSuccess(testBeatmapFile)); addAvailabilityCheckStep("state importing", BeatmapAvailability.Importing); AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true)); @@ -171,22 +173,6 @@ namespace osu.Game.Tests.Online return new TestBeatmapModelManager(this, storage, contextFactory, rulesets, api, host); } - protected override BeatmapModelDownloader CreateBeatmapModelDownloader(IModelImporter manager, IAPIProvider api, GameHost host) - { - return new TestBeatmapModelDownloader(manager, api, host); - } - - internal class TestBeatmapModelDownloader : BeatmapModelDownloader - { - public TestBeatmapModelDownloader(IModelImporter importer, IAPIProvider apiProvider, GameHost gameHost) - : base(importer, apiProvider, gameHost) - { - } - - protected override ArchiveDownloadRequest CreateDownloadRequest(IBeatmapSetInfo set, bool minimiseDownloadSize) - => new TestDownloadRequest(set); - } - internal class TestBeatmapModelManager : BeatmapModelManager { private readonly TestBeatmapManager testBeatmapManager; @@ -205,6 +191,17 @@ namespace osu.Game.Tests.Online } } + internal class TestBeatmapModelDownloader : BeatmapModelDownloader + { + public TestBeatmapModelDownloader(IModelImporter importer, IAPIProvider apiProvider, GameHost gameHost) + : base(importer, apiProvider, gameHost) + { + } + + protected override ArchiveDownloadRequest CreateDownloadRequest(IBeatmapSetInfo set, bool minimiseDownloadSize) + => new TestDownloadRequest(set); + } + private class TestDownloadRequest : ArchiveDownloadRequest { public new void SetProgress(float progress) => base.SetProgress(progress); diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 0594cd1316..179d479b53 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -29,12 +29,11 @@ namespace osu.Game.Beatmaps /// Handles general operations related to global beatmap management. /// [ExcludeFromDynamicCompile] - public class BeatmapManager : IModelDownloader, IModelManager, IModelFileManager, IModelImporter, IWorkingBeatmapCache, IDisposable + public class BeatmapManager : IModelManager, IModelFileManager, IModelImporter, IWorkingBeatmapCache, IDisposable { public ITrackStore BeatmapTrackStore { get; } private readonly BeatmapModelManager beatmapModelManager; - private readonly BeatmapModelDownloader beatmapModelDownloader; private readonly WorkingBeatmapCache workingBeatmapCache; private readonly BeatmapOnlineLookupQueue onlineBeatmapLookupQueue; @@ -46,7 +45,6 @@ namespace osu.Game.Beatmaps BeatmapTrackStore = audioManager.GetTrackStore(userResources); beatmapModelManager = CreateBeatmapModelManager(storage, contextFactory, rulesets, api, host); - beatmapModelDownloader = CreateBeatmapModelDownloader(beatmapModelManager, api, host); workingBeatmapCache = CreateWorkingBeatmapCache(audioManager, gameResources, userResources, defaultBeatmap, host); workingBeatmapCache.BeatmapManager = beatmapModelManager; @@ -59,11 +57,6 @@ namespace osu.Game.Beatmaps } } - protected virtual BeatmapModelDownloader CreateBeatmapModelDownloader(IModelImporter modelManager, IAPIProvider api, GameHost host) - { - return new BeatmapModelDownloader(modelManager, api, host); - } - protected virtual WorkingBeatmapCache CreateWorkingBeatmapCache(AudioManager audioManager, IResourceStore resources, IResourceStore storage, WorkingBeatmap defaultBeatmap, GameHost host) { return new WorkingBeatmapCache(BeatmapTrackStore, audioManager, resources, storage, defaultBeatmap, host); @@ -185,11 +178,7 @@ namespace osu.Game.Beatmaps /// public Action PostNotification { - set - { - beatmapModelManager.PostNotification = value; - beatmapModelDownloader.PostNotification = value; - } + set => beatmapModelManager.PostNotification = value; } /// @@ -267,28 +256,6 @@ namespace osu.Game.Beatmaps #endregion - #region Implementation of IModelDownloader - - public event Action> DownloadBegan - { - add => beatmapModelDownloader.DownloadBegan += value; - remove => beatmapModelDownloader.DownloadBegan -= value; - } - - public event Action> DownloadFailed - { - add => beatmapModelDownloader.DownloadFailed += value; - remove => beatmapModelDownloader.DownloadFailed -= value; - } - - public bool Download(IBeatmapSetInfo model, bool minimiseDownloadSize = false) => - beatmapModelDownloader.Download(model, minimiseDownloadSize); - - public ArchiveDownloadRequest GetExistingDownload(IBeatmapSetInfo model) => - beatmapModelDownloader.GetExistingDownload(model); - - #endregion - #region Implementation of ICanAcceptFiles public Task Import(params string[] paths) diff --git a/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs b/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs index 7430fce1c8..1a514c8d36 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/Buttons/DownloadButton.cs @@ -24,7 +24,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons private Bindable preferNoVideo = null!; [Resolved] - private BeatmapManager beatmaps { get; set; } = null!; + private BeatmapModelDownloader beatmaps { get; set; } = null!; public DownloadButton(APIBeatmapSet beatmapSet) { diff --git a/osu.Game/Online/BeatmapDownloadTracker.cs b/osu.Game/Online/BeatmapDownloadTracker.cs index 77a8fca1e4..509d5c1b71 100644 --- a/osu.Game/Online/BeatmapDownloadTracker.cs +++ b/osu.Game/Online/BeatmapDownloadTracker.cs @@ -15,6 +15,9 @@ namespace osu.Game.Online [Resolved(CanBeNull = true)] protected BeatmapManager? Manager { get; private set; } + [Resolved(CanBeNull = true)] + protected BeatmapModelDownloader? Downloader { get; private set; } + private ArchiveDownloadRequest? attachedRequest; public BeatmapDownloadTracker(IBeatmapSetInfo 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. @@ -34,10 +37,10 @@ namespace osu.Game.Online if (Manager.IsAvailableLocally(beatmapSetInfo)) UpdateState(DownloadState.LocallyAvailable); else - attachDownload(Manager.GetExistingDownload(beatmapSetInfo)); + attachDownload(Downloader.GetExistingDownload(beatmapSetInfo)); - Manager.DownloadBegan += downloadBegan; - Manager.DownloadFailed += downloadFailed; + Downloader.DownloadBegan += downloadBegan; + Downloader.DownloadFailed += downloadFailed; Manager.ItemUpdated += itemUpdated; Manager.ItemRemoved += itemRemoved; } @@ -115,10 +118,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; } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 574a5e5393..1060724680 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -656,6 +656,7 @@ namespace osu.Game BeatmapManager.PostNotification = n => Notifications.Post(n); BeatmapManager.PostImport = items => PresentBeatmap(items.First().Value); + BeatmapDownloader.PostNotification = n => Notifications.Post(n); ScoreManager.PostNotification = n => Notifications.Post(n); ScoreManager.PostImport = items => PresentScore(items.First().Value); diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index dd4ae590c7..a64d9ac01a 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -96,6 +96,8 @@ namespace osu.Game protected BeatmapManager BeatmapManager { get; private set; } + protected BeatmapModelDownloader BeatmapDownloader { get; private set; } + protected ScoreManager ScoreManager { get; private set; } protected SkinManager SkinManager { get; private set; } @@ -235,6 +237,7 @@ namespace osu.Game dependencies.Cache(ScoreManager = new ScoreManager(RulesetStore, () => BeatmapManager, Storage, API, 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)); // the following realm components are not actively used yet, but initialised and kept up to date for initial testing. realmRulesetStore = new RealmRulesetStore(realmFactory, Storage); diff --git a/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs b/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs index 1282a14c3d..0a66c3ccb7 100644 --- a/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs +++ b/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs @@ -65,7 +65,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels } [BackgroundDependencyLoader(true)] - private void load(OsuGame game, BeatmapManager beatmaps, OsuConfigManager osuConfig) + private void load(OsuGame game, BeatmapModelDownloader beatmaps, OsuConfigManager osuConfig) { noVideoSetting = osuConfig.GetBindable(OsuSetting.PreferNoVideo); diff --git a/osu.Game/Overlays/BeatmapSet/Buttons/HeaderDownloadButton.cs b/osu.Game/Overlays/BeatmapSet/Buttons/HeaderDownloadButton.cs index ee40f114d2..4eed8f28f2 100644 --- a/osu.Game/Overlays/BeatmapSet/Buttons/HeaderDownloadButton.cs +++ b/osu.Game/Overlays/BeatmapSet/Buttons/HeaderDownloadButton.cs @@ -51,7 +51,7 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons } [BackgroundDependencyLoader] - private void load(IAPIProvider api, BeatmapManager beatmaps) + private void load(IAPIProvider api, BeatmapModelDownloader beatmaps) { FillFlowContainer textSprites; diff --git a/osu.Game/Screens/Play/SoloSpectator.cs b/osu.Game/Screens/Play/SoloSpectator.cs index c65d4af2ae..5ecdb91718 100644 --- a/osu.Game/Screens/Play/SoloSpectator.cs +++ b/osu.Game/Screens/Play/SoloSpectator.cs @@ -49,6 +49,9 @@ namespace osu.Game.Screens.Play [Resolved] private BeatmapManager beatmaps { get; set; } + [Resolved] + private BeatmapModelDownloader beatmapDownloader { get; set; } + private Container beatmapPanelContainer; private TriangleButton watchButton; private SettingsCheckbox automaticDownload; @@ -244,7 +247,7 @@ namespace osu.Game.Screens.Play if (beatmaps.IsAvailableLocally(new BeatmapSetInfo { OnlineID = beatmapSet.OnlineID })) return; - beatmaps.Download(beatmapSet); + beatmapDownloader.Download(beatmapSet); } public override bool OnExiting(IScreen next)