mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Merge branch 'master' into importer-returns-live
This commit is contained in:
@ -242,7 +242,7 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
// GetDifficultyAsync will fall back to existing data from BeatmapInfo if not locally available
|
||||
// (contrary to GetAsync)
|
||||
GetDifficultyAsync(bindable.Beatmap, rulesetInfo, mods, cancellationToken)
|
||||
GetDifficultyAsync(bindable.BeatmapInfo, rulesetInfo, mods, cancellationToken)
|
||||
.ContinueWith(t =>
|
||||
{
|
||||
// We're on a threadpool thread, but we should exit back to the update thread so consumers can safely handle value-changed events.
|
||||
@ -262,7 +262,7 @@ namespace osu.Game.Beatmaps
|
||||
private StarDifficulty computeDifficulty(in DifficultyCacheLookup key)
|
||||
{
|
||||
// In the case that the user hasn't given us a ruleset, use the beatmap's default ruleset.
|
||||
var beatmapInfo = key.Beatmap;
|
||||
var beatmapInfo = key.BeatmapInfo;
|
||||
var rulesetInfo = key.Ruleset;
|
||||
|
||||
try
|
||||
@ -270,7 +270,7 @@ namespace osu.Game.Beatmaps
|
||||
var ruleset = rulesetInfo.CreateInstance();
|
||||
Debug.Assert(ruleset != null);
|
||||
|
||||
var calculator = ruleset.CreateDifficultyCalculator(beatmapManager.GetWorkingBeatmap(key.Beatmap));
|
||||
var calculator = ruleset.CreateDifficultyCalculator(beatmapManager.GetWorkingBeatmap(key.BeatmapInfo));
|
||||
var attributes = calculator.Calculate(key.OrderedMods);
|
||||
|
||||
return new StarDifficulty(attributes);
|
||||
@ -300,21 +300,21 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
public readonly struct DifficultyCacheLookup : IEquatable<DifficultyCacheLookup>
|
||||
{
|
||||
public readonly BeatmapInfo Beatmap;
|
||||
public readonly BeatmapInfo BeatmapInfo;
|
||||
public readonly RulesetInfo Ruleset;
|
||||
|
||||
public readonly Mod[] OrderedMods;
|
||||
|
||||
public DifficultyCacheLookup([NotNull] BeatmapInfo beatmap, [CanBeNull] RulesetInfo ruleset, IEnumerable<Mod> mods)
|
||||
public DifficultyCacheLookup([NotNull] BeatmapInfo beatmapInfo, [CanBeNull] RulesetInfo ruleset, IEnumerable<Mod> mods)
|
||||
{
|
||||
Beatmap = beatmap;
|
||||
BeatmapInfo = beatmapInfo;
|
||||
// In the case that the user hasn't given us a ruleset, use the beatmap's default ruleset.
|
||||
Ruleset = ruleset ?? Beatmap.Ruleset;
|
||||
Ruleset = ruleset ?? BeatmapInfo.Ruleset;
|
||||
OrderedMods = mods?.OrderBy(m => m.Acronym).Select(mod => mod.DeepClone()).ToArray() ?? Array.Empty<Mod>();
|
||||
}
|
||||
|
||||
public bool Equals(DifficultyCacheLookup other)
|
||||
=> Beatmap.ID == other.Beatmap.ID
|
||||
=> BeatmapInfo.ID == other.BeatmapInfo.ID
|
||||
&& Ruleset.ID == other.Ruleset.ID
|
||||
&& OrderedMods.SequenceEqual(other.OrderedMods);
|
||||
|
||||
@ -322,7 +322,7 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
var hashCode = new HashCode();
|
||||
|
||||
hashCode.Add(Beatmap.ID);
|
||||
hashCode.Add(BeatmapInfo.ID);
|
||||
hashCode.Add(Ruleset.ID);
|
||||
|
||||
foreach (var mod in OrderedMods)
|
||||
@ -334,12 +334,12 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
private class BindableStarDifficulty : Bindable<StarDifficulty?>
|
||||
{
|
||||
public readonly BeatmapInfo Beatmap;
|
||||
public readonly BeatmapInfo BeatmapInfo;
|
||||
public readonly CancellationToken CancellationToken;
|
||||
|
||||
public BindableStarDifficulty(BeatmapInfo beatmap, CancellationToken cancellationToken)
|
||||
public BindableStarDifficulty(BeatmapInfo beatmapInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
Beatmap = beatmap;
|
||||
BeatmapInfo = beatmapInfo;
|
||||
CancellationToken = cancellationToken;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ namespace osu.Game.Beatmaps
|
||||
private readonly BeatmapModelDownloader beatmapModelDownloader;
|
||||
|
||||
private readonly WorkingBeatmapCache workingBeatmapCache;
|
||||
private readonly BeatmapOnlineLookupQueue onlineBetamapLookupQueue;
|
||||
private readonly BeatmapOnlineLookupQueue onlineBeatmapLookupQueue;
|
||||
|
||||
public BeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, GameHost host = null,
|
||||
WorkingBeatmap defaultBeatmap = null, bool performOnlineLookups = false)
|
||||
@ -48,8 +48,8 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
if (performOnlineLookups)
|
||||
{
|
||||
onlineBetamapLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
|
||||
beatmapModelManager.OnlineLookupQueue = onlineBetamapLookupQueue;
|
||||
onlineBeatmapLookupQueue = new BeatmapOnlineLookupQueue(api, storage);
|
||||
beatmapModelManager.OnlineLookupQueue = onlineBeatmapLookupQueue;
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,14 +183,14 @@ namespace osu.Game.Beatmaps
|
||||
/// <summary>
|
||||
/// Delete a beatmap difficulty.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap difficulty to hide.</param>
|
||||
public void Hide(BeatmapInfo beatmap) => beatmapModelManager.Hide(beatmap);
|
||||
/// <param name="beatmapInfo">The beatmap difficulty to hide.</param>
|
||||
public void Hide(BeatmapInfo beatmapInfo) => beatmapModelManager.Hide(beatmapInfo);
|
||||
|
||||
/// <summary>
|
||||
/// Restore a beatmap difficulty.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap difficulty to restore.</param>
|
||||
public void Restore(BeatmapInfo beatmap) => beatmapModelManager.Restore(beatmap);
|
||||
/// <param name="beatmapInfo">The beatmap difficulty to restore.</param>
|
||||
public void Restore(BeatmapInfo beatmapInfo) => beatmapModelManager.Restore(beatmapInfo);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -330,7 +330,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
onlineBetamapLookupQueue?.Dispose();
|
||||
onlineBeatmapLookupQueue?.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -173,24 +173,24 @@ namespace osu.Game.Beatmaps
|
||||
/// <summary>
|
||||
/// Delete a beatmap difficulty.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap difficulty to hide.</param>
|
||||
public void Hide(BeatmapInfo beatmap) => beatmaps.Hide(beatmap);
|
||||
/// <param name="beatmapInfo">The beatmap difficulty to hide.</param>
|
||||
public void Hide(BeatmapInfo beatmapInfo) => beatmaps.Hide(beatmapInfo);
|
||||
|
||||
/// <summary>
|
||||
/// Restore a beatmap difficulty.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap difficulty to restore.</param>
|
||||
public void Restore(BeatmapInfo beatmap) => beatmaps.Restore(beatmap);
|
||||
/// <param name="beatmapInfo">The beatmap difficulty to restore.</param>
|
||||
public void Restore(BeatmapInfo beatmapInfo) => beatmaps.Restore(beatmapInfo);
|
||||
|
||||
/// <summary>
|
||||
/// Saves an <see cref="IBeatmap"/> file against a given <see cref="BeatmapInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="info">The <see cref="BeatmapInfo"/> to save the content against. The file referenced by <see cref="BeatmapInfo.Path"/> will be replaced.</param>
|
||||
/// <param name="beatmapInfo">The <see cref="BeatmapInfo"/> to save the content against. The file referenced by <see cref="BeatmapInfo.Path"/> will be replaced.</param>
|
||||
/// <param name="beatmapContent">The <see cref="IBeatmap"/> content to write.</param>
|
||||
/// <param name="beatmapSkin">The beatmap <see cref="ISkin"/> content to write, null if to be omitted.</param>
|
||||
public virtual void Save(BeatmapInfo info, IBeatmap beatmapContent, ISkin beatmapSkin = null)
|
||||
public virtual void Save(BeatmapInfo beatmapInfo, IBeatmap beatmapContent, ISkin beatmapSkin = null)
|
||||
{
|
||||
var setInfo = info.BeatmapSet;
|
||||
var setInfo = beatmapInfo.BeatmapSet;
|
||||
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
@ -201,7 +201,7 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
using (ContextFactory.GetForWrite())
|
||||
{
|
||||
var beatmapInfo = setInfo.Beatmaps.Single(b => b.ID == info.ID);
|
||||
beatmapInfo = setInfo.Beatmaps.Single(b => b.ID == beatmapInfo.ID);
|
||||
var metadata = beatmapInfo.Metadata ?? setInfo.Metadata;
|
||||
|
||||
// grab the original file (or create a new one if not found).
|
||||
@ -219,7 +219,7 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
}
|
||||
|
||||
WorkingBeatmapCache?.Invalidate(info);
|
||||
WorkingBeatmapCache?.Invalidate(beatmapInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -58,18 +58,18 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
|
||||
// todo: expose this when we need to do individual difficulty lookups.
|
||||
protected Task UpdateAsync(BeatmapSetInfo beatmapSet, BeatmapInfo beatmap, CancellationToken cancellationToken)
|
||||
=> Task.Factory.StartNew(() => lookup(beatmapSet, beatmap), cancellationToken, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
||||
protected Task UpdateAsync(BeatmapSetInfo beatmapSet, BeatmapInfo beatmapInfo, CancellationToken cancellationToken)
|
||||
=> Task.Factory.StartNew(() => lookup(beatmapSet, beatmapInfo), cancellationToken, TaskCreationOptions.HideScheduler | TaskCreationOptions.RunContinuationsAsynchronously, updateScheduler);
|
||||
|
||||
private void lookup(BeatmapSetInfo set, BeatmapInfo beatmap)
|
||||
private void lookup(BeatmapSetInfo set, BeatmapInfo beatmapInfo)
|
||||
{
|
||||
if (checkLocalCache(set, beatmap))
|
||||
if (checkLocalCache(set, beatmapInfo))
|
||||
return;
|
||||
|
||||
if (api?.State.Value != APIState.Online)
|
||||
return;
|
||||
|
||||
var req = new GetBeatmapRequest(beatmap);
|
||||
var req = new GetBeatmapRequest(beatmapInfo);
|
||||
|
||||
req.Failure += fail;
|
||||
|
||||
@ -82,18 +82,18 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
if (res != null)
|
||||
{
|
||||
beatmap.Status = res.Status;
|
||||
beatmap.BeatmapSet.Status = res.BeatmapSet.Status;
|
||||
beatmap.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID;
|
||||
beatmap.OnlineBeatmapID = res.OnlineBeatmapID;
|
||||
beatmapInfo.Status = res.Status;
|
||||
beatmapInfo.BeatmapSet.Status = res.BeatmapSet.Status;
|
||||
beatmapInfo.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID;
|
||||
beatmapInfo.OnlineBeatmapID = res.OnlineBeatmapID;
|
||||
|
||||
if (beatmap.Metadata != null)
|
||||
beatmap.Metadata.AuthorID = res.AuthorID;
|
||||
if (beatmapInfo.Metadata != null)
|
||||
beatmapInfo.Metadata.AuthorID = res.AuthorID;
|
||||
|
||||
if (beatmap.BeatmapSet.Metadata != null)
|
||||
beatmap.BeatmapSet.Metadata.AuthorID = res.AuthorID;
|
||||
if (beatmapInfo.BeatmapSet.Metadata != null)
|
||||
beatmapInfo.BeatmapSet.Metadata.AuthorID = res.AuthorID;
|
||||
|
||||
logForModel(set, $"Online retrieval mapped {beatmap} to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.");
|
||||
logForModel(set, $"Online retrieval mapped {beatmapInfo} to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
@ -103,8 +103,8 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
void fail(Exception e)
|
||||
{
|
||||
beatmap.OnlineBeatmapID = null;
|
||||
logForModel(set, $"Online retrieval failed for {beatmap} ({e.Message})");
|
||||
beatmapInfo.OnlineBeatmapID = null;
|
||||
logForModel(set, $"Online retrieval failed for {beatmapInfo} ({e.Message})");
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ namespace osu.Game.Beatmaps
|
||||
cacheDownloadRequest.PerformAsync();
|
||||
}
|
||||
|
||||
private bool checkLocalCache(BeatmapSetInfo set, BeatmapInfo beatmap)
|
||||
private bool checkLocalCache(BeatmapSetInfo set, BeatmapInfo beatmapInfo)
|
||||
{
|
||||
// download is in progress (or was, and failed).
|
||||
if (cacheDownloadRequest != null)
|
||||
@ -159,9 +159,9 @@ namespace osu.Game.Beatmaps
|
||||
if (!storage.Exists(cache_database_name))
|
||||
return false;
|
||||
|
||||
if (string.IsNullOrEmpty(beatmap.MD5Hash)
|
||||
&& string.IsNullOrEmpty(beatmap.Path)
|
||||
&& beatmap.OnlineBeatmapID == null)
|
||||
if (string.IsNullOrEmpty(beatmapInfo.MD5Hash)
|
||||
&& string.IsNullOrEmpty(beatmapInfo.Path)
|
||||
&& beatmapInfo.OnlineBeatmapID == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
@ -174,9 +174,9 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
cmd.CommandText = "SELECT beatmapset_id, beatmap_id, approved, user_id FROM osu_beatmaps WHERE checksum = @MD5Hash OR beatmap_id = @OnlineBeatmapID OR filename = @Path";
|
||||
|
||||
cmd.Parameters.Add(new SqliteParameter("@MD5Hash", beatmap.MD5Hash));
|
||||
cmd.Parameters.Add(new SqliteParameter("@OnlineBeatmapID", beatmap.OnlineBeatmapID ?? (object)DBNull.Value));
|
||||
cmd.Parameters.Add(new SqliteParameter("@Path", beatmap.Path));
|
||||
cmd.Parameters.Add(new SqliteParameter("@MD5Hash", beatmapInfo.MD5Hash));
|
||||
cmd.Parameters.Add(new SqliteParameter("@OnlineBeatmapID", beatmapInfo.OnlineBeatmapID ?? (object)DBNull.Value));
|
||||
cmd.Parameters.Add(new SqliteParameter("@Path", beatmapInfo.Path));
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
@ -184,18 +184,18 @@ namespace osu.Game.Beatmaps
|
||||
{
|
||||
var status = (BeatmapSetOnlineStatus)reader.GetByte(2);
|
||||
|
||||
beatmap.Status = status;
|
||||
beatmap.BeatmapSet.Status = status;
|
||||
beatmap.BeatmapSet.OnlineBeatmapSetID = reader.GetInt32(0);
|
||||
beatmap.OnlineBeatmapID = reader.GetInt32(1);
|
||||
beatmapInfo.Status = status;
|
||||
beatmapInfo.BeatmapSet.Status = status;
|
||||
beatmapInfo.BeatmapSet.OnlineBeatmapSetID = reader.GetInt32(0);
|
||||
beatmapInfo.OnlineBeatmapID = reader.GetInt32(1);
|
||||
|
||||
if (beatmap.Metadata != null)
|
||||
beatmap.Metadata.AuthorID = reader.GetInt32(3);
|
||||
if (beatmapInfo.Metadata != null)
|
||||
beatmapInfo.Metadata.AuthorID = reader.GetInt32(3);
|
||||
|
||||
if (beatmap.BeatmapSet.Metadata != null)
|
||||
beatmap.BeatmapSet.Metadata.AuthorID = reader.GetInt32(3);
|
||||
if (beatmapInfo.BeatmapSet.Metadata != null)
|
||||
beatmapInfo.BeatmapSet.Metadata.AuthorID = reader.GetInt32(3);
|
||||
|
||||
logForModel(set, $"Cached local retrieval for {beatmap}.");
|
||||
logForModel(set, $"Cached local retrieval for {beatmapInfo}.");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -204,7 +204,7 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logForModel(set, $"Cached local retrieval for {beatmap} failed with {ex}.");
|
||||
logForModel(set, $"Cached local retrieval for {beatmapInfo} failed with {ex}.");
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -25,40 +25,40 @@ namespace osu.Game.Beatmaps
|
||||
/// <summary>
|
||||
/// Hide a <see cref="BeatmapInfo"/> in the database.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap to hide.</param>
|
||||
/// <param name="beatmapInfo">The beatmap to hide.</param>
|
||||
/// <returns>Whether the beatmap's <see cref="BeatmapInfo.Hidden"/> was changed.</returns>
|
||||
public bool Hide(BeatmapInfo beatmap)
|
||||
public bool Hide(BeatmapInfo beatmapInfo)
|
||||
{
|
||||
using (ContextFactory.GetForWrite())
|
||||
{
|
||||
Refresh(ref beatmap, Beatmaps);
|
||||
Refresh(ref beatmapInfo, Beatmaps);
|
||||
|
||||
if (beatmap.Hidden) return false;
|
||||
if (beatmapInfo.Hidden) return false;
|
||||
|
||||
beatmap.Hidden = true;
|
||||
beatmapInfo.Hidden = true;
|
||||
}
|
||||
|
||||
BeatmapHidden?.Invoke(beatmap);
|
||||
BeatmapHidden?.Invoke(beatmapInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restore a previously hidden <see cref="BeatmapInfo"/>.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap to restore.</param>
|
||||
/// <param name="beatmapInfo">The beatmap to restore.</param>
|
||||
/// <returns>Whether the beatmap's <see cref="BeatmapInfo.Hidden"/> was changed.</returns>
|
||||
public bool Restore(BeatmapInfo beatmap)
|
||||
public bool Restore(BeatmapInfo beatmapInfo)
|
||||
{
|
||||
using (ContextFactory.GetForWrite())
|
||||
{
|
||||
Refresh(ref beatmap, Beatmaps);
|
||||
Refresh(ref beatmapInfo, Beatmaps);
|
||||
|
||||
if (!beatmap.Hidden) return false;
|
||||
if (!beatmapInfo.Hidden) return false;
|
||||
|
||||
beatmap.Hidden = false;
|
||||
beatmapInfo.Hidden = false;
|
||||
}
|
||||
|
||||
BeatmapRestored?.Invoke(beatmap);
|
||||
BeatmapRestored?.Invoke(beatmapInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -62,14 +62,14 @@ namespace osu.Game.Beatmaps
|
||||
if (!recommendedDifficultyMapping.TryGetValue(r, out var recommendation))
|
||||
continue;
|
||||
|
||||
BeatmapInfo beatmap = beatmaps.Where(b => b.Ruleset.Equals(r)).OrderBy(b =>
|
||||
BeatmapInfo beatmapInfo = beatmaps.Where(b => b.Ruleset.Equals(r)).OrderBy(b =>
|
||||
{
|
||||
var difference = b.StarDifficulty - recommendation;
|
||||
return difference >= 0 ? difference * 2 : difference * -1; // prefer easier over harder
|
||||
}).FirstOrDefault();
|
||||
|
||||
if (beatmap != null)
|
||||
return beatmap;
|
||||
if (beatmapInfo != null)
|
||||
return beatmapInfo;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -37,7 +37,7 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
}
|
||||
|
||||
[NotNull]
|
||||
private readonly BeatmapInfo beatmap;
|
||||
private readonly BeatmapInfo beatmapInfo;
|
||||
|
||||
[CanBeNull]
|
||||
private readonly RulesetInfo ruleset;
|
||||
@ -56,26 +56,26 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DifficultyIcon"/> with a given <see cref="RulesetInfo"/> and <see cref="Mod"/> combination.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap to show the difficulty of.</param>
|
||||
/// <param name="beatmapInfo">The beatmap to show the difficulty of.</param>
|
||||
/// <param name="ruleset">The ruleset to show the difficulty with.</param>
|
||||
/// <param name="mods">The mods to show the difficulty with.</param>
|
||||
/// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param>
|
||||
public DifficultyIcon([NotNull] BeatmapInfo beatmap, [CanBeNull] RulesetInfo ruleset, [CanBeNull] IReadOnlyList<Mod> mods, bool shouldShowTooltip = true)
|
||||
: this(beatmap, shouldShowTooltip)
|
||||
public DifficultyIcon([NotNull] BeatmapInfo beatmapInfo, [CanBeNull] RulesetInfo ruleset, [CanBeNull] IReadOnlyList<Mod> mods, bool shouldShowTooltip = true)
|
||||
: this(beatmapInfo, shouldShowTooltip)
|
||||
{
|
||||
this.ruleset = ruleset ?? beatmap.Ruleset;
|
||||
this.ruleset = ruleset ?? beatmapInfo.Ruleset;
|
||||
this.mods = mods ?? Array.Empty<Mod>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="DifficultyIcon"/> that follows the currently-selected ruleset and mods.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap to show the difficulty of.</param>
|
||||
/// <param name="beatmapInfo">The beatmap to show the difficulty of.</param>
|
||||
/// <param name="shouldShowTooltip">Whether to display a tooltip when hovered.</param>
|
||||
/// <param name="performBackgroundDifficultyLookup">Whether to perform difficulty lookup (including calculation if necessary).</param>
|
||||
public DifficultyIcon([NotNull] BeatmapInfo beatmap, bool shouldShowTooltip = true, bool performBackgroundDifficultyLookup = true)
|
||||
public DifficultyIcon([NotNull] BeatmapInfo beatmapInfo, bool shouldShowTooltip = true, bool performBackgroundDifficultyLookup = true)
|
||||
{
|
||||
this.beatmap = beatmap ?? throw new ArgumentNullException(nameof(beatmap));
|
||||
this.beatmapInfo = beatmapInfo ?? throw new ArgumentNullException(nameof(beatmapInfo));
|
||||
this.shouldShowTooltip = shouldShowTooltip;
|
||||
this.performBackgroundDifficultyLookup = performBackgroundDifficultyLookup;
|
||||
|
||||
@ -105,7 +105,7 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
Child = background = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = colours.ForStarDifficulty(beatmap.StarDifficulty) // Default value that will be re-populated once difficulty calculation completes
|
||||
Colour = colours.ForStarDifficulty(beatmapInfo.StarDifficulty) // Default value that will be re-populated once difficulty calculation completes
|
||||
},
|
||||
},
|
||||
new ConstrainedIconContainer
|
||||
@ -114,27 +114,27 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
// the null coalesce here is only present to make unit tests work (ruleset dlls aren't copied correctly for testing at the moment)
|
||||
Icon = (ruleset ?? beatmap.Ruleset)?.CreateInstance()?.CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle }
|
||||
Icon = (ruleset ?? beatmapInfo.Ruleset)?.CreateInstance()?.CreateIcon() ?? new SpriteIcon { Icon = FontAwesome.Regular.QuestionCircle }
|
||||
},
|
||||
};
|
||||
|
||||
if (performBackgroundDifficultyLookup)
|
||||
iconContainer.Add(new DelayedLoadUnloadWrapper(() => new DifficultyRetriever(beatmap, ruleset, mods) { StarDifficulty = { BindTarget = difficultyBindable } }, 0));
|
||||
iconContainer.Add(new DelayedLoadUnloadWrapper(() => new DifficultyRetriever(beatmapInfo, ruleset, mods) { StarDifficulty = { BindTarget = difficultyBindable } }, 0));
|
||||
else
|
||||
difficultyBindable.Value = new StarDifficulty(beatmap.StarDifficulty, 0);
|
||||
difficultyBindable.Value = new StarDifficulty(beatmapInfo.StarDifficulty, 0);
|
||||
|
||||
difficultyBindable.BindValueChanged(difficulty => background.Colour = colours.ForStarDifficulty(difficulty.NewValue.Stars));
|
||||
}
|
||||
|
||||
ITooltip<DifficultyIconTooltipContent> IHasCustomTooltip<DifficultyIconTooltipContent>.GetCustomTooltip() => new DifficultyIconTooltip();
|
||||
|
||||
DifficultyIconTooltipContent IHasCustomTooltip<DifficultyIconTooltipContent>.TooltipContent => shouldShowTooltip ? new DifficultyIconTooltipContent(beatmap, difficultyBindable) : null;
|
||||
DifficultyIconTooltipContent IHasCustomTooltip<DifficultyIconTooltipContent>.TooltipContent => shouldShowTooltip ? new DifficultyIconTooltipContent(beatmapInfo, difficultyBindable) : null;
|
||||
|
||||
private class DifficultyRetriever : Component
|
||||
{
|
||||
public readonly Bindable<StarDifficulty> StarDifficulty = new Bindable<StarDifficulty>();
|
||||
|
||||
private readonly BeatmapInfo beatmap;
|
||||
private readonly BeatmapInfo beatmapInfo;
|
||||
private readonly RulesetInfo ruleset;
|
||||
private readonly IReadOnlyList<Mod> mods;
|
||||
|
||||
@ -143,9 +143,9 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
[Resolved]
|
||||
private BeatmapDifficultyCache difficultyCache { get; set; }
|
||||
|
||||
public DifficultyRetriever(BeatmapInfo beatmap, RulesetInfo ruleset, IReadOnlyList<Mod> mods)
|
||||
public DifficultyRetriever(BeatmapInfo beatmapInfo, RulesetInfo ruleset, IReadOnlyList<Mod> mods)
|
||||
{
|
||||
this.beatmap = beatmap;
|
||||
this.beatmapInfo = beatmapInfo;
|
||||
this.ruleset = ruleset;
|
||||
this.mods = mods;
|
||||
}
|
||||
@ -157,8 +157,8 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
{
|
||||
difficultyCancellation = new CancellationTokenSource();
|
||||
localStarDifficulty = ruleset != null
|
||||
? difficultyCache.GetBindableDifficulty(beatmap, ruleset, mods, difficultyCancellation.Token)
|
||||
: difficultyCache.GetBindableDifficulty(beatmap, difficultyCancellation.Token);
|
||||
? difficultyCache.GetBindableDifficulty(beatmapInfo, ruleset, mods, difficultyCancellation.Token)
|
||||
: difficultyCache.GetBindableDifficulty(beatmapInfo, difficultyCancellation.Token);
|
||||
localStarDifficulty.BindValueChanged(d =>
|
||||
{
|
||||
if (d.NewValue is StarDifficulty diff)
|
||||
|
@ -89,7 +89,7 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
|
||||
public void SetContent(DifficultyIconTooltipContent content)
|
||||
{
|
||||
difficultyName.Text = content.Beatmap.Version;
|
||||
difficultyName.Text = content.BeatmapInfo.Version;
|
||||
|
||||
starDifficulty.UnbindAll();
|
||||
starDifficulty.BindTo(content.Difficulty);
|
||||
@ -109,12 +109,12 @@ namespace osu.Game.Beatmaps.Drawables
|
||||
|
||||
internal class DifficultyIconTooltipContent
|
||||
{
|
||||
public readonly BeatmapInfo Beatmap;
|
||||
public readonly BeatmapInfo BeatmapInfo;
|
||||
public readonly IBindable<StarDifficulty> Difficulty;
|
||||
|
||||
public DifficultyIconTooltipContent(BeatmapInfo beatmap, IBindable<StarDifficulty> difficulty)
|
||||
public DifficultyIconTooltipContent(BeatmapInfo beatmapInfo, IBindable<StarDifficulty> difficulty)
|
||||
{
|
||||
Beatmap = beatmap;
|
||||
BeatmapInfo = beatmapInfo;
|
||||
Difficulty = difficulty;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user