mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 02:02:53 +08:00
populate Status for Beatmap + BeatmapSet
also added Status to APIBeatmap + APIBeatmapSet
This commit is contained in:
parent
5414ce9932
commit
638a2e5ba8
@ -35,7 +35,7 @@ namespace osu.Game.Beatmaps
|
|||||||
public int BeatmapSetInfoID { get; set; }
|
public int BeatmapSetInfoID { get; set; }
|
||||||
|
|
||||||
public BeatmapSetOnlineStatus Status { get; set; } = BeatmapSetOnlineStatus.None;
|
public BeatmapSetOnlineStatus Status { get; set; } = BeatmapSetOnlineStatus.None;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public BeatmapSetInfo BeatmapSet { get; set; }
|
public BeatmapSetInfo BeatmapSet { get; set; }
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
@ -104,7 +104,7 @@ namespace osu.Game.Beatmaps
|
|||||||
validateOnlineIds(beatmapSet.Beatmaps);
|
validateOnlineIds(beatmapSet.Beatmaps);
|
||||||
|
|
||||||
foreach (BeatmapInfo b in beatmapSet.Beatmaps)
|
foreach (BeatmapInfo b in beatmapSet.Beatmaps)
|
||||||
fetchAndPopulateOnlineIDs(b, beatmapSet.Beatmaps);
|
fetchAndPopulateOnlineValues(b, beatmapSet.Beatmaps);
|
||||||
|
|
||||||
// check if a set already exists with the same online id, delete if it does.
|
// check if a set already exists with the same online id, delete if it does.
|
||||||
if (beatmapSet.OnlineBeatmapSetID != null)
|
if (beatmapSet.OnlineBeatmapSetID != null)
|
||||||
@ -388,21 +388,22 @@ namespace osu.Game.Beatmaps
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Query the API to populate mising OnlineBeatmapID / OnlineBeatmapSetID properties.
|
/// Query the API to populate missing values like OnlineBeatmapID / OnlineBeatmapSetID or (Rank-)Status.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmap">The beatmap to populate.</param>
|
/// <param name="beatmap">The beatmap to populate.</param>
|
||||||
/// <param name="otherBeatmaps">The other beatmaps contained within this set.</param>
|
/// <param name="otherBeatmaps">The other beatmaps contained within this set.</param>
|
||||||
/// <param name="force">Whether to re-query if the provided beatmap already has populated values.</param>
|
/// <param name="force">Whether to re-query if the provided beatmap already has populated values.</param>
|
||||||
/// <returns>True if population was successful.</returns>
|
/// <returns>True if population was successful.</returns>
|
||||||
private bool fetchAndPopulateOnlineIDs(BeatmapInfo beatmap, IEnumerable<BeatmapInfo> otherBeatmaps, bool force = false)
|
private bool fetchAndPopulateOnlineValues(BeatmapInfo beatmap, IEnumerable<BeatmapInfo> otherBeatmaps, bool force = false)
|
||||||
{
|
{
|
||||||
if (api?.State != APIState.Online)
|
if (api?.State != APIState.Online)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!force && beatmap.OnlineBeatmapID != null && beatmap.BeatmapSet.OnlineBeatmapSetID != null)
|
if (!force && beatmap.OnlineBeatmapID != null && beatmap.BeatmapSet.OnlineBeatmapSetID != null
|
||||||
|
&& beatmap.Status != BeatmapSetOnlineStatus.None && beatmap.BeatmapSet.Status != BeatmapSetOnlineStatus.None)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Logger.Log("Attempting online lookup for IDs...", LoggingTarget.Database);
|
Logger.Log("Attempting online lookup for the missing values...", LoggingTarget.Database);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -414,6 +415,9 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
Logger.Log($"Successfully mapped to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.", LoggingTarget.Database);
|
Logger.Log($"Successfully mapped to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.", LoggingTarget.Database);
|
||||||
|
|
||||||
|
beatmap.Status = res.Status;
|
||||||
|
beatmap.BeatmapSet.Status = res.BeatmapSet.Status;
|
||||||
|
|
||||||
if (otherBeatmaps.Any(b => b.OnlineBeatmapID == res.OnlineBeatmapID))
|
if (otherBeatmaps.Any(b => b.OnlineBeatmapID == res.OnlineBeatmapID))
|
||||||
{
|
{
|
||||||
Logger.Log("Another beatmap in the same set already mapped to this ID. We'll skip adding it this time.", LoggingTarget.Database);
|
Logger.Log("Another beatmap in the same set already mapped to this ID. We'll skip adding it this time.", LoggingTarget.Database);
|
||||||
@ -422,6 +426,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
beatmap.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID;
|
beatmap.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID;
|
||||||
beatmap.OnlineBeatmapID = res.OnlineBeatmapID;
|
beatmap.OnlineBeatmapID = res.OnlineBeatmapID;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -20,7 +20,7 @@ namespace osu.Game.Beatmaps
|
|||||||
get => onlineBeatmapSetID;
|
get => onlineBeatmapSetID;
|
||||||
set => onlineBeatmapSetID = value > 0 ? value : null;
|
set => onlineBeatmapSetID = value > 0 ? value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BeatmapSetOnlineStatus Status { get; set; } = BeatmapSetOnlineStatus.None;
|
public BeatmapSetOnlineStatus Status { get; set; } = BeatmapSetOnlineStatus.None;
|
||||||
|
|
||||||
public BeatmapMetadata Metadata { get; set; }
|
public BeatmapMetadata Metadata { get; set; }
|
||||||
|
@ -15,6 +15,12 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
[JsonProperty(@"beatmapset_id")]
|
[JsonProperty(@"beatmapset_id")]
|
||||||
public int OnlineBeatmapSetID { get; set; }
|
public int OnlineBeatmapSetID { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"status")]
|
||||||
|
public BeatmapSetOnlineStatus Status { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty(@"beatmapset")]
|
||||||
|
public APIBeatmapSet BeatmapSet { get; set; }
|
||||||
|
|
||||||
[JsonProperty(@"playcount")]
|
[JsonProperty(@"playcount")]
|
||||||
private int playCount { get; set; }
|
private int playCount { get; set; }
|
||||||
|
|
||||||
@ -59,11 +65,13 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
Ruleset = rulesets.GetRuleset(ruleset),
|
Ruleset = rulesets.GetRuleset(ruleset),
|
||||||
StarDifficulty = starDifficulty,
|
StarDifficulty = starDifficulty,
|
||||||
OnlineBeatmapID = OnlineBeatmapID,
|
OnlineBeatmapID = OnlineBeatmapID,
|
||||||
|
Version = version,
|
||||||
|
Status = Status,
|
||||||
BeatmapSet = new BeatmapSetInfo
|
BeatmapSet = new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
OnlineBeatmapSetID = OnlineBeatmapSetID,
|
OnlineBeatmapSetID = OnlineBeatmapSetID,
|
||||||
|
Status = BeatmapSet?.Status ?? BeatmapSetOnlineStatus.None
|
||||||
},
|
},
|
||||||
Version = version,
|
|
||||||
BaseDifficulty = new BeatmapDifficulty
|
BaseDifficulty = new BeatmapDifficulty
|
||||||
{
|
{
|
||||||
DrainRate = drainRate,
|
DrainRate = drainRate,
|
||||||
|
@ -20,10 +20,13 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
[JsonProperty(@"id")]
|
[JsonProperty(@"id")]
|
||||||
public int? OnlineBeatmapSetID
|
public int? OnlineBeatmapSetID
|
||||||
{
|
{
|
||||||
get { return onlineBeatmapSetID; }
|
get => onlineBeatmapSetID;
|
||||||
set { onlineBeatmapSetID = value > 0 ? value : null; }
|
set => onlineBeatmapSetID = value > 0 ? value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[JsonProperty(@"status")]
|
||||||
|
public BeatmapSetOnlineStatus Status { get; set; }
|
||||||
|
|
||||||
[JsonProperty(@"preview_url")]
|
[JsonProperty(@"preview_url")]
|
||||||
private string preview { get; set; }
|
private string preview { get; set; }
|
||||||
|
|
||||||
@ -42,9 +45,6 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
[JsonProperty(@"storyboard")]
|
[JsonProperty(@"storyboard")]
|
||||||
private bool hasStoryboard { get; set; }
|
private bool hasStoryboard { get; set; }
|
||||||
|
|
||||||
[JsonProperty(@"status")]
|
|
||||||
private BeatmapSetOnlineStatus status { get; set; }
|
|
||||||
|
|
||||||
[JsonProperty(@"submitted_date")]
|
[JsonProperty(@"submitted_date")]
|
||||||
private DateTimeOffset submitted { get; set; }
|
private DateTimeOffset submitted { get; set; }
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
[JsonProperty(@"user_id")]
|
[JsonProperty(@"user_id")]
|
||||||
private long creatorId
|
private long creatorId
|
||||||
{
|
{
|
||||||
set { Author.Id = value; }
|
set => Author.Id = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty(@"beatmaps")]
|
[JsonProperty(@"beatmaps")]
|
||||||
@ -69,6 +69,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
{
|
{
|
||||||
OnlineBeatmapSetID = OnlineBeatmapSetID,
|
OnlineBeatmapSetID = OnlineBeatmapSetID,
|
||||||
Metadata = this,
|
Metadata = this,
|
||||||
|
Status = Status,
|
||||||
OnlineInfo = new BeatmapSetOnlineInfo
|
OnlineInfo = new BeatmapSetOnlineInfo
|
||||||
{
|
{
|
||||||
Covers = covers,
|
Covers = covers,
|
||||||
@ -76,7 +77,7 @@ namespace osu.Game.Online.API.Requests.Responses
|
|||||||
PlayCount = playCount,
|
PlayCount = playCount,
|
||||||
FavouriteCount = favouriteCount,
|
FavouriteCount = favouriteCount,
|
||||||
BPM = bpm,
|
BPM = bpm,
|
||||||
Status = status,
|
Status = Status,
|
||||||
HasVideo = hasVideo,
|
HasVideo = hasVideo,
|
||||||
HasStoryboard = hasStoryboard,
|
HasStoryboard = hasStoryboard,
|
||||||
Submitted = submitted,
|
Submitted = submitted,
|
||||||
|
Loading…
Reference in New Issue
Block a user