1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-07 21:32:57 +08:00

Merge pull request #15459 from peppy/beatmap-refactor/remove-online-info

Remove `IOnlineInfo` implementations from database models
This commit is contained in:
Dan Balasescu 2021-11-05 13:16:21 +09:00 committed by GitHub
commit 9b5ed791b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 122 additions and 270 deletions

View File

@ -39,8 +39,8 @@ namespace osu.Game.Tests.NonVisual
[Test] [Test]
public void TestCheckNullID() public void TestCheckNullID()
{ {
var ourInfo = new BeatmapSetInfo { Status = BeatmapSetOnlineStatus.Loved }; var ourInfo = new BeatmapSetInfo { Hash = "1" };
var otherInfo = new BeatmapSetInfo { Status = BeatmapSetOnlineStatus.Approved }; var otherInfo = new BeatmapSetInfo { Hash = "2" };
Assert.AreNotEqual(ourInfo, otherInfo); Assert.AreNotEqual(ourInfo, otherInfo);
} }

View File

@ -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.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -223,11 +224,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test] [Test]
public void TestDownloadButtonVisibleInitiallyWhenBeatmapDoesNotExist() public void TestDownloadButtonVisibleInitiallyWhenBeatmapDoesNotExist()
{ {
var byOnlineId = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo; var byOnlineId = CreateAPIBeatmap();
byOnlineId.BeatmapSet.OnlineBeatmapSetID = 1337; // Some random ID that does not exist locally. byOnlineId.OnlineID = 1337; // Some random ID that does not exist locally.
var byChecksum = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo; var byChecksum = CreateAPIBeatmap();
byChecksum.MD5Hash = "1337"; // Some random checksum that does not exist locally. byChecksum.Checksum = "1337"; // Some random checksum that does not exist locally.
createPlaylist(byOnlineId, byChecksum); createPlaylist(byOnlineId, byChecksum);
@ -237,8 +238,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Test] [Test]
public void TestExplicitBeatmapItem() public void TestExplicitBeatmapItem()
{ {
var beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo; var beatmap = CreateAPIBeatmap();
beatmap.BeatmapSet.OnlineInfo.HasExplicitContent = true;
Debug.Assert(beatmap.BeatmapSet != null);
beatmap.BeatmapSet.HasExplicitContent = true;
createPlaylist(beatmap); createPlaylist(beatmap);
} }
@ -310,7 +314,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
AddUntilStep("wait for items to load", () => playlist.ItemMap.Values.All(i => i.IsLoaded)); AddUntilStep("wait for items to load", () => playlist.ItemMap.Values.All(i => i.IsLoaded));
} }
private void createPlaylist(params BeatmapInfo[] beatmaps) private void createPlaylist(params IBeatmapInfo[] beatmaps)
{ {
AddStep("create playlist", () => AddStep("create playlist", () =>
{ {

View File

@ -9,7 +9,6 @@ using osu.Game.Beatmaps;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.BeatmapListing.Panels; using osu.Game.Overlays.BeatmapListing.Panels;
using osu.Game.Rulesets.Osu;
using osu.Game.Tests.Resources; using osu.Game.Tests.Resources;
using osuTK; using osuTK;
@ -110,7 +109,7 @@ namespace osu.Game.Tests.Visual.Online
private IBeatmapSetInfo getDownloadableBeatmapSet() private IBeatmapSetInfo getDownloadableBeatmapSet()
{ {
var apiBeatmapSet = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo).BeatmapSetInfo.OnlineInfo; var apiBeatmapSet = CreateAPIBeatmapSet();
apiBeatmapSet.HasVideo = true; apiBeatmapSet.HasVideo = true;
apiBeatmapSet.HasStoryboard = true; apiBeatmapSet.HasStoryboard = true;
@ -120,7 +119,7 @@ namespace osu.Game.Tests.Visual.Online
private IBeatmapSetInfo getUndownloadableBeatmapSet() private IBeatmapSetInfo getUndownloadableBeatmapSet()
{ {
var apiBeatmapSet = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo).BeatmapSetInfo.OnlineInfo; var apiBeatmapSet = CreateAPIBeatmapSet();
apiBeatmapSet.Artist = "test"; apiBeatmapSet.Artist = "test";
apiBeatmapSet.Title = "undownloadable"; apiBeatmapSet.Title = "undownloadable";

View File

@ -7,7 +7,6 @@ using osu.Framework.Graphics;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Select; using osu.Game.Screens.Select;
namespace osu.Game.Tests.Visual.SongSelect namespace osu.Game.Tests.Visual.SongSelect
@ -32,159 +31,112 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestAllMetrics() public void TestAllMetrics()
{ {
AddStep("all metrics", () => details.BeatmapInfo = new BeatmapInfo AddStep("all metrics", () => details.BeatmapInfo = new APIBeatmap
{ {
BeatmapSet = new BeatmapSetInfo BeatmapSet = new APIBeatmapSet
{
OnlineInfo = new APIBeatmapSet
{
Ratings = Enumerable.Range(0, 11).ToArray(),
}
},
Version = "All Metrics",
Metadata = new BeatmapMetadata
{ {
Source = "osu!", Source = "osu!",
Tags = "this beatmap has all the metrics", Tags = "this beatmap has all the metrics",
Ratings = Enumerable.Range(0, 11).ToArray(),
}, },
BaseDifficulty = new BeatmapDifficulty DifficultyName = "All Metrics",
CircleSize = 7,
DrainRate = 1,
OverallDifficulty = 5.7f,
ApproachRate = 3.5f,
StarRating = 5.3f,
FailTimes = new APIFailTimes
{ {
CircleSize = 7, Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6).ToArray(),
DrainRate = 1, Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6).ToArray(),
OverallDifficulty = 5.7f,
ApproachRate = 3.5f,
}, },
StarDifficulty = 5.3f,
Ruleset = new OsuRuleset().RulesetInfo,
OnlineInfo = new APIBeatmap
{
FailTimes = new APIFailTimes
{
Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6).ToArray(),
Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6).ToArray(),
},
}
}); });
} }
[Test] [Test]
public void TestAllMetricsExceptSource() public void TestAllMetricsExceptSource()
{ {
AddStep("all except source", () => details.BeatmapInfo = new BeatmapInfo AddStep("all except source", () => details.BeatmapInfo = new APIBeatmap
{ {
BeatmapSet = new BeatmapSetInfo BeatmapSet = new APIBeatmapSet
{
OnlineInfo = new APIBeatmapSet
{
Ratings = Enumerable.Range(0, 11).ToArray(),
}
},
Version = "All Metrics",
Metadata = new BeatmapMetadata
{ {
Tags = "this beatmap has all the metrics", Tags = "this beatmap has all the metrics",
Ratings = Enumerable.Range(0, 11).ToArray(),
}, },
BaseDifficulty = new BeatmapDifficulty DifficultyName = "All Metrics",
CircleSize = 7,
DrainRate = 1,
OverallDifficulty = 5.7f,
ApproachRate = 3.5f,
StarRating = 5.3f,
FailTimes = new APIFailTimes
{ {
CircleSize = 7, Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6).ToArray(),
DrainRate = 1, Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6).ToArray(),
OverallDifficulty = 5.7f,
ApproachRate = 3.5f,
}, },
StarDifficulty = 5.3f,
Ruleset = new OsuRuleset().RulesetInfo,
OnlineInfo = new APIBeatmap
{
FailTimes = new APIFailTimes
{
Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6).ToArray(),
Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6).ToArray(),
},
}
}); });
} }
[Test] [Test]
public void TestOnlyRatings() public void TestOnlyRatings()
{ {
AddStep("ratings", () => details.BeatmapInfo = new BeatmapInfo AddStep("ratings", () => details.BeatmapInfo = new APIBeatmap
{ {
BeatmapSet = new BeatmapSetInfo BeatmapSet = new APIBeatmapSet
{
OnlineInfo = new APIBeatmapSet
{
Ratings = Enumerable.Range(0, 11).ToArray(),
}
},
Version = "Only Ratings",
Metadata = new BeatmapMetadata
{ {
Ratings = Enumerable.Range(0, 11).ToArray(),
Source = "osu!", Source = "osu!",
Tags = "this beatmap has ratings metrics but not retries or fails", Tags = "this beatmap has ratings metrics but not retries or fails",
}, },
Ruleset = new OsuRuleset().RulesetInfo, DifficultyName = "Only Ratings",
BaseDifficulty = new BeatmapDifficulty CircleSize = 6,
{ DrainRate = 9,
CircleSize = 6, OverallDifficulty = 6,
DrainRate = 9, ApproachRate = 6,
OverallDifficulty = 6, StarRating = 4.8f,
ApproachRate = 6,
},
StarDifficulty = 4.8f,
}); });
} }
[Test] [Test]
public void TestOnlyFailsAndRetries() public void TestOnlyFailsAndRetries()
{ {
AddStep("fails retries", () => details.BeatmapInfo = new BeatmapInfo AddStep("fails retries", () => details.BeatmapInfo = new APIBeatmap
{ {
Version = "Only Retries and Fails", DifficultyName = "Only Retries and Fails",
Metadata = new BeatmapMetadata BeatmapSet = new APIBeatmapSet
{ {
Source = "osu!", Source = "osu!",
Tags = "this beatmap has retries and fails but no ratings", Tags = "this beatmap has retries and fails but no ratings",
}, },
BaseDifficulty = new BeatmapDifficulty CircleSize = 3.7f,
DrainRate = 6,
OverallDifficulty = 6,
ApproachRate = 7,
StarRating = 2.91f,
FailTimes = new APIFailTimes
{ {
CircleSize = 3.7f, Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6).ToArray(),
DrainRate = 6, Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6).ToArray(),
OverallDifficulty = 6,
ApproachRate = 7,
}, },
Ruleset = new OsuRuleset().RulesetInfo,
StarDifficulty = 2.91f,
OnlineInfo = new APIBeatmap
{
FailTimes = new APIFailTimes
{
Fails = Enumerable.Range(1, 100).Select(i => i % 12 - 6).ToArray(),
Retries = Enumerable.Range(-2, 100).Select(i => i % 12 - 6).ToArray(),
},
}
}); });
} }
[Test] [Test]
public void TestNoMetrics() public void TestNoMetrics()
{ {
AddStep("no metrics", () => details.BeatmapInfo = new BeatmapInfo AddStep("no metrics", () => details.BeatmapInfo = new APIBeatmap
{ {
Version = "No Metrics", DifficultyName = "No Metrics",
Metadata = new BeatmapMetadata BeatmapSet = new APIBeatmapSet
{ {
Source = "osu!", Source = "osu!",
Tags = "this beatmap has no metrics", Tags = "this beatmap has no metrics",
}, },
Ruleset = new OsuRuleset().RulesetInfo, CircleSize = 5,
BaseDifficulty = new BeatmapDifficulty DrainRate = 5,
{ OverallDifficulty = 5.5f,
CircleSize = 5, ApproachRate = 6.5f,
DrainRate = 5, StarRating = 1.97f,
OverallDifficulty = 5.5f,
ApproachRate = 6.5f,
},
StarDifficulty = 1.97f,
}); });
} }
@ -197,10 +149,9 @@ namespace osu.Game.Tests.Visual.SongSelect
[Test] [Test]
public void TestOnlineMetrics() public void TestOnlineMetrics()
{ {
AddStep("online ratings/retries/fails", () => details.BeatmapInfo = new BeatmapInfo AddStep("online ratings/retries/fails", () => details.BeatmapInfo = new APIBeatmap
{ {
OnlineBeatmapID = 162, OnlineID = 162,
Ruleset = new OsuRuleset().RulesetInfo
}); });
AddStep("set online", () => api.SetState(APIState.Online)); AddStep("set online", () => api.SetState(APIState.Online));
AddStep("set offline", () => api.SetState(APIState.Offline)); AddStep("set offline", () => api.SetState(APIState.Offline));

View File

@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
AddStep("setup cover", () => Child = new UpdateableOnlineBeatmapSetCover(coverType) AddStep("setup cover", () => Child = new UpdateableOnlineBeatmapSetCover(coverType)
{ {
OnlineInfo = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet.OnlineInfo, OnlineInfo = CreateAPIBeatmapSet(),
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
}); });
@ -41,7 +41,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("setup covers", () => AddStep("setup covers", () =>
{ {
BeatmapSetInfo setInfo = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet; var beatmapSet = CreateAPIBeatmapSet();
FillFlowContainer fillFlow; FillFlowContainer fillFlow;
@ -68,7 +68,7 @@ namespace osu.Game.Tests.Visual.UserInterface
var cover = new UpdateableOnlineBeatmapSetCover(coverType) var cover = new UpdateableOnlineBeatmapSetCover(coverType)
{ {
OnlineInfo = setInfo.OnlineInfo, OnlineInfo = beatmapSet,
Height = 100, Height = 100,
Masking = true, Masking = true,
}; };
@ -99,7 +99,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("setup cover", () => Child = updateableCover = new TestUpdateableOnlineBeatmapSetCover AddStep("setup cover", () => Child = updateableCover = new TestUpdateableOnlineBeatmapSetCover
{ {
OnlineInfo = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet.OnlineInfo, OnlineInfo = CreateAPIBeatmapSet(),
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
}); });
@ -117,7 +117,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("setup cover", () => Child = updateableCover = new TestUpdateableOnlineBeatmapSetCover(0) AddStep("setup cover", () => Child = updateableCover = new TestUpdateableOnlineBeatmapSetCover(0)
{ {
OnlineInfo = createBeatmapWithCover("https://assets.ppy.sh/beatmaps/1189904/covers/cover.jpg").OnlineInfo, OnlineInfo = createBeatmapWithCover("https://assets.ppy.sh/beatmaps/1189904/covers/cover.jpg"),
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
Alpha = 0.4f Alpha = 0.4f
@ -128,16 +128,13 @@ namespace osu.Game.Tests.Visual.UserInterface
AddUntilStep("wait for fade complete", () => initialCover.Alpha == 1); AddUntilStep("wait for fade complete", () => initialCover.Alpha == 1);
AddStep("switch beatmap", AddStep("switch beatmap",
() => updateableCover.OnlineInfo = createBeatmapWithCover("https://assets.ppy.sh/beatmaps/1079428/covers/cover.jpg").OnlineInfo); () => updateableCover.OnlineInfo = createBeatmapWithCover("https://assets.ppy.sh/beatmaps/1079428/covers/cover.jpg"));
AddUntilStep("new cover loaded", () => updateableCover.ChildrenOfType<OnlineBeatmapSetCover>().Except(new[] { initialCover }).Any()); AddUntilStep("new cover loaded", () => updateableCover.ChildrenOfType<OnlineBeatmapSetCover>().Except(new[] { initialCover }).Any());
} }
private static BeatmapSetInfo createBeatmapWithCover(string coverUrl) => new BeatmapSetInfo private static APIBeatmapSet createBeatmapWithCover(string coverUrl) => new APIBeatmapSet
{ {
OnlineInfo = new APIBeatmapSet Covers = new BeatmapSetOnlineCovers { Cover = coverUrl }
{
Covers = new BeatmapSetOnlineCovers { Cover = coverUrl }
}
}; };
private class TestUpdateableOnlineBeatmapSetCover : UpdateableOnlineBeatmapSetCover private class TestUpdateableOnlineBeatmapSetCover : UpdateableOnlineBeatmapSetCover

View File

@ -17,7 +17,7 @@ namespace osu.Game.Beatmaps
{ {
[ExcludeFromDynamicCompile] [ExcludeFromDynamicCompile]
[Serializable] [Serializable]
public class BeatmapInfo : IEquatable<BeatmapInfo>, IHasPrimaryKey, IBeatmapInfo, IBeatmapOnlineInfo public class BeatmapInfo : IEquatable<BeatmapInfo>, IHasPrimaryKey, IBeatmapInfo
{ {
public int ID { get; set; } public int ID { get; set; }
@ -201,24 +201,5 @@ namespace osu.Game.Beatmaps
double IBeatmapInfo.StarRating => StarDifficulty; double IBeatmapInfo.StarRating => StarDifficulty;
#endregion #endregion
#region Implementation of IBeatmapOnlineInfo
[JsonIgnore]
public int CircleCount => OnlineInfo.CircleCount;
[JsonIgnore]
public int SliderCount => OnlineInfo.SliderCount;
[JsonIgnore]
public int PlayCount => OnlineInfo.PlayCount;
[JsonIgnore]
public int PassCount => OnlineInfo.PassCount;
[JsonIgnore]
public APIFailTimes FailTimes => OnlineInfo.FailTimes;
#endregion
} }
} }

View File

@ -6,10 +6,8 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Newtonsoft.Json;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
@ -32,13 +30,11 @@ namespace osu.Game.Beatmaps
public List<BeatmapInfo> Beatmaps { get; set; } public List<BeatmapInfo> Beatmaps { get; set; }
public BeatmapSetOnlineStatus Status { get; set; } = BeatmapSetOnlineStatus.None;
[NotNull] [NotNull]
public List<BeatmapSetFileInfo> Files { get; set; } = new List<BeatmapSetFileInfo>(); public List<BeatmapSetFileInfo> Files { get; set; } = new List<BeatmapSetFileInfo>();
// This field is temporary and only used by `APIBeatmapSet.ToBeatmapSet` (soon to be removed) and tests (to be updated to provide APIBeatmapSet instead).
[NotMapped]
public APIBeatmapSet OnlineInfo { get; set; }
/// <summary> /// <summary>
/// The maximum star difficulty of all beatmaps in this set. /// The maximum star difficulty of all beatmaps in this set.
/// </summary> /// </summary>
@ -100,80 +96,5 @@ namespace osu.Game.Beatmaps
IEnumerable<INamedFileUsage> IBeatmapSetInfo.Files => Files; IEnumerable<INamedFileUsage> IBeatmapSetInfo.Files => Files;
#endregion #endregion
#region Delegation for IBeatmapSetOnlineInfo
[NotMapped]
[JsonIgnore]
public DateTimeOffset Submitted => OnlineInfo.Submitted;
[NotMapped]
[JsonIgnore]
public DateTimeOffset? Ranked => OnlineInfo.Ranked;
[NotMapped]
[JsonIgnore]
public DateTimeOffset? LastUpdated => OnlineInfo.LastUpdated;
[JsonIgnore]
public BeatmapSetOnlineStatus Status { get; set; } = BeatmapSetOnlineStatus.None;
[NotMapped]
[JsonIgnore]
public bool HasExplicitContent => OnlineInfo.HasExplicitContent;
[NotMapped]
[JsonIgnore]
public bool HasVideo => OnlineInfo.HasVideo;
[NotMapped]
[JsonIgnore]
public bool HasStoryboard => OnlineInfo.HasStoryboard;
[NotMapped]
[JsonIgnore]
public BeatmapSetOnlineCovers Covers => OnlineInfo.Covers;
[NotMapped]
[JsonIgnore]
public string Preview => OnlineInfo.Preview;
[NotMapped]
[JsonIgnore]
public double BPM => OnlineInfo.BPM;
[NotMapped]
[JsonIgnore]
public int PlayCount => OnlineInfo.PlayCount;
[NotMapped]
[JsonIgnore]
public int FavouriteCount => OnlineInfo.FavouriteCount;
[NotMapped]
[JsonIgnore]
public bool HasFavourited => OnlineInfo.HasFavourited;
[NotMapped]
[JsonIgnore]
public BeatmapSetOnlineAvailability Availability => OnlineInfo.Availability;
[NotMapped]
[JsonIgnore]
public BeatmapSetOnlineGenre Genre => OnlineInfo.Genre;
[NotMapped]
[JsonIgnore]
public BeatmapSetOnlineLanguage Language => OnlineInfo.Language;
[NotMapped]
[JsonIgnore]
public int? TrackId => OnlineInfo?.TrackId;
[NotMapped]
[JsonIgnore]
public int[] Ratings => OnlineInfo?.Ratings;
#endregion
} }
} }

View File

@ -57,12 +57,7 @@ namespace osu.Game.Beatmaps.Drawables
return new OnlineBeatmapSetCover(online, beatmapSetCoverType); return new OnlineBeatmapSetCover(online, beatmapSetCoverType);
if (model is BeatmapInfo localModel) if (model is BeatmapInfo localModel)
{
if (localModel.BeatmapSet?.OnlineInfo != null)
return new OnlineBeatmapSetCover(localModel.BeatmapSet.OnlineInfo, beatmapSetCoverType);
return new BeatmapBackgroundSprite(beatmaps.GetWorkingBeatmap(localModel)); return new BeatmapBackgroundSprite(beatmaps.GetWorkingBeatmap(localModel));
}
return new BeatmapBackgroundSprite(beatmaps.DefaultBeatmap); return new BeatmapBackgroundSprite(beatmaps.DefaultBeatmap);
} }

View File

@ -128,7 +128,6 @@ namespace osu.Game.Online.API.Requests.Responses
OnlineBeatmapSetID = OnlineID, OnlineBeatmapSetID = OnlineID,
Metadata = metadata, Metadata = metadata,
Status = Status, Status = Status,
OnlineInfo = this
}; };
beatmapSet.Beatmaps = Beatmaps.Select(b => beatmapSet.Beatmaps = Beatmaps.Select(b =>

View File

@ -41,13 +41,13 @@ namespace osu.Game.Screens.Select
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private RulesetStore rulesets { get; set; }
private BeatmapInfo beatmapInfo; private IBeatmapInfo beatmapInfo;
private APIFailTimes failTimes; private APIFailTimes failTimes;
private int[] ratings; private int[] ratings;
public BeatmapInfo BeatmapInfo public IBeatmapInfo BeatmapInfo
{ {
get => beatmapInfo; get => beatmapInfo;
set set
@ -56,8 +56,11 @@ namespace osu.Game.Screens.Select
beatmapInfo = value; beatmapInfo = value;
failTimes = beatmapInfo?.OnlineInfo?.FailTimes; var onlineInfo = beatmapInfo as IBeatmapOnlineInfo;
ratings = beatmapInfo?.BeatmapSet?.OnlineInfo?.Ratings; var onlineSetInfo = beatmapInfo.BeatmapSet as IBeatmapSetOnlineInfo;
failTimes = onlineInfo?.FailTimes;
ratings = onlineSetInfo?.Ratings;
Scheduler.AddOnce(updateStatistics); Scheduler.AddOnce(updateStatistics);
} }
@ -178,9 +181,9 @@ namespace osu.Game.Screens.Select
private void updateStatistics() private void updateStatistics()
{ {
advanced.BeatmapInfo = BeatmapInfo; advanced.BeatmapInfo = BeatmapInfo;
description.Text = BeatmapInfo?.Version; description.Text = BeatmapInfo?.DifficultyName;
source.Text = BeatmapInfo?.Metadata?.Source; source.Text = BeatmapInfo?.Metadata.Source;
tags.Text = BeatmapInfo?.Metadata?.Tags; tags.Text = BeatmapInfo?.Metadata.Tags;
// failTimes may have been previously fetched // failTimes may have been previously fetched
if (ratings != null && failTimes != null) if (ratings != null && failTimes != null)
@ -190,7 +193,7 @@ namespace osu.Game.Screens.Select
} }
// for now, let's early abort if an OnlineBeatmapID is not present (should have been populated at import time). // for now, let's early abort if an OnlineBeatmapID is not present (should have been populated at import time).
if (BeatmapInfo?.OnlineBeatmapID == null || api.State.Value == APIState.Offline) if (BeatmapInfo == null || BeatmapInfo.OnlineID <= 0 || api.State.Value == APIState.Offline)
{ {
updateMetrics(); updateMetrics();
return; return;

View File

@ -39,16 +39,6 @@ namespace osu.Game.Tests.Beatmaps
BeatmapInfo.Length = 75000; BeatmapInfo.Length = 75000;
BeatmapInfo.OnlineInfo = new APIBeatmap(); BeatmapInfo.OnlineInfo = new APIBeatmap();
BeatmapInfo.OnlineBeatmapID = Interlocked.Increment(ref onlineBeatmapID); BeatmapInfo.OnlineBeatmapID = Interlocked.Increment(ref onlineBeatmapID);
BeatmapInfo.BeatmapSet.OnlineInfo = new APIBeatmapSet
{
Status = BeatmapSetOnlineStatus.Ranked,
Covers = new BeatmapSetOnlineCovers
{
Cover = "https://assets.ppy.sh/beatmaps/163112/covers/cover.jpg",
Card = "https://assets.ppy.sh/beatmaps/163112/covers/card.jpg",
List = "https://assets.ppy.sh/beatmaps/163112/covers/list.jpg"
}
};
} }
protected virtual Beatmap CreateBeatmap() => createTestBeatmap(); protected virtual Beatmap CreateBeatmap() => createTestBeatmap();

View File

@ -175,27 +175,42 @@ namespace osu.Game.Tests.Visual
protected virtual IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestBeatmap(ruleset); protected virtual IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestBeatmap(ruleset);
protected APIBeatmapSet CreateAPIBeatmapSet(RulesetInfo ruleset) /// <summary>
/// Returns a sample API Beatmap with BeatmapSet populated.
/// </summary>
/// <param name="ruleset">The ruleset to create the sample model using. osu! ruleset will be used if not specified.</param>
protected APIBeatmap CreateAPIBeatmap(RulesetInfo ruleset = null)
{ {
var beatmap = CreateBeatmap(ruleset).BeatmapInfo; var beatmapSet = CreateAPIBeatmapSet(ruleset ?? Ruleset.Value);
// Avoid circular reference.
var beatmap = beatmapSet.Beatmaps.First();
beatmapSet.Beatmaps = Array.Empty<APIBeatmap>();
// Populate the set as that's generally what we expect from the API.
beatmap.BeatmapSet = beatmapSet;
return beatmap;
}
/// <summary>
/// Returns a sample API BeatmapSet with beatmaps populated.
/// </summary>
/// <param name="ruleset">The ruleset to create the sample model using. osu! ruleset will be used if not specified.</param>
protected APIBeatmapSet CreateAPIBeatmapSet(RulesetInfo ruleset = null)
{
var beatmap = CreateBeatmap(ruleset ?? Ruleset.Value).BeatmapInfo;
return new APIBeatmapSet return new APIBeatmapSet
{ {
Covers = beatmap.BeatmapSet.Covers,
OnlineID = beatmap.BeatmapSet.OnlineID, OnlineID = beatmap.BeatmapSet.OnlineID,
Status = beatmap.BeatmapSet.Status, Status = BeatmapSetOnlineStatus.Ranked,
Preview = beatmap.BeatmapSet.Preview, Covers = new BeatmapSetOnlineCovers
HasFavourited = beatmap.BeatmapSet.HasFavourited, {
PlayCount = beatmap.BeatmapSet.PlayCount, Cover = "https://assets.ppy.sh/beatmaps/163112/covers/cover.jpg",
FavouriteCount = beatmap.BeatmapSet.FavouriteCount, Card = "https://assets.ppy.sh/beatmaps/163112/covers/card.jpg",
BPM = beatmap.BeatmapSet.BPM, List = "https://assets.ppy.sh/beatmaps/163112/covers/list.jpg"
HasExplicitContent = beatmap.BeatmapSet.HasExplicitContent, },
HasVideo = beatmap.BeatmapSet.HasVideo,
HasStoryboard = beatmap.BeatmapSet.HasStoryboard,
Submitted = beatmap.BeatmapSet.Submitted,
Ranked = beatmap.BeatmapSet.Ranked,
LastUpdated = beatmap.BeatmapSet.LastUpdated,
TrackId = beatmap.BeatmapSet.TrackId,
Title = beatmap.BeatmapSet.Metadata.Title, Title = beatmap.BeatmapSet.Metadata.Title,
TitleUnicode = beatmap.BeatmapSet.Metadata.TitleUnicode, TitleUnicode = beatmap.BeatmapSet.Metadata.TitleUnicode,
Artist = beatmap.BeatmapSet.Metadata.Artist, Artist = beatmap.BeatmapSet.Metadata.Artist,
@ -203,9 +218,6 @@ namespace osu.Game.Tests.Visual
Author = beatmap.BeatmapSet.Metadata.Author, Author = beatmap.BeatmapSet.Metadata.Author,
AuthorID = beatmap.BeatmapSet.Metadata.AuthorID, AuthorID = beatmap.BeatmapSet.Metadata.AuthorID,
AuthorString = beatmap.BeatmapSet.Metadata.AuthorString, AuthorString = beatmap.BeatmapSet.Metadata.AuthorString,
Availability = beatmap.BeatmapSet.Availability,
Genre = beatmap.BeatmapSet.Genre,
Language = beatmap.BeatmapSet.Language,
Source = beatmap.BeatmapSet.Metadata.Source, Source = beatmap.BeatmapSet.Metadata.Source,
Tags = beatmap.BeatmapSet.Metadata.Tags, Tags = beatmap.BeatmapSet.Metadata.Tags,
Beatmaps = new[] Beatmaps = new[]