Merge branch 'master' into remove-model-file-list-inits

This commit is contained in:
Dan Balasescu
2021-11-24 19:46:42 +09:00
committed by GitHub
36 changed files with 234 additions and 349 deletions

View File

@ -103,7 +103,10 @@ namespace osu.Desktop.Updater
} }
else else
{ {
// In the case of an error, a separate notification will be displayed.
notification.State = ProgressNotificationState.Cancelled; notification.State = ProgressNotificationState.Cancelled;
notification.Close();
Logger.Error(e, @"update failed!"); Logger.Error(e, @"update failed!");
} }
} }

View File

@ -596,7 +596,7 @@ namespace osu.Game.Tests.Beatmaps.IO
{ {
OnlineID = 2, OnlineID = 2,
Metadata = metadata, Metadata = metadata,
Status = BeatmapSetOnlineStatus.Loved, Status = BeatmapOnlineStatus.Loved,
BaseDifficulty = difficulty BaseDifficulty = difficulty
} }
} }

View File

@ -550,7 +550,7 @@ namespace osu.Game.Tests.Database
new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata) new RealmBeatmap(ruleset, new RealmBeatmapDifficulty(), metadata)
{ {
OnlineID = 2, OnlineID = 2,
Status = BeatmapSetOnlineStatus.Loved, Status = BeatmapOnlineStatus.Loved,
} }
} }
}; };

View File

@ -38,7 +38,7 @@ namespace osu.Game.Tests.NonVisual.Filtering
Length = 2500, Length = 2500,
BPM = 160, BPM = 160,
BeatDivisor = 12, BeatDivisor = 12,
Status = BeatmapSetOnlineStatus.Loved Status = BeatmapOnlineStatus.Loved
}; };
[Test] [Test]

View File

@ -162,9 +162,9 @@ namespace osu.Game.Tests.NonVisual.Filtering
FilterQueryParser.ApplyQueries(filterCriteria, query); FilterQueryParser.ApplyQueries(filterCriteria, query);
Assert.AreEqual("I want the pp", filterCriteria.SearchText.Trim()); Assert.AreEqual("I want the pp", filterCriteria.SearchText.Trim());
Assert.AreEqual(4, filterCriteria.SearchTerms.Length); Assert.AreEqual(4, filterCriteria.SearchTerms.Length);
Assert.AreEqual(BeatmapSetOnlineStatus.Ranked, filterCriteria.OnlineStatus.Min); Assert.AreEqual(BeatmapOnlineStatus.Ranked, filterCriteria.OnlineStatus.Min);
Assert.IsTrue(filterCriteria.OnlineStatus.IsLowerInclusive); Assert.IsTrue(filterCriteria.OnlineStatus.IsLowerInclusive);
Assert.AreEqual(BeatmapSetOnlineStatus.Ranked, filterCriteria.OnlineStatus.Max); Assert.AreEqual(BeatmapOnlineStatus.Ranked, filterCriteria.OnlineStatus.Max);
Assert.IsTrue(filterCriteria.OnlineStatus.IsUpperInclusive); Assert.IsTrue(filterCriteria.OnlineStatus.IsUpperInclusive);
} }

View File

@ -2,10 +2,18 @@
// 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.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
using System.Threading;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Extensions;
using osu.Framework.IO.Stores; using osu.Framework.IO.Stores;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
namespace osu.Game.Tests.Resources namespace osu.Game.Tests.Resources
{ {
@ -56,5 +64,78 @@ namespace osu.Game.Tests.Resources
} }
private static string getTempFilename() => temp_storage.GetFullPath(Guid.NewGuid() + ".osz"); private static string getTempFilename() => temp_storage.GetFullPath(Guid.NewGuid() + ".osz");
private static int importId;
/// <summary>
/// Create a test beatmap set model.
/// </summary>
/// <param name="difficultyCount">Number of difficulties. If null, a random number between 1 and 20 will be used.</param>
/// <param name="rulesets">Rulesets to cycle through when creating difficulties. If <c>null</c>, osu! ruleset will be used.</param>
public static BeatmapSetInfo CreateTestBeatmapSetInfo(int? difficultyCount = null, RulesetInfo[] rulesets = null)
{
int j = 0;
RulesetInfo getRuleset() => rulesets?[j++ % rulesets.Length] ?? new OsuRuleset().RulesetInfo;
int setId = Interlocked.Increment(ref importId);
var metadata = new BeatmapMetadata
{
// Create random metadata, then we can check if sorting works based on these
Artist = "Some Artist " + RNG.Next(0, 9),
Title = $"Some Song (set id {setId}) {Guid.NewGuid()}",
AuthorString = "Some Guy " + RNG.Next(0, 9),
};
var beatmapSet = new BeatmapSetInfo
{
OnlineID = setId,
Hash = new MemoryStream(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())).ComputeMD5Hash(),
DateAdded = DateTimeOffset.UtcNow,
Metadata = metadata
};
foreach (var b in getBeatmaps(difficultyCount ?? RNG.Next(1, 20)))
beatmapSet.Beatmaps.Add(b);
return beatmapSet;
IEnumerable<BeatmapInfo> getBeatmaps(int count)
{
for (int i = 0; i < count; i++)
{
int beatmapId = setId * 1000 + i;
int length = RNG.Next(30000, 200000);
double bpm = RNG.NextSingle(80, 200);
float diff = (float)i / count * 10;
string version = "Normal";
if (diff > 6.6)
version = "Insane";
else if (diff > 3.3)
version = "Hard";
var rulesetInfo = getRuleset();
yield return new BeatmapInfo
{
OnlineID = beatmapId,
DifficultyName = $"{version} {beatmapId} (length {TimeSpan.FromMilliseconds(length):m\\:ss}, bpm {bpm:0.#})",
StarRating = diff,
Length = length,
BPM = bpm,
Ruleset = rulesetInfo,
RulesetID = rulesetInfo.ID ?? -1,
Metadata = metadata,
BaseDifficulty = new BeatmapDifficulty
{
OverallDifficulty = diff,
}
};
}
}
}
} }
} }

View File

@ -42,7 +42,7 @@ namespace osu.Game.Tests.Visual.Beatmaps
var withStatistics = CreateAPIBeatmapSet(Ruleset.Value); var withStatistics = CreateAPIBeatmapSet(Ruleset.Value);
withStatistics.Title = withStatistics.TitleUnicode = "play favourite stats"; withStatistics.Title = withStatistics.TitleUnicode = "play favourite stats";
withStatistics.Status = BeatmapSetOnlineStatus.Approved; withStatistics.Status = BeatmapOnlineStatus.Approved;
withStatistics.FavouriteCount = 284_239; withStatistics.FavouriteCount = 284_239;
withStatistics.PlayCount = 999_001; withStatistics.PlayCount = 999_001;
withStatistics.Ranked = DateTimeOffset.Now.AddDays(-45); withStatistics.Ranked = DateTimeOffset.Now.AddDays(-45);
@ -63,7 +63,7 @@ namespace osu.Game.Tests.Visual.Beatmaps
var someDifficulties = getManyDifficultiesBeatmapSet(11); var someDifficulties = getManyDifficultiesBeatmapSet(11);
someDifficulties.Title = someDifficulties.TitleUnicode = "favourited"; someDifficulties.Title = someDifficulties.TitleUnicode = "favourited";
someDifficulties.Title = someDifficulties.TitleUnicode = "some difficulties"; someDifficulties.Title = someDifficulties.TitleUnicode = "some difficulties";
someDifficulties.Status = BeatmapSetOnlineStatus.Qualified; someDifficulties.Status = BeatmapOnlineStatus.Qualified;
someDifficulties.HasFavourited = true; someDifficulties.HasFavourited = true;
someDifficulties.FavouriteCount = 1; someDifficulties.FavouriteCount = 1;
someDifficulties.NominationStatus = new BeatmapSetNominationStatus someDifficulties.NominationStatus = new BeatmapSetNominationStatus
@ -73,7 +73,7 @@ namespace osu.Game.Tests.Visual.Beatmaps
}; };
var manyDifficulties = getManyDifficultiesBeatmapSet(100); var manyDifficulties = getManyDifficultiesBeatmapSet(100);
manyDifficulties.Status = BeatmapSetOnlineStatus.Pending; manyDifficulties.Status = BeatmapOnlineStatus.Pending;
var explicitMap = CreateAPIBeatmapSet(Ruleset.Value); var explicitMap = CreateAPIBeatmapSet(Ruleset.Value);
explicitMap.Title = someDifficulties.TitleUnicode = "explicit beatmap"; explicitMap.Title = someDifficulties.TitleUnicode = "explicit beatmap";

View File

@ -26,7 +26,7 @@ namespace osu.Game.Tests.Visual.Beatmaps
Origin = Anchor.Centre, Origin = Anchor.Centre,
Direction = FillDirection.Vertical, Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 10), Spacing = new Vector2(0, 10),
ChildrenEnumerable = Enum.GetValues(typeof(BeatmapSetOnlineStatus)).Cast<BeatmapSetOnlineStatus>().Select(status => new BeatmapSetOnlineStatusPill ChildrenEnumerable = Enum.GetValues(typeof(BeatmapOnlineStatus)).Cast<BeatmapOnlineStatus>().Select(status => new BeatmapSetOnlineStatusPill
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,

View File

@ -30,25 +30,10 @@ namespace osu.Game.Tests.Visual.Menus
[Test] [Test]
public void TestMusicNavigationActions() public void TestMusicNavigationActions()
{ {
int importId = 0;
Queue<(IWorkingBeatmap working, TrackChangeDirection changeDirection)> trackChangeQueue = null; Queue<(IWorkingBeatmap working, TrackChangeDirection changeDirection)> trackChangeQueue = null;
// ensure we have at least two beatmaps available to identify the direction the music controller navigated to. // ensure we have at least two beatmaps available to identify the direction the music controller navigated to.
AddRepeatStep("import beatmap", () => Game.BeatmapManager.Import(new BeatmapSetInfo AddRepeatStep("import beatmap", () => Game.BeatmapManager.Import(TestResources.CreateTestBeatmapSetInfo()).Wait(), 5);
{
Beatmaps =
{
new BeatmapInfo
{
BaseDifficulty = new BeatmapDifficulty(),
}
},
Metadata = new BeatmapMetadata
{
Artist = $"a test map {importId++}",
Title = "title",
}
}).Wait(), 5);
AddStep("import beatmap with track", () => AddStep("import beatmap with track", () =>
{ {

View File

@ -2,13 +2,10 @@
// 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.IO;
using System.Linq; using System.Linq;
using System.Text;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Extensions;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Utils; using osu.Framework.Utils;
@ -20,6 +17,7 @@ using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Playlists; using osu.Game.Screens.OnlinePlay.Playlists;
using osu.Game.Tests.Resources;
using osu.Game.Tests.Visual.OnlinePlay; using osu.Game.Tests.Visual.OnlinePlay;
namespace osu.Game.Tests.Visual.Multiplayer namespace osu.Game.Tests.Visual.Multiplayer
@ -41,43 +39,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Dependencies.Cache(rulesets = new RulesetStore(ContextFactory)); Dependencies.Cache(rulesets = new RulesetStore(ContextFactory));
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default));
var metadata = new BeatmapMetadata var beatmapSet = TestResources.CreateTestBeatmapSetInfo();
{
// Create random metadata, then we can check if sorting works based on these
Artist = "Some Artist " + RNG.Next(0, 9),
Title = "Some Song (set id 10)",
AuthorString = "Some Guy " + RNG.Next(0, 9),
};
var beatmapSet = new BeatmapSetInfo
{
OnlineID = 10,
Hash = new MemoryStream(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())).ComputeMD5Hash(),
Metadata = metadata,
DateAdded = DateTimeOffset.UtcNow,
};
for (int i = 0; i < 6; i++)
{
int beatmapId = 10 * 10 + i;
int length = RNG.Next(30000, 200000);
double bpm = RNG.NextSingle(80, 200);
beatmapSet.Beatmaps.Add(new BeatmapInfo
{
Ruleset = new OsuRuleset().RulesetInfo,
OnlineID = beatmapId,
DifficultyName = $"{beatmapId} (length {TimeSpan.FromMilliseconds(length):m\\:ss}, bpm {bpm:0.#})",
Length = length,
Metadata = metadata,
BPM = bpm,
BaseDifficulty = new BeatmapDifficulty
{
OverallDifficulty = 3.5f,
},
});
}
manager.Import(beatmapSet).Wait(); manager.Import(beatmapSet).Wait();
} }

View File

@ -57,7 +57,7 @@ namespace osu.Game.Tests.Visual.Online
} }
}, },
Ratings = Enumerable.Range(0, 11).Select(_ => RNG.Next(10)).ToArray(), Ratings = Enumerable.Range(0, 11).Select(_ => RNG.Next(10)).ToArray(),
Status = BeatmapSetOnlineStatus.Ranked Status = BeatmapOnlineStatus.Ranked
}; };
} }

View File

@ -338,7 +338,7 @@ namespace osu.Game.Tests.Visual.Ranking
: base(score, true) : base(score, true)
{ {
Score.BeatmapInfo.OnlineID = 0; Score.BeatmapInfo.OnlineID = 0;
Score.BeatmapInfo.Status = BeatmapSetOnlineStatus.Pending; Score.BeatmapInfo.Status = BeatmapOnlineStatus.Pending;
} }
protected override void LoadComplete() protected override void LoadComplete()

View File

@ -3,15 +3,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -19,6 +15,7 @@ using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Select; using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Carousel; using osu.Game.Screens.Select.Carousel;
using osu.Game.Screens.Select.Filter; using osu.Game.Screens.Select.Filter;
using osu.Game.Tests.Resources;
using osuTK.Input; using osuTK.Input;
namespace osu.Game.Tests.Visual.SongSelect namespace osu.Game.Tests.Visual.SongSelect
@ -152,7 +149,7 @@ namespace osu.Game.Tests.Visual.SongSelect
const int total_set_count = 200; const int total_set_count = 200;
for (int i = 0; i < total_set_count; i++) for (int i = 0; i < total_set_count; i++)
sets.Add(createTestBeatmapSet(i + 1)); sets.Add(TestResources.CreateTestBeatmapSetInfo());
loadBeatmaps(sets); loadBeatmaps(sets);
@ -183,7 +180,7 @@ namespace osu.Game.Tests.Visual.SongSelect
const int total_set_count = 20; const int total_set_count = 20;
for (int i = 0; i < total_set_count; i++) for (int i = 0; i < total_set_count; i++)
sets.Add(createTestBeatmapSet(i + 1)); sets.Add(TestResources.CreateTestBeatmapSetInfo(3));
loadBeatmaps(sets); loadBeatmaps(sets);
@ -228,10 +225,9 @@ namespace osu.Game.Tests.Visual.SongSelect
loadBeatmaps(); loadBeatmaps();
// basic filtering // basic filtering
setSelected(1, 1); setSelected(1, 1);
AddStep("Filter", () => carousel.Filter(new FilterCriteria { SearchText = "set #3!" }, false)); AddStep("Filter", () => carousel.Filter(new FilterCriteria { SearchText = carousel.BeatmapSets.ElementAt(2).Metadata.Title }, false));
checkVisibleItemCount(diff: false, count: 1); checkVisibleItemCount(diff: false, count: 1);
checkVisibleItemCount(diff: true, count: 3); checkVisibleItemCount(diff: true, count: 3);
waitForSelection(3, 1); waitForSelection(3, 1);
@ -275,16 +271,20 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestFilterRange() public void TestFilterRange()
{ {
string searchText = null;
loadBeatmaps(); loadBeatmaps();
// buffer the selection // buffer the selection
setSelected(3, 2); setSelected(3, 2);
AddStep("get search text", () => searchText = carousel.SelectedBeatmapSet.Metadata.Title);
setSelected(1, 3); setSelected(1, 3);
AddStep("Apply a range filter", () => carousel.Filter(new FilterCriteria AddStep("Apply a range filter", () => carousel.Filter(new FilterCriteria
{ {
SearchText = "#3", SearchText = searchText,
StarDifficulty = new FilterCriteria.OptionalRange<double> StarDifficulty = new FilterCriteria.OptionalRange<double>
{ {
Min = 2, Min = 2,
@ -327,7 +327,7 @@ namespace osu.Game.Tests.Visual.SongSelect
nextRandom(); nextRandom();
AddAssert("ensure repeat", () => selectedSets.Contains(carousel.SelectedBeatmapSet)); AddAssert("ensure repeat", () => selectedSets.Contains(carousel.SelectedBeatmapSet));
AddStep("Add set with 100 difficulties", () => carousel.UpdateBeatmapSet(createTestBeatmapSetWithManyDifficulties(set_count + 1))); AddStep("Add set with 100 difficulties", () => carousel.UpdateBeatmapSet(TestResources.CreateTestBeatmapSetInfo(100, rulesets.AvailableRulesets.ToArray())));
AddStep("Filter Extra", () => carousel.Filter(new FilterCriteria { SearchText = "Extra 10" }, false)); AddStep("Filter Extra", () => carousel.Filter(new FilterCriteria { SearchText = "Extra 10" }, false));
checkInvisibleDifficultiesUnselectable(); checkInvisibleDifficultiesUnselectable();
checkInvisibleDifficultiesUnselectable(); checkInvisibleDifficultiesUnselectable();
@ -345,18 +345,21 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
loadBeatmaps(); loadBeatmaps();
AddStep("Add new set", () => carousel.UpdateBeatmapSet(createTestBeatmapSet(set_count + 1))); var firstAdded = TestResources.CreateTestBeatmapSetInfo();
AddStep("Add new set", () => carousel.UpdateBeatmapSet(createTestBeatmapSet(set_count + 2))); var secondAdded = TestResources.CreateTestBeatmapSetInfo();
AddStep("Add new set", () => carousel.UpdateBeatmapSet(firstAdded));
AddStep("Add new set", () => carousel.UpdateBeatmapSet(secondAdded));
checkVisibleItemCount(false, set_count + 2); checkVisibleItemCount(false, set_count + 2);
AddStep("Remove set", () => carousel.RemoveBeatmapSet(createTestBeatmapSet(set_count + 2))); AddStep("Remove set", () => carousel.RemoveBeatmapSet(firstAdded));
checkVisibleItemCount(false, set_count + 1); checkVisibleItemCount(false, set_count + 1);
setSelected(set_count + 1, 1); setSelected(set_count + 1, 1);
AddStep("Remove set", () => carousel.RemoveBeatmapSet(createTestBeatmapSet(set_count + 1))); AddStep("Remove set", () => carousel.RemoveBeatmapSet(secondAdded));
checkVisibleItemCount(false, set_count); checkVisibleItemCount(false, set_count);
@ -372,7 +375,7 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
sets.Clear(); sets.Clear();
var rulesetBeatmapSet = createTestBeatmapSet(1); var rulesetBeatmapSet = TestResources.CreateTestBeatmapSetInfo(1);
var taikoRuleset = rulesets.AvailableRulesets.ElementAt(1); var taikoRuleset = rulesets.AvailableRulesets.ElementAt(1);
rulesetBeatmapSet.Beatmaps.ForEach(b => rulesetBeatmapSet.Beatmaps.ForEach(b =>
{ {
@ -397,12 +400,29 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestSorting() public void TestSorting()
{ {
loadBeatmaps(); var sets = new List<BeatmapSetInfo>();
const string zzz_string = "zzzzz";
for (int i = 0; i < 20; i++)
{
var set = TestResources.CreateTestBeatmapSetInfo();
if (i == 4)
set.Metadata.Artist = zzz_string;
if (i == 16)
set.Metadata.AuthorString = zzz_string;
sets.Add(set);
}
loadBeatmaps(sets);
AddStep("Sort by author", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Author }, false)); AddStep("Sort by author", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Author }, false));
AddAssert("Check zzzzz is at bottom", () => carousel.BeatmapSets.Last().Metadata.Author.Username == "zzzzz"); AddAssert($"Check {zzz_string} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Author.Username == zzz_string);
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false)); AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
AddAssert($"Check #{set_count} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Title.EndsWith($"#{set_count}!", StringComparison.Ordinal)); AddAssert($"Check {zzz_string} is at bottom", () => carousel.BeatmapSets.Last().Metadata.Artist == zzz_string);
} }
[Test] [Test]
@ -412,20 +432,21 @@ namespace osu.Game.Tests.Visual.SongSelect
for (int i = 0; i < 20; i++) for (int i = 0; i < 20; i++)
{ {
// index + 1 because we are using OnlineID which should never be zero. var set = TestResources.CreateTestBeatmapSetInfo();
var set = createTestBeatmapSet(i + 1);
set.Metadata.Artist = "same artist"; set.Metadata.Artist = "same artist";
set.Metadata.Title = "same title"; set.Metadata.Title = "same title";
sets.Add(set); sets.Add(set);
} }
int idOffset = sets.First().OnlineID ?? 0;
loadBeatmaps(sets); loadBeatmaps(sets);
AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false)); AddStep("Sort by artist", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Artist }, false));
AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == index + 1).All(b => b)); AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == index + idOffset).All(b => b));
AddStep("Sort by title", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Title }, false)); AddStep("Sort by title", () => carousel.Filter(new FilterCriteria { Sort = SortMode.Title }, false));
AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == index + 1).All(b => b)); AddAssert("Items remain in original order", () => carousel.BeatmapSets.Select((set, index) => set.OnlineID == index + idOffset).All(b => b));
} }
[Test] [Test]
@ -435,7 +456,7 @@ namespace osu.Game.Tests.Visual.SongSelect
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
var set = createTestBeatmapSet(i); var set = TestResources.CreateTestBeatmapSetInfo(3);
set.Beatmaps[0].StarRating = 3 - i; set.Beatmaps[0].StarRating = 3 - i;
set.Beatmaps[2].StarRating = 6 + i; set.Beatmaps[2].StarRating = 6 + i;
sets.Add(set); sets.Add(set);
@ -504,7 +525,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("create hidden set", () => AddStep("create hidden set", () =>
{ {
hidingSet = createTestBeatmapSet(1); hidingSet = TestResources.CreateTestBeatmapSetInfo(3);
hidingSet.Beatmaps[1].Hidden = true; hidingSet.Beatmaps[1].Hidden = true;
hiddenList.Clear(); hiddenList.Clear();
@ -551,7 +572,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("add mixed ruleset beatmapset", () => AddStep("add mixed ruleset beatmapset", () =>
{ {
testMixed = createTestBeatmapSet(set_count + 1); testMixed = TestResources.CreateTestBeatmapSetInfo();
for (int i = 0; i <= 2; i++) for (int i = 0; i <= 2; i++)
{ {
@ -574,7 +595,7 @@ namespace osu.Game.Tests.Visual.SongSelect
BeatmapSetInfo testSingle = null; BeatmapSetInfo testSingle = null;
AddStep("add single ruleset beatmapset", () => AddStep("add single ruleset beatmapset", () =>
{ {
testSingle = createTestBeatmapSet(set_count + 2); testSingle = TestResources.CreateTestBeatmapSetInfo();
testSingle.Beatmaps.ForEach(b => testSingle.Beatmaps.ForEach(b =>
{ {
b.Ruleset = rulesets.AvailableRulesets.ElementAt(1); b.Ruleset = rulesets.AvailableRulesets.ElementAt(1);
@ -594,7 +615,7 @@ namespace osu.Game.Tests.Visual.SongSelect
List<BeatmapSetInfo> manySets = new List<BeatmapSetInfo>(); List<BeatmapSetInfo> manySets = new List<BeatmapSetInfo>();
for (int i = 1; i <= 50; i++) for (int i = 1; i <= 50; i++)
manySets.Add(createTestBeatmapSet(i)); manySets.Add(TestResources.CreateTestBeatmapSetInfo(i));
loadBeatmaps(manySets); loadBeatmaps(manySets);
@ -627,18 +648,11 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
var set = createTestBeatmapSet(i); manySets.Add(TestResources.CreateTestBeatmapSetInfo(3, new[]
foreach (var b in set.Beatmaps)
{ {
// all taiko except for first // all taiko except for first
int ruleset = i > 0 ? 1 : 0; rulesets.GetRuleset(i > 0 ? 1 : 0)
}));
b.Ruleset = rulesets.GetRuleset(ruleset);
b.RulesetID = ruleset;
}
manySets.Add(set);
} }
}); });
@ -660,7 +674,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("Restore different ruleset filter", () => AddStep("Restore different ruleset filter", () =>
{ {
carousel.Filter(new FilterCriteria { Ruleset = rulesets.GetRuleset(1) }, false); carousel.Filter(new FilterCriteria { Ruleset = rulesets.GetRuleset(1) }, false);
eagerSelectedIDs.Add(carousel.SelectedBeatmapSet.ID); eagerSelectedIDs.Add(carousel.SelectedBeatmapSet.OnlineID ?? -1);
}); });
AddAssert("selection changed", () => !carousel.SelectedBeatmapInfo.Equals(manySets.First().Beatmaps.First())); AddAssert("selection changed", () => !carousel.SelectedBeatmapInfo.Equals(manySets.First().Beatmaps.First()));
@ -678,7 +692,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("add mixed difficulty set", () => AddStep("add mixed difficulty set", () =>
{ {
set = createTestBeatmapSet(1); set = TestResources.CreateTestBeatmapSetInfo(1);
set.Beatmaps.Clear(); set.Beatmaps.Clear();
for (int i = 1; i <= 15; i++) for (int i = 1; i <= 15; i++)
@ -730,7 +744,11 @@ namespace osu.Game.Tests.Visual.SongSelect
beatmapSets = new List<BeatmapSetInfo>(); beatmapSets = new List<BeatmapSetInfo>();
for (int i = 1; i <= (count ?? set_count); i++) for (int i = 1; i <= (count ?? set_count); i++)
beatmapSets.Add(createTestBeatmapSet(i, randomDifficulties)); {
beatmapSets.Add(randomDifficulties
? TestResources.CreateTestBeatmapSetInfo()
: TestResources.CreateTestBeatmapSetInfo(3));
}
} }
carousel.Filter(initialCriteria?.Invoke() ?? new FilterCriteria()); carousel.Filter(initialCriteria?.Invoke() ?? new FilterCriteria());
@ -766,7 +784,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddUntilStep($"selected is set{set}{(diff.HasValue ? $" diff{diff.Value}" : "")}", () => AddUntilStep($"selected is set{set}{(diff.HasValue ? $" diff{diff.Value}" : "")}", () =>
{ {
if (diff != null) if (diff != null)
return carousel.SelectedBeatmapInfo.Equals(carousel.BeatmapSets.Skip(set - 1).First().Beatmaps.Skip(diff.Value - 1).First()); return carousel.SelectedBeatmapInfo?.Equals(carousel.BeatmapSets.Skip(set - 1).First().Beatmaps.Skip(diff.Value - 1).First()) == true;
return carousel.BeatmapSets.Skip(set - 1).First().Beatmaps.Contains(carousel.SelectedBeatmapInfo); return carousel.BeatmapSets.Skip(set - 1).First().Beatmaps.Contains(carousel.SelectedBeatmapInfo);
}); });
@ -834,95 +852,6 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert("Selection is visible", selectedBeatmapVisible); AddAssert("Selection is visible", selectedBeatmapVisible);
} }
private BeatmapSetInfo createTestBeatmapSet(int id, bool randomDifficultyCount = false)
{
var metadata = new BeatmapMetadata
{
// Create random metadata, then we can check if sorting works based on these
Artist = $"peppy{id.ToString().PadLeft(6, '0')}",
Title = $"test set #{id}!",
AuthorString = string.Concat(Enumerable.Repeat((char)('z' - Math.Min(25, id - 1)), 5))
};
var beatmapSet = new BeatmapSetInfo
{
ID = id,
OnlineID = id,
Hash = new MemoryStream(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())).ComputeMD5Hash(),
Metadata = metadata,
};
foreach (var b in getBeatmaps(randomDifficultyCount ? RNG.Next(1, 20) : 3, metadata))
beatmapSet.Beatmaps.Add(b);
return beatmapSet;
}
private IEnumerable<BeatmapInfo> getBeatmaps(int count, BeatmapMetadata metadata)
{
int id = 0;
for (int i = 0; i < count; i++)
{
float diff = (float)i / count * 10;
string version = "Normal";
if (diff > 6.6)
version = "Insane";
else if (diff > 3.3)
version = "Hard";
yield return new BeatmapInfo
{
OnlineID = id++ * 10,
DifficultyName = version,
StarRating = diff,
Ruleset = new OsuRuleset().RulesetInfo,
Metadata = metadata,
BaseDifficulty = new BeatmapDifficulty
{
OverallDifficulty = diff,
}
};
}
}
private BeatmapSetInfo createTestBeatmapSetWithManyDifficulties(int id)
{
var metadata = new BeatmapMetadata
{
// Create random metadata, then we can check if sorting works based on these
Artist = $"peppy{id.ToString().PadLeft(6, '0')}",
Title = $"test set #{id}!",
AuthorString = string.Concat(Enumerable.Repeat((char)('z' - Math.Min(25, id - 1)), 5))
};
var toReturn = new BeatmapSetInfo
{
OnlineID = id,
Hash = new MemoryStream(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())).ComputeMD5Hash(),
Metadata = metadata,
};
for (int b = 1; b < 101; b++)
{
toReturn.Beatmaps.Add(new BeatmapInfo
{
OnlineID = b * 10,
DifficultyName = $"Extra {b}",
Ruleset = rulesets.GetRuleset((b - 1) % 4),
StarRating = 2,
Metadata = metadata,
BaseDifficulty = new BeatmapDifficulty
{
OverallDifficulty = 3.5f,
}
});
}
return toReturn;
}
private class TestBeatmapCarousel : BeatmapCarousel private class TestBeatmapCarousel : BeatmapCarousel
{ {
public bool PendingFilterTask => PendingFilter != null; public bool PendingFilterTask => PendingFilter != null;

View File

@ -220,7 +220,7 @@ namespace osu.Game.Tests.Visual.SongSelect
Title = "Verrrrry long Title" Title = "Verrrrry long Title"
}, },
DifficultyName = "Verrrrrrrrrrrrrrrrrrrrrrrrrrrrry long Version", DifficultyName = "Verrrrrrrrrrrrrrrrrrrrrrrrrrrrry long Version",
Status = BeatmapSetOnlineStatus.Graveyard, Status = BeatmapOnlineStatus.Graveyard,
}, },
}; };
} }

View File

@ -121,7 +121,7 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestBeatmapStates() public void TestBeatmapStates()
{ {
foreach (BeatmapSetOnlineStatus status in Enum.GetValues(typeof(BeatmapSetOnlineStatus))) foreach (BeatmapOnlineStatus status in Enum.GetValues(typeof(BeatmapOnlineStatus)))
AddStep($"{status} beatmap", () => showBeatmapWithStatus(status)); AddStep($"{status} beatmap", () => showBeatmapWithStatus(status));
} }
@ -384,7 +384,7 @@ namespace osu.Game.Tests.Visual.SongSelect
}; };
} }
private void showBeatmapWithStatus(BeatmapSetOnlineStatus status) private void showBeatmapWithStatus(BeatmapOnlineStatus status)
{ {
leaderboard.BeatmapInfo = new BeatmapInfo leaderboard.BeatmapInfo = new BeatmapInfo
{ {

View File

@ -16,6 +16,7 @@ using osu.Game.Rulesets.Catch;
using osu.Game.Rulesets.Mania; using osu.Game.Rulesets.Mania;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Taiko; using osu.Game.Rulesets.Taiko;
using osu.Game.Tests.Resources;
using osu.Game.Users; using osu.Game.Users;
namespace osu.Game.Tests.Visual.SongSelect namespace osu.Game.Tests.Visual.SongSelect
@ -89,7 +90,7 @@ namespace osu.Game.Tests.Visual.SongSelect
for (int i = 0; i < import_count; ++i) for (int i = 0; i < import_count; ++i)
{ {
beatmapSets.Add(importBeatmapSet(i, Enumerable.Repeat(new OsuRuleset().RulesetInfo, 5))); beatmapSets.Add(importBeatmapSet(Enumerable.Repeat(new OsuRuleset().RulesetInfo, 5)));
} }
}); });
@ -103,9 +104,8 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
BeatmapSetInfo catchSet = null, mixedSet = null; BeatmapSetInfo catchSet = null, mixedSet = null;
AddStep("create catch beatmapset", () => catchSet = importBeatmapSet(1, new[] { new CatchRuleset().RulesetInfo })); AddStep("create catch beatmapset", () => catchSet = importBeatmapSet(new[] { new CatchRuleset().RulesetInfo }));
AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(2, AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new ManiaRuleset().RulesetInfo }));
new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new ManiaRuleset().RulesetInfo }));
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { catchSet, mixedSet })); AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { catchSet, mixedSet }));
@ -121,9 +121,8 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
BeatmapSetInfo osuSet = null, mixedSet = null; BeatmapSetInfo osuSet = null, mixedSet = null;
AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(1, new[] { new OsuRuleset().RulesetInfo })); AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(new[] { new OsuRuleset().RulesetInfo }));
AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(2, AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new ManiaRuleset().RulesetInfo }));
new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new ManiaRuleset().RulesetInfo }));
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, mixedSet })); AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, mixedSet }));
@ -139,9 +138,8 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
BeatmapSetInfo osuSet = null, mixedSet = null; BeatmapSetInfo osuSet = null, mixedSet = null;
AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(1, new[] { new OsuRuleset().RulesetInfo })); AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(new[] { new OsuRuleset().RulesetInfo }));
AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(2, AddStep("create mixed beatmapset", () => mixedSet = importBeatmapSet(new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new TaikoRuleset().RulesetInfo }));
new[] { new TaikoRuleset().RulesetInfo, new CatchRuleset().RulesetInfo, new TaikoRuleset().RulesetInfo }));
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, mixedSet })); AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, mixedSet }));
@ -157,8 +155,8 @@ namespace osu.Game.Tests.Visual.SongSelect
{ {
BeatmapSetInfo osuSet = null, maniaSet = null; BeatmapSetInfo osuSet = null, maniaSet = null;
AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(1, new[] { new OsuRuleset().RulesetInfo })); AddStep("create osu! beatmapset", () => osuSet = importBeatmapSet(new[] { new OsuRuleset().RulesetInfo }));
AddStep("create mania beatmapset", () => maniaSet = importBeatmapSet(2, Enumerable.Repeat(new ManiaRuleset().RulesetInfo, 10))); AddStep("create mania beatmapset", () => maniaSet = importBeatmapSet(Enumerable.Repeat(new ManiaRuleset().RulesetInfo, 10)));
AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, maniaSet })); AddAssert("all sets imported", () => ensureAllBeatmapSetsImported(new[] { osuSet, maniaSet }));
@ -169,31 +167,19 @@ namespace osu.Game.Tests.Visual.SongSelect
presentAndConfirm(() => maniaSet, 5); presentAndConfirm(() => maniaSet, 5);
} }
private BeatmapSetInfo importBeatmapSet(int importID, IEnumerable<RulesetInfo> difficultyRulesets) private BeatmapSetInfo importBeatmapSet(IEnumerable<RulesetInfo> difficultyRulesets)
{ {
var metadata = new BeatmapMetadata var rulesets = difficultyRulesets.ToArray();
{
Artist = "SomeArtist",
AuthorString = "SomeAuthor",
Title = $"import {importID}"
};
var beatmapSet = new BeatmapSetInfo var beatmapSet = TestResources.CreateTestBeatmapSetInfo(rulesets.Length, rulesets);
{
Hash = Guid.NewGuid().ToString(),
OnlineID = importID,
Metadata = metadata,
};
beatmapSet.Beatmaps.AddRange(difficultyRulesets.Select((ruleset, difficultyIndex) => new BeatmapInfo for (int i = 0; i < rulesets.Length; i++)
{ {
OnlineID = importID * 1024 + difficultyIndex, var beatmap = beatmapSet.Beatmaps[i];
Metadata = metadata,
BaseDifficulty = new BeatmapDifficulty(), beatmap.StarRating = i + 1;
Ruleset = ruleset, beatmap.DifficultyName = $"SR{i + 1}";
StarRating = difficultyIndex + 1, }
DifficultyName = $"SR{difficultyIndex + 1}"
}));
return Game.BeatmapManager.Import(beatmapSet).Result.Value; return Game.BeatmapManager.Import(beatmapSet).Result.Value;
} }

View File

@ -3,15 +3,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions;
using osu.Framework.Utils;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Testing; using osu.Framework.Testing;
@ -31,6 +27,7 @@ using osu.Game.Screens.Play;
using osu.Game.Screens.Select; using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Carousel; using osu.Game.Screens.Select.Carousel;
using osu.Game.Screens.Select.Filter; using osu.Game.Screens.Select.Filter;
using osu.Game.Tests.Resources;
using osuTK.Input; using osuTK.Input;
namespace osu.Game.Tests.Visual.SongSelect namespace osu.Game.Tests.Visual.SongSelect
@ -259,7 +256,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("import multi-ruleset map", () => AddStep("import multi-ruleset map", () =>
{ {
var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray(); var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();
manager.Import(createTestBeatmapSet(usableRulesets)).Wait(); manager.Import(TestResources.CreateTestBeatmapSetInfo(rulesets: usableRulesets)).Wait();
}); });
} }
else else
@ -666,7 +663,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("import multi-ruleset map", () => AddStep("import multi-ruleset map", () =>
{ {
var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray(); var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();
manager.Import(createTestBeatmapSet(usableRulesets)).Wait(); manager.Import(TestResources.CreateTestBeatmapSetInfo(3, usableRulesets)).Wait();
}); });
int previousSetID = 0; int previousSetID = 0;
@ -706,7 +703,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("import multi-ruleset map", () => AddStep("import multi-ruleset map", () =>
{ {
var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray(); var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();
manager.Import(createTestBeatmapSet(usableRulesets)).Wait(); manager.Import(TestResources.CreateTestBeatmapSetInfo(3, usableRulesets)).Wait();
}); });
DrawableCarouselBeatmapSet set = null; DrawableCarouselBeatmapSet set = null;
@ -755,7 +752,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("import huge difficulty count map", () => AddStep("import huge difficulty count map", () =>
{ {
var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray(); var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();
imported = manager.Import(createTestBeatmapSet(usableRulesets, 50)).Result.Value; imported = manager.Import(TestResources.CreateTestBeatmapSetInfo(50, usableRulesets)).Result.Value;
}); });
AddStep("select the first beatmap of import", () => Beatmap.Value = manager.GetWorkingBeatmap(imported.Beatmaps.First())); AddStep("select the first beatmap of import", () => Beatmap.Value = manager.GetWorkingBeatmap(imported.Beatmaps.First()));
@ -869,11 +866,7 @@ namespace osu.Game.Tests.Visual.SongSelect
private void addRulesetImportStep(int id) => AddStep($"import test map for ruleset {id}", () => importForRuleset(id)); private void addRulesetImportStep(int id) => AddStep($"import test map for ruleset {id}", () => importForRuleset(id));
private void importForRuleset(int id) => manager.Import(createTestBeatmapSet(rulesets.AvailableRulesets.Where(r => r.OnlineID == id).ToArray())).Wait(); private void importForRuleset(int id) => manager.Import(TestResources.CreateTestBeatmapSetInfo(3, rulesets.AvailableRulesets.Where(r => r.OnlineID == id).ToArray())).Wait();
private static int importId;
private int getImportId() => ++importId;
private void checkMusicPlaying(bool playing) => private void checkMusicPlaying(bool playing) =>
AddUntilStep($"music {(playing ? "" : "not ")}playing", () => music.IsPlaying == playing); AddUntilStep($"music {(playing ? "" : "not ")}playing", () => music.IsPlaying == playing);
@ -896,58 +889,10 @@ namespace osu.Game.Tests.Visual.SongSelect
var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray(); var usableRulesets = rulesets.AvailableRulesets.Where(r => r.OnlineID != 2).ToArray();
for (int i = 0; i < 100; i += 10) for (int i = 0; i < 100; i += 10)
manager.Import(createTestBeatmapSet(usableRulesets)).Wait(); manager.Import(TestResources.CreateTestBeatmapSetInfo(rulesets: usableRulesets)).Wait();
}); });
} }
private BeatmapSetInfo createTestBeatmapSet(RulesetInfo[] rulesets, int countPerRuleset = 6)
{
int j = 0;
RulesetInfo getRuleset() => rulesets[j++ % rulesets.Length];
int setId = getImportId();
var metadata = new BeatmapMetadata
{
// Create random metadata, then we can check if sorting works based on these
Artist = "Some Artist " + RNG.Next(0, 9),
Title = $"Some Song (set id {setId})",
AuthorString = "Some Guy " + RNG.Next(0, 9),
};
var beatmapSet = new BeatmapSetInfo
{
OnlineID = setId,
Hash = new MemoryStream(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())).ComputeMD5Hash(),
DateAdded = DateTimeOffset.UtcNow,
Metadata = metadata
};
for (int i = 0; i < countPerRuleset; i++)
{
int beatmapId = setId * 1000 + i;
int length = RNG.Next(30000, 200000);
double bpm = RNG.NextSingle(80, 200);
beatmapSet.Beatmaps.Add(new BeatmapInfo
{
Ruleset = getRuleset(),
OnlineID = beatmapId,
DifficultyName = $"{beatmapId} (length {TimeSpan.FromMilliseconds(length):m\\:ss}, bpm {bpm:0.#})",
Length = length,
Metadata = metadata,
BPM = bpm,
BaseDifficulty = new BeatmapDifficulty
{
OverallDifficulty = 3.5f,
},
});
}
return beatmapSet;
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);

View File

@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.UserInterface
[Test] [Test]
public void TestLabelledEnumDropdown() public void TestLabelledEnumDropdown()
=> AddStep(@"create dropdown", () => Child = new LabelledEnumDropdown<BeatmapSetOnlineStatus> => AddStep(@"create dropdown", () => Child = new LabelledEnumDropdown<BeatmapOnlineStatus>
{ {
Label = @"Beatmap status", Label = @"Beatmap status",
Description = @"This is a description" Description = @"This is a description"

View File

@ -10,7 +10,7 @@ namespace osu.Game.Tests.Visual.UserInterface
public class TestSceneOsuDropdown : ThemeComparisonTestScene public class TestSceneOsuDropdown : ThemeComparisonTestScene
{ {
protected override Drawable CreateContent() => protected override Drawable CreateContent() =>
new OsuEnumDropdown<BeatmapSetOnlineStatus> new OsuEnumDropdown<BeatmapOnlineStatus>
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,

View File

@ -1,16 +1,16 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// 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.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
using osu.Game.Overlays.Music; using osu.Game.Overlays.Music;
using osu.Game.Tests.Resources;
using osuTK; using osuTK;
using osuTK.Input; using osuTK.Input;
@ -22,6 +22,8 @@ namespace osu.Game.Tests.Visual.UserInterface
private PlaylistOverlay playlistOverlay; private PlaylistOverlay playlistOverlay;
private BeatmapSetInfo first;
[SetUp] [SetUp]
public void Setup() => Schedule(() => public void Setup() => Schedule(() =>
{ {
@ -43,19 +45,11 @@ namespace osu.Game.Tests.Visual.UserInterface
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
beatmapSets.Add(new BeatmapSetInfo beatmapSets.Add(TestResources.CreateTestBeatmapSetInfo());
{
Metadata = new BeatmapMetadata
{
// Create random metadata, then we can check if sorting works based on these
Artist = "Some Artist " + RNG.Next(0, 9),
Title = $"Some Song {i + 1}",
AuthorString = "Some Guy " + RNG.Next(0, 9),
},
DateAdded = DateTimeOffset.UtcNow,
});
} }
first = beatmapSets.First();
playlistOverlay.BeatmapSets.BindTo(beatmapSets); playlistOverlay.BeatmapSets.BindTo(beatmapSets);
}); });
@ -66,7 +60,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("hold 1st item handle", () => AddStep("hold 1st item handle", () =>
{ {
var handle = this.ChildrenOfType<PlaylistItem.PlaylistItemHandle>().First(); var handle = this.ChildrenOfType<OsuRearrangeableListItem<BeatmapSetInfo>.PlaylistItemHandle>().First();
InputManager.MoveMouseTo(handle.ScreenSpaceDrawQuad.Centre); InputManager.MoveMouseTo(handle.ScreenSpaceDrawQuad.Centre);
InputManager.PressButton(MouseButton.Left); InputManager.PressButton(MouseButton.Left);
}); });
@ -77,7 +71,7 @@ namespace osu.Game.Tests.Visual.UserInterface
InputManager.MoveMouseTo(item.ScreenSpaceDrawQuad.Centre); InputManager.MoveMouseTo(item.ScreenSpaceDrawQuad.Centre);
}); });
AddAssert("song 1 is 5th", () => beatmapSets[4].Metadata.Title == "Some Song 1"); AddAssert("song 1 is 5th", () => beatmapSets[4] == first);
AddStep("release handle", () => InputManager.ReleaseButton(MouseButton.Left)); AddStep("release handle", () => InputManager.ReleaseButton(MouseButton.Left));
} }

View File

@ -35,7 +35,7 @@ namespace osu.Game.Beatmaps
[JsonIgnore] [JsonIgnore]
public int BeatmapSetInfoID { get; set; } public int BeatmapSetInfoID { get; set; }
public BeatmapSetOnlineStatus Status { get; set; } = BeatmapSetOnlineStatus.None; public BeatmapOnlineStatus Status { get; set; } = BeatmapOnlineStatus.None;
[Required] [Required]
public BeatmapSetInfo BeatmapSet { get; set; } public BeatmapSetInfo BeatmapSet { get; set; }

View File

@ -83,7 +83,7 @@ namespace osu.Game.Beatmaps
if (res != null) if (res != null)
{ {
beatmapInfo.Status = res.Status; beatmapInfo.Status = res.Status;
beatmapInfo.BeatmapSet.Status = res.BeatmapSet?.Status ?? BeatmapSetOnlineStatus.None; beatmapInfo.BeatmapSet.Status = res.BeatmapSet?.Status ?? BeatmapOnlineStatus.None;
beatmapInfo.BeatmapSet.OnlineID = res.OnlineBeatmapSetID; beatmapInfo.BeatmapSet.OnlineID = res.OnlineBeatmapSetID;
beatmapInfo.OnlineID = res.OnlineID; beatmapInfo.OnlineID = res.OnlineID;
@ -182,7 +182,7 @@ namespace osu.Game.Beatmaps
{ {
if (reader.Read()) if (reader.Read())
{ {
var status = (BeatmapSetOnlineStatus)reader.GetByte(2); var status = (BeatmapOnlineStatus)reader.GetByte(2);
beatmapInfo.Status = status; beatmapInfo.Status = status;
beatmapInfo.BeatmapSet.Status = status; beatmapInfo.BeatmapSet.Status = status;

View File

@ -6,7 +6,7 @@ using osu.Game.Resources.Localisation.Web;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
public enum BeatmapSetOnlineStatus public enum BeatmapOnlineStatus
{ {
None = -3, None = -3,
@ -34,7 +34,7 @@ namespace osu.Game.Beatmaps
public static class BeatmapSetOnlineStatusExtensions public static class BeatmapSetOnlineStatusExtensions
{ {
public static bool GrantsPerformancePoints(this BeatmapSetOnlineStatus status) public static bool GrantsPerformancePoints(this BeatmapOnlineStatus status)
=> status == BeatmapSetOnlineStatus.Ranked || status == BeatmapSetOnlineStatus.Approved; => status == BeatmapOnlineStatus.Ranked || status == BeatmapOnlineStatus.Approved;
} }
} }

View File

@ -34,7 +34,7 @@ namespace osu.Game.Beatmaps
[NotNull] [NotNull]
public List<BeatmapInfo> Beatmaps { get; } = new List<BeatmapInfo>(); public List<BeatmapInfo> Beatmaps { get; } = new List<BeatmapInfo>();
public BeatmapSetOnlineStatus Status { get; set; } = BeatmapSetOnlineStatus.None; public BeatmapOnlineStatus Status { get; set; } = BeatmapOnlineStatus.None;
public List<BeatmapSetFileInfo> Files { get; } = new List<BeatmapSetFileInfo>(); public List<BeatmapSetFileInfo> Files { get; } = new List<BeatmapSetFileInfo>();

View File

@ -18,9 +18,9 @@ namespace osu.Game.Beatmaps.Drawables
{ {
public class BeatmapSetOnlineStatusPill : CircularContainer public class BeatmapSetOnlineStatusPill : CircularContainer
{ {
private BeatmapSetOnlineStatus status; private BeatmapOnlineStatus status;
public BeatmapSetOnlineStatus Status public BeatmapOnlineStatus Status
{ {
get => status; get => status;
set set
@ -75,7 +75,7 @@ namespace osu.Game.Beatmaps.Drawables
}, },
}; };
Status = BeatmapSetOnlineStatus.None; Status = BeatmapOnlineStatus.None;
TextPadding = new MarginPadding { Horizontal = 5, Bottom = 1 }; TextPadding = new MarginPadding { Horizontal = 5, Bottom = 1 };
} }
@ -87,14 +87,14 @@ namespace osu.Game.Beatmaps.Drawables
private void updateState() private void updateState()
{ {
Alpha = Status == BeatmapSetOnlineStatus.None ? 0 : 1; Alpha = Status == BeatmapOnlineStatus.None ? 0 : 1;
statusText.Text = Status.GetLocalisableDescription().ToUpper(); statusText.Text = Status.GetLocalisableDescription().ToUpper();
if (colourProvider != null) if (colourProvider != null)
statusText.Colour = status == BeatmapSetOnlineStatus.Graveyard ? colourProvider.Background1 : colourProvider.Background3; statusText.Colour = status == BeatmapOnlineStatus.Graveyard ? colourProvider.Background1 : colourProvider.Background3;
else else
statusText.Colour = status == BeatmapSetOnlineStatus.Graveyard ? colours.GreySeafoamLight : Color4.Black; statusText.Colour = status == BeatmapOnlineStatus.Graveyard ? colours.GreySeafoamLight : Color4.Black;
background.Colour = OsuColour.ForBeatmapSetOnlineStatus(Status) ?? colourProvider?.Light1 ?? colours.GreySeafoamLighter; background.Colour = OsuColour.ForBeatmapSetOnlineStatus(Status) ?? colourProvider?.Light1 ?? colours.GreySeafoamLighter;
} }

View File

@ -41,10 +41,10 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Statistics
// reference: https://github.com/ppy/osu-web/blob/ef432c11719fd1207bec5f9194b04f0033bdf02c/resources/assets/lib/beatmapset-panel.tsx#L36-L44 // reference: https://github.com/ppy/osu-web/blob/ef432c11719fd1207bec5f9194b04f0033bdf02c/resources/assets/lib/beatmapset-panel.tsx#L36-L44
switch (beatmapSetInfo.Status) switch (beatmapSetInfo.Status)
{ {
case BeatmapSetOnlineStatus.Ranked: case BeatmapOnlineStatus.Ranked:
case BeatmapSetOnlineStatus.Approved: case BeatmapOnlineStatus.Approved:
case BeatmapSetOnlineStatus.Loved: case BeatmapOnlineStatus.Loved:
case BeatmapSetOnlineStatus.Qualified: case BeatmapOnlineStatus.Qualified:
return beatmapSetInfo.Ranked; return beatmapSetInfo.Ranked;
default: default:

View File

@ -30,7 +30,7 @@ namespace osu.Game.Beatmaps
/// <summary> /// <summary>
/// The status of this beatmap set. /// The status of this beatmap set.
/// </summary> /// </summary>
BeatmapSetOnlineStatus Status { get; } BeatmapOnlineStatus Status { get; }
/// <summary> /// <summary>
/// Whether or not this beatmap set has explicit content. /// Whether or not this beatmap set has explicit content.
@ -105,7 +105,7 @@ namespace osu.Game.Beatmaps
/// <summary> /// <summary>
/// Contains the current hype status of the beatmap set. /// Contains the current hype status of the beatmap set.
/// Non-null only for <see cref="BeatmapSetOnlineStatus.WIP"/>, <see cref="BeatmapSetOnlineStatus.Pending"/>, and <see cref="BeatmapSetOnlineStatus.Qualified"/> sets. /// Non-null only for <see cref="BeatmapOnlineStatus.WIP"/>, <see cref="BeatmapOnlineStatus.Pending"/>, and <see cref="BeatmapOnlineStatus.Qualified"/> sets.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// See: https://github.com/ppy/osu-web/blob/93930cd02cfbd49724929912597c727c9fbadcd1/app/Models/Beatmapset.php#L155 /// See: https://github.com/ppy/osu-web/blob/93930cd02cfbd49724929912597c727c9fbadcd1/app/Models/Beatmapset.php#L155

View File

@ -122,34 +122,34 @@ namespace osu.Game.Graphics
} }
/// <summary> /// <summary>
/// Retrieves a colour for the given <see cref="BeatmapSetOnlineStatus"/>. /// Retrieves a colour for the given <see cref="BeatmapOnlineStatus"/>.
/// A <see langword="null"/> value indicates that a "background" shade from the local <see cref="OverlayColourProvider"/> /// A <see langword="null"/> value indicates that a "background" shade from the local <see cref="OverlayColourProvider"/>
/// (or another fallback colour) should be used. /// (or another fallback colour) should be used.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Sourced from web: https://github.com/ppy/osu-web/blob/007eebb1916ed5cb6a7866d82d8011b1060a945e/resources/assets/less/layout.less#L36-L50 /// Sourced from web: https://github.com/ppy/osu-web/blob/007eebb1916ed5cb6a7866d82d8011b1060a945e/resources/assets/less/layout.less#L36-L50
/// </remarks> /// </remarks>
public static Color4? ForBeatmapSetOnlineStatus(BeatmapSetOnlineStatus status) public static Color4? ForBeatmapSetOnlineStatus(BeatmapOnlineStatus status)
{ {
switch (status) switch (status)
{ {
case BeatmapSetOnlineStatus.Ranked: case BeatmapOnlineStatus.Ranked:
case BeatmapSetOnlineStatus.Approved: case BeatmapOnlineStatus.Approved:
return Color4Extensions.FromHex(@"b3ff66"); return Color4Extensions.FromHex(@"b3ff66");
case BeatmapSetOnlineStatus.Loved: case BeatmapOnlineStatus.Loved:
return Color4Extensions.FromHex(@"ff66ab"); return Color4Extensions.FromHex(@"ff66ab");
case BeatmapSetOnlineStatus.Qualified: case BeatmapOnlineStatus.Qualified:
return Color4Extensions.FromHex(@"66ccff"); return Color4Extensions.FromHex(@"66ccff");
case BeatmapSetOnlineStatus.Pending: case BeatmapOnlineStatus.Pending:
return Color4Extensions.FromHex(@"ffd966"); return Color4Extensions.FromHex(@"ffd966");
case BeatmapSetOnlineStatus.WIP: case BeatmapOnlineStatus.WIP:
return Color4Extensions.FromHex(@"ff9966"); return Color4Extensions.FromHex(@"ff9966");
case BeatmapSetOnlineStatus.Graveyard: case BeatmapOnlineStatus.Graveyard:
return Color4.Black; return Color4.Black;
default: default:

View File

@ -39,9 +39,9 @@ namespace osu.Game.Models
[Ignored] [Ignored]
public RealmNamedFileUsage? File => BeatmapSet?.Files.First(f => f.File.Hash == Hash); public RealmNamedFileUsage? File => BeatmapSet?.Files.First(f => f.File.Hash == Hash);
public BeatmapSetOnlineStatus Status public BeatmapOnlineStatus Status
{ {
get => (BeatmapSetOnlineStatus)StatusInt; get => (BeatmapOnlineStatus)StatusInt;
set => StatusInt = (int)value; set => StatusInt = (int)value;
} }

View File

@ -20,7 +20,7 @@ namespace osu.Game.Online.API.Requests.Responses
public int OnlineBeatmapSetID { get; set; } public int OnlineBeatmapSetID { get; set; }
[JsonProperty(@"status")] [JsonProperty(@"status")]
public BeatmapSetOnlineStatus Status { get; set; } public BeatmapOnlineStatus Status { get; set; }
[JsonProperty("checksum")] [JsonProperty("checksum")]
public string Checksum { get; set; } = string.Empty; public string Checksum { get; set; } = string.Empty;

View File

@ -21,7 +21,7 @@ namespace osu.Game.Online.API.Requests.Responses
public int OnlineID { get; set; } public int OnlineID { get; set; }
[JsonProperty(@"status")] [JsonProperty(@"status")]
public BeatmapSetOnlineStatus Status { get; set; } public BeatmapOnlineStatus Status { get; set; }
[JsonProperty(@"preview_url")] [JsonProperty(@"preview_url")]
public string Preview { get; set; } = string.Empty; public string Preview { get; set; } = string.Empty;

View File

@ -244,7 +244,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
noScoresPlaceholder.Hide(); noScoresPlaceholder.Hide();
if (Beatmap.Value == null || Beatmap.Value.OnlineID <= 0 || (Beatmap.Value?.BeatmapSet as IBeatmapSetOnlineInfo)?.Status <= BeatmapSetOnlineStatus.Pending) if (Beatmap.Value == null || Beatmap.Value.OnlineID <= 0 || (Beatmap.Value?.BeatmapSet as IBeatmapSetOnlineInfo)?.Status <= BeatmapOnlineStatus.Pending)
{ {
Scores = null; Scores = null;
Hide(); Hide();

View File

@ -27,7 +27,7 @@ namespace osu.Game.Screens.Ranking
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback) protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
{ {
if (Score.BeatmapInfo.OnlineID == null || Score.BeatmapInfo.Status <= BeatmapSetOnlineStatus.Pending) if (Score.BeatmapInfo.OnlineID == null || Score.BeatmapInfo.Status <= BeatmapOnlineStatus.Pending)
return null; return null;
getScoreRequest = new GetScoresRequest(Score.BeatmapInfo, Score.Ruleset); getScoreRequest = new GetScoresRequest(Score.BeatmapInfo, Score.Ruleset);

View File

@ -28,7 +28,7 @@ namespace osu.Game.Screens.Select
public OptionalRange<double> Length; public OptionalRange<double> Length;
public OptionalRange<double> BPM; public OptionalRange<double> BPM;
public OptionalRange<int> BeatDivisor; public OptionalRange<int> BeatDivisor;
public OptionalRange<BeatmapSetOnlineStatus> OnlineStatus; public OptionalRange<BeatmapOnlineStatus> OnlineStatus;
public OptionalTextFilter Creator; public OptionalTextFilter Creator;
public OptionalTextFilter Artist; public OptionalTextFilter Artist;

View File

@ -154,7 +154,7 @@ namespace osu.Game.Screens.Select.Leaderboards
return null; return null;
} }
if (BeatmapInfo.OnlineID == null || BeatmapInfo?.Status <= BeatmapSetOnlineStatus.Pending) if (BeatmapInfo.OnlineID == null || BeatmapInfo?.Status <= BeatmapOnlineStatus.Pending)
{ {
PlaceholderState = PlaceholderState.Unavailable; PlaceholderState = PlaceholderState.Unavailable;
return null; return null;

View File

@ -226,7 +226,7 @@ namespace osu.Game.Tests.Visual
return new APIBeatmapSet return new APIBeatmapSet
{ {
OnlineID = ((IBeatmapSetInfo)beatmap.BeatmapSet).OnlineID, OnlineID = ((IBeatmapSetInfo)beatmap.BeatmapSet).OnlineID,
Status = BeatmapSetOnlineStatus.Ranked, Status = BeatmapOnlineStatus.Ranked,
Covers = new BeatmapSetOnlineCovers Covers = new BeatmapSetOnlineCovers
{ {
Cover = "https://assets.ppy.sh/beatmaps/163112/covers/cover.jpg", Cover = "https://assets.ppy.sh/beatmaps/163112/covers/cover.jpg",