1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 16:07:25 +08:00
osu-lazer/osu.Game/Beatmaps/BindableBeatmap.cs

43 lines
1.4 KiB
C#
Raw Normal View History

// 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.
using System.Diagnostics;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
namespace osu.Game.Beatmaps
{
/// <summary>
2019-02-21 18:04:31 +08:00
/// A <see cref="Bindable{T}"/> for the <see cref="OsuGame"/> beatmap.
2019-04-25 16:36:17 +08:00
/// This should be used sparingly in-favour of <see cref="IBindable{WorkingBeatmap}"/>.
/// </summary>
2019-02-01 14:42:15 +08:00
public abstract class BindableBeatmap : NonNullableBindable<WorkingBeatmap>
{
private WorkingBeatmap lastBeatmap;
protected BindableBeatmap(WorkingBeatmap defaultValue)
: base(defaultValue)
{
BindValueChanged(b => updateAudioTrack(b.NewValue), true);
}
private void updateAudioTrack(WorkingBeatmap beatmap)
{
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;
}
}
}