2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-10-28 13:14:45 +08:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Audio.Track;
|
2017-03-06 13:52:37 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2016-11-05 19:00:14 +08:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2016-10-28 19:24:14 +08:00
|
|
|
|
using osu.Game.Database;
|
2017-03-05 16:45:40 +08:00
|
|
|
|
using osu.Game.Modes;
|
2017-03-12 21:13:43 +08:00
|
|
|
|
using osu.Game.Modes.Mods;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-10-28 13:14:45 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps
|
|
|
|
|
{
|
2017-02-24 12:43:21 +08:00
|
|
|
|
public abstract class WorkingBeatmap : IDisposable
|
2016-10-28 13:14:45 +08:00
|
|
|
|
{
|
2016-11-05 17:16:15 +08:00
|
|
|
|
public readonly BeatmapInfo BeatmapInfo;
|
2016-10-28 19:24:14 +08:00
|
|
|
|
|
2016-11-05 17:16:15 +08:00
|
|
|
|
public readonly BeatmapSetInfo BeatmapSetInfo;
|
|
|
|
|
|
2017-03-05 16:45:40 +08:00
|
|
|
|
/// <summary>
|
2017-03-06 13:08:58 +08:00
|
|
|
|
/// A play mode that is preferred for this beatmap. PlayMode will become this mode where conversion is feasible,
|
|
|
|
|
/// or otherwise to the beatmap's default.
|
2017-03-05 16:45:40 +08:00
|
|
|
|
/// </summary>
|
2017-03-06 13:08:58 +08:00
|
|
|
|
public PlayMode? PreferredPlayMode;
|
2017-03-05 16:45:40 +08:00
|
|
|
|
|
2017-03-22 17:54:07 +08:00
|
|
|
|
public PlayMode PlayMode => Beatmap?.BeatmapInfo?.Mode > PlayMode.Osu ? Beatmap.BeatmapInfo.Mode : PreferredPlayMode ?? PlayMode.Osu;
|
2017-03-05 16:45:40 +08:00
|
|
|
|
|
2017-03-06 14:20:55 +08:00
|
|
|
|
public readonly Bindable<IEnumerable<Mod>> Mods = new Bindable<IEnumerable<Mod>>();
|
2017-03-06 13:52:37 +08:00
|
|
|
|
|
2017-02-09 22:09:48 +08:00
|
|
|
|
public readonly bool WithStoryboard;
|
|
|
|
|
|
2017-02-24 12:43:21 +08:00
|
|
|
|
protected WorkingBeatmap(BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, bool withStoryboard = false)
|
|
|
|
|
{
|
|
|
|
|
BeatmapInfo = beatmapInfo;
|
|
|
|
|
BeatmapSetInfo = beatmapSetInfo;
|
|
|
|
|
WithStoryboard = withStoryboard;
|
|
|
|
|
}
|
2017-03-22 18:15:32 +08:00
|
|
|
|
|
|
|
|
|
protected abstract Beatmap GetBeatmap();
|
|
|
|
|
protected abstract Texture GetBackground();
|
|
|
|
|
protected abstract Track GetTrack();
|
|
|
|
|
|
|
|
|
|
private Beatmap beatmap;
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly object beatmapLock = new object();
|
2017-03-22 18:15:32 +08:00
|
|
|
|
public Beatmap Beatmap
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
lock (beatmapLock)
|
|
|
|
|
{
|
|
|
|
|
return beatmap ?? (beatmap = GetBeatmap());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-22 17:54:07 +08:00
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly object backgroundLock = new object();
|
2017-03-22 18:15:32 +08:00
|
|
|
|
private Texture background;
|
|
|
|
|
public Texture Background
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
lock (backgroundLock)
|
|
|
|
|
{
|
|
|
|
|
return background ?? (background = GetBackground());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Track track;
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly object trackLock = new object();
|
2017-03-22 18:15:32 +08:00
|
|
|
|
public Track Track
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
lock (trackLock)
|
|
|
|
|
{
|
|
|
|
|
return track ?? (track = GetTrack());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-28 19:24:14 +08:00
|
|
|
|
|
2017-03-22 18:15:32 +08:00
|
|
|
|
public bool TrackLoaded => track != null;
|
2016-11-05 20:01:46 +08:00
|
|
|
|
|
2017-03-22 18:15:32 +08:00
|
|
|
|
public void TransferTo(WorkingBeatmap other)
|
|
|
|
|
{
|
|
|
|
|
if (track != null && BeatmapInfo.AudioEquals(other.BeatmapInfo))
|
|
|
|
|
other.track = track;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Dispose()
|
|
|
|
|
{
|
|
|
|
|
track?.Dispose();
|
|
|
|
|
track = null;
|
|
|
|
|
background?.Dispose();
|
|
|
|
|
background = null;
|
|
|
|
|
}
|
2016-10-28 13:14:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|