mirror of
https://github.com/ppy/osu
synced 2025-01-10 16:19:47 +00:00
Fix download buttons not finding existing downloads and already… (#5171)
Fix download buttons not finding existing downloads and already downloaded maps Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
e0fb547bb3
@ -3,11 +3,15 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Online;
|
||||||
using osu.Game.Overlays.Direct;
|
using osu.Game.Overlays.Direct;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Tests.Resources;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Online
|
namespace osu.Game.Tests.Visual.Online
|
||||||
@ -21,6 +25,9 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
|
|
||||||
private TestDownloadButton downloadButton;
|
private TestDownloadButton downloadButton;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private BeatmapManager beatmaps { get; set; }
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDownloadableBeatmap()
|
public void TestDownloadableBeatmap()
|
||||||
{
|
{
|
||||||
@ -35,11 +42,66 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
assertEnabled(false);
|
assertEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDownloadState()
|
||||||
|
{
|
||||||
|
AddUntilStep("ensure manager loaded", () => beatmaps != null);
|
||||||
|
ensureSoleilyRemoved();
|
||||||
|
createButtonWithBeatmap(createSoleily());
|
||||||
|
AddAssert("button state not downloaded", () => downloadButton.DownloadState == DownloadState.NotDownloaded);
|
||||||
|
AddStep("import soleily", () => beatmaps.Import(new[] { TestResources.GetTestBeatmapForImport() }));
|
||||||
|
AddUntilStep("wait for beatmap import", () => beatmaps.GetAllUsableBeatmapSets().Any(b => b.OnlineBeatmapSetID == 241526));
|
||||||
|
createButtonWithBeatmap(createSoleily());
|
||||||
|
AddAssert("button state downloaded", () => downloadButton.DownloadState == DownloadState.LocallyAvailable);
|
||||||
|
ensureSoleilyRemoved();
|
||||||
|
AddAssert("button state not downloaded", () => downloadButton.DownloadState == DownloadState.NotDownloaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureSoleilyRemoved()
|
||||||
|
{
|
||||||
|
AddStep("remove soleily", () =>
|
||||||
|
{
|
||||||
|
var beatmap = beatmaps.QueryBeatmapSet(b => b.OnlineBeatmapSetID == 241526);
|
||||||
|
|
||||||
|
if (beatmap != null) beatmaps.Delete(beatmap);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void assertEnabled(bool enabled)
|
private void assertEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
AddAssert($"button {(enabled ? "enabled" : "disabled")}", () => downloadButton.DownloadEnabled == enabled);
|
AddAssert($"button {(enabled ? "enabled" : "disabled")}", () => downloadButton.DownloadEnabled == enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BeatmapSetInfo createSoleily()
|
||||||
|
{
|
||||||
|
return new BeatmapSetInfo
|
||||||
|
{
|
||||||
|
ID = 1,
|
||||||
|
OnlineBeatmapSetID = 241526,
|
||||||
|
OnlineInfo = new BeatmapSetOnlineInfo
|
||||||
|
{
|
||||||
|
Availability = new BeatmapSetOnlineAvailability
|
||||||
|
{
|
||||||
|
DownloadDisabled = false,
|
||||||
|
ExternalLink = string.Empty,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createButtonWithBeatmap(BeatmapSetInfo beatmap)
|
||||||
|
{
|
||||||
|
AddStep("create button", () =>
|
||||||
|
{
|
||||||
|
Child = downloadButton = new TestDownloadButton(beatmap)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Size = new Vector2(75, 50),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void createButton(bool downloadable)
|
private void createButton(bool downloadable)
|
||||||
{
|
{
|
||||||
AddStep("create button", () =>
|
AddStep("create button", () =>
|
||||||
@ -85,6 +147,8 @@ namespace osu.Game.Tests.Visual.Online
|
|||||||
{
|
{
|
||||||
public new bool DownloadEnabled => base.DownloadEnabled;
|
public new bool DownloadEnabled => base.DownloadEnabled;
|
||||||
|
|
||||||
|
public DownloadState DownloadState => State.Value;
|
||||||
|
|
||||||
public TestDownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
|
public TestDownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
|
||||||
: base(beatmapSet, noVideo)
|
: base(beatmapSet, noVideo)
|
||||||
{
|
{
|
||||||
|
@ -145,6 +145,8 @@ namespace osu.Game.Beatmaps
|
|||||||
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.OnlineBeatmapID = null);
|
void resetIds() => beatmapSet.Beatmaps.ForEach(b => b.OnlineBeatmapID = null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override bool CheckLocalAvailability(BeatmapSetInfo model, IQueryable<BeatmapSetInfo> items) => items.Any(b => b.OnlineBeatmapSetID == model.OnlineBeatmapSetID);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete a beatmap difficulty.
|
/// Delete a beatmap difficulty.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -20,7 +20,7 @@ namespace osu.Game.Database
|
|||||||
/// <typeparam name="TModel">The model type.</typeparam>
|
/// <typeparam name="TModel">The model type.</typeparam>
|
||||||
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
|
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
|
||||||
public abstract class DownloadableArchiveModelManager<TModel, TFileModel> : ArchiveModelManager<TModel, TFileModel>, IModelDownloader<TModel>
|
public abstract class DownloadableArchiveModelManager<TModel, TFileModel> : ArchiveModelManager<TModel, TFileModel>, IModelDownloader<TModel>
|
||||||
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
|
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete, IEquatable<TModel>
|
||||||
where TFileModel : INamedFileInfo, new()
|
where TFileModel : INamedFileInfo, new()
|
||||||
{
|
{
|
||||||
public event Action<ArchiveDownloadRequest<TModel>> DownloadBegan;
|
public event Action<ArchiveDownloadRequest<TModel>> DownloadBegan;
|
||||||
@ -110,7 +110,15 @@ namespace osu.Game.Database
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool IsAvailableLocally(TModel model) => modelStore.ConsumableItems.Any(m => m.Equals(model) && !m.DeletePending);
|
public bool IsAvailableLocally(TModel model) => CheckLocalAvailability(model, modelStore.ConsumableItems.Where(m => !m.DeletePending));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs implementation specific comparisons to determine whether a given model is present in the local store.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">The <see cref="TModel"/> whose existence needs to be checked.</param>
|
||||||
|
/// <param name="items">The usable items present in the store.</param>
|
||||||
|
/// <returns>Whether the <see cref="TModel"/> exists.</returns>
|
||||||
|
protected abstract bool CheckLocalAvailability(TModel model, IQueryable<TModel> items);
|
||||||
|
|
||||||
public ArchiveDownloadRequest<TModel> GetExistingDownload(TModel model) => currentDownloads.Find(r => r.Model.Equals(model));
|
public ArchiveDownloadRequest<TModel> GetExistingDownload(TModel model) => currentDownloads.Find(r => r.Model.Equals(model));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user