1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-26 16:12:54 +08:00

Expose more of WorkingBeatmap via interface

This commit is contained in:
Dean Herbert 2021-11-15 18:24:00 +09:00
parent da75329f0c
commit a0e25d18cd
2 changed files with 66 additions and 20 deletions

View File

@ -17,33 +17,69 @@ namespace osu.Game.Beatmaps
{ {
public interface IWorkingBeatmap public interface IWorkingBeatmap
{ {
IBeatmapInfo BeatmapInfo { get; }
IBeatmapSetInfo BeatmapSetInfo => BeatmapInfo.BeatmapSet;
IBeatmapMetadataInfo Metadata => BeatmapInfo.Metadata;
/// <summary> /// <summary>
/// Retrieves the <see cref="IBeatmap"/> which this <see cref="WorkingBeatmap"/> represents. /// Whether the Beatmap has finished loading.
///</summary>
public bool BeatmapLoaded { get; }
/// <summary>
/// Whether the Background has finished loading.
///</summary>
public bool BackgroundLoaded { get; }
/// <summary>
/// Whether the Waveform has finished loading.
///</summary>
public bool WaveformLoaded { get; }
/// <summary>
/// Whether the Storyboard has finished loading.
///</summary>
public bool StoryboardLoaded { get; }
/// <summary>
/// Whether the Skin has finished loading.
///</summary>
public bool SkinLoaded { get; }
/// <summary>
/// Whether the Track has finished loading.
///</summary>
public bool TrackLoaded { get; }
/// <summary>
/// Retrieves the <see cref="IBeatmap"/> which this <see cref="IWorkingBeatmap"/> represents.
/// </summary> /// </summary>
IBeatmap Beatmap { get; } IBeatmap Beatmap { get; }
/// <summary> /// <summary>
/// Retrieves the background for this <see cref="WorkingBeatmap"/>. /// Retrieves the background for this <see cref="IWorkingBeatmap"/>.
/// </summary> /// </summary>
Texture Background { get; } Texture Background { get; }
/// <summary> /// <summary>
/// Retrieves the <see cref="Waveform"/> for the <see cref="Track"/> of this <see cref="WorkingBeatmap"/>. /// Retrieves the <see cref="Waveform"/> for the <see cref="Track"/> of this <see cref="IWorkingBeatmap"/>.
/// </summary> /// </summary>
Waveform Waveform { get; } Waveform Waveform { get; }
/// <summary> /// <summary>
/// Retrieves the <see cref="Storyboard"/> which this <see cref="WorkingBeatmap"/> provides. /// Retrieves the <see cref="Storyboard"/> which this <see cref="IWorkingBeatmap"/> provides.
/// </summary> /// </summary>
Storyboard Storyboard { get; } Storyboard Storyboard { get; }
/// <summary> /// <summary>
/// Retrieves the <see cref="Skin"/> which this <see cref="WorkingBeatmap"/> provides. /// Retrieves the <see cref="Skin"/> which this <see cref="IWorkingBeatmap"/> provides.
/// </summary> /// </summary>
ISkin Skin { get; } ISkin Skin { get; }
/// <summary> /// <summary>
/// Retrieves the <see cref="Track"/> which this <see cref="WorkingBeatmap"/> has loaded. /// Retrieves the <see cref="Track"/> which this <see cref="IWorkingBeatmap"/> has loaded.
/// </summary> /// </summary>
Track Track { get; } Track Track { get; }
@ -67,7 +103,7 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// In a standard game context, the loading of the track is managed solely by MusicController, which will /// In a standard game context, the loading of the track is managed solely by MusicController, which will
/// automatically load the track of the current global IBindable WorkingBeatmap. /// automatically load the track of the current global IBindable IWorkingBeatmap.
/// As such, this method should only be called in very special scenarios, such as external tests or apps which are /// As such, this method should only be called in very special scenarios, such as external tests or apps which are
/// outside of the game context. /// outside of the game context.
/// </remarks> /// </remarks>
@ -79,5 +115,20 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
/// <param name="storagePath">The storage path to the file.</param> /// <param name="storagePath">The storage path to the file.</param>
Stream GetStream(string storagePath); Stream GetStream(string storagePath);
/// <summary>
/// Beings loading the contents of this <see cref="IWorkingBeatmap"/> asynchronously.
/// </summary>
public void BeginAsyncLoad();
/// <summary>
/// Cancels the asynchronous loading of the contents of this <see cref="IWorkingBeatmap"/>.
/// </summary>
public void CancelAsyncLoad();
/// <summary>
/// Reads the correct track restart point from beatmap metadata and sets looping to enabled.
/// </summary>
void PrepareTrackForPreviewLooping();
} }
} }

View File

@ -28,8 +28,10 @@ namespace osu.Game.Beatmaps
{ {
public readonly BeatmapInfo BeatmapInfo; public readonly BeatmapInfo BeatmapInfo;
// ReSharper disable once FieldHidesInterfacePropertyWithDefaultImplementation
public readonly BeatmapSetInfo BeatmapSetInfo; public readonly BeatmapSetInfo BeatmapSetInfo;
// ReSharper disable once FieldHidesInterfacePropertyWithDefaultImplementation
public readonly BeatmapMetadata Metadata; public readonly BeatmapMetadata Metadata;
protected AudioManager AudioManager { get; } protected AudioManager AudioManager { get; }
@ -89,6 +91,9 @@ namespace osu.Game.Beatmaps
var rulesetInstance = ruleset.CreateInstance(); var rulesetInstance = ruleset.CreateInstance();
if (rulesetInstance == null)
throw new RulesetLoadException("Creating ruleset instance failed when attempting to create playable beatmap.");
IBeatmapConverter converter = CreateBeatmapConverter(Beatmap, rulesetInstance); IBeatmapConverter converter = CreateBeatmapConverter(Beatmap, rulesetInstance);
// Check if the beatmap can be converted // Check if the beatmap can be converted
@ -176,17 +181,8 @@ namespace osu.Game.Beatmaps
private CancellationTokenSource loadCancellation = new CancellationTokenSource(); private CancellationTokenSource loadCancellation = new CancellationTokenSource();
/// <summary> public void BeginAsyncLoad() => loadBeatmapAsync();
/// Beings loading the contents of this <see cref="WorkingBeatmap"/> asynchronously.
/// </summary>
public void BeginAsyncLoad()
{
loadBeatmapAsync();
}
/// <summary>
/// Cancels the asynchronous loading of the contents of this <see cref="WorkingBeatmap"/>.
/// </summary>
public void CancelAsyncLoad() public void CancelAsyncLoad()
{ {
lock (beatmapFetchLock) lock (beatmapFetchLock)
@ -234,6 +230,8 @@ namespace osu.Game.Beatmaps
public virtual bool BeatmapLoaded => beatmapLoadTask?.IsCompleted ?? false; public virtual bool BeatmapLoaded => beatmapLoadTask?.IsCompleted ?? false;
IBeatmapInfo IWorkingBeatmap.BeatmapInfo => BeatmapInfo;
public IBeatmap Beatmap public IBeatmap Beatmap
{ {
get get
@ -273,9 +271,6 @@ namespace osu.Game.Beatmaps
[NotNull] [NotNull]
public Track LoadTrack() => loadedTrack = GetBeatmapTrack() ?? GetVirtualTrack(1000); public Track LoadTrack() => loadedTrack = GetBeatmapTrack() ?? GetVirtualTrack(1000);
/// <summary>
/// Reads the correct track restart point from beatmap metadata and sets looping to enabled.
/// </summary>
public void PrepareTrackForPreviewLooping() public void PrepareTrackForPreviewLooping()
{ {
Track.Looping = true; Track.Looping = true;