2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-05-23 08:37:39 +00:00
|
|
|
|
|
2018-05-23 09:52:09 +00:00
|
|
|
|
using System.Diagnostics;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-05-23 08:37:39 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-02-21 10:04:31 +00:00
|
|
|
|
/// A <see cref="Bindable{T}"/> for the <see cref="OsuGame"/> beatmap.
|
2019-04-25 08:36:17 +00:00
|
|
|
|
/// This should be used sparingly in-favour of <see cref="IBindable{WorkingBeatmap}"/>.
|
2018-05-23 08:37:39 +00:00
|
|
|
|
/// </summary>
|
2019-02-01 06:42:15 +00:00
|
|
|
|
public abstract class BindableBeatmap : NonNullableBindable<WorkingBeatmap>
|
2018-05-23 08:37:39 +00:00
|
|
|
|
{
|
2018-05-23 09:52:09 +00:00
|
|
|
|
private WorkingBeatmap lastBeatmap;
|
|
|
|
|
|
2019-05-31 05:40:53 +00:00
|
|
|
|
protected BindableBeatmap(WorkingBeatmap defaultValue)
|
2018-05-23 08:37:39 +00:00
|
|
|
|
: base(defaultValue)
|
|
|
|
|
{
|
2019-05-31 05:40:53 +00:00
|
|
|
|
BindValueChanged(b => updateAudioTrack(b.NewValue), true);
|
2018-05-23 09:52:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 14:54:42 +00:00
|
|
|
|
private void updateAudioTrack(WorkingBeatmap beatmap)
|
2018-05-23 09:52:09 +00:00
|
|
|
|
{
|
|
|
|
|
var trackLoaded = lastBeatmap?.TrackLoaded ?? false;
|
|
|
|
|
|
|
|
|
|
// compare to last beatmap as sometimes the two may share a track representation (optimisation, see WorkingBeatmap.TransferTo)
|
|
|
|
|
if (!trackLoaded || lastBeatmap?.Track != beatmap.Track)
|
|
|
|
|
{
|
|
|
|
|
if (trackLoaded)
|
|
|
|
|
{
|
|
|
|
|
Debug.Assert(lastBeatmap != null);
|
|
|
|
|
Debug.Assert(lastBeatmap.Track != null);
|
|
|
|
|
|
|
|
|
|
lastBeatmap.RecycleTrack();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lastBeatmap = beatmap;
|
2018-05-23 08:37:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|