2016-10-28 13:14:45 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-10-28 19:24:14 +08:00
|
|
|
|
using System.IO;
|
2016-10-28 13:14:45 +08:00
|
|
|
|
using osu.Framework.Audio.Track;
|
2016-11-05 19:00:14 +08:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2016-10-28 19:24:14 +08:00
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
2016-10-28 13:14:45 +08:00
|
|
|
|
using osu.Game.Beatmaps.IO;
|
2016-10-28 19:24:14 +08:00
|
|
|
|
using osu.Game.Database;
|
2016-10-28 13:14:45 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps
|
|
|
|
|
{
|
|
|
|
|
public class WorkingBeatmap : IDisposable
|
|
|
|
|
{
|
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;
|
|
|
|
|
private readonly BeatmapDatabase database;
|
|
|
|
|
|
|
|
|
|
private ArchiveReader reader => database.GetReader(BeatmapSetInfo);
|
2016-10-28 19:24:14 +08:00
|
|
|
|
|
2016-11-05 19:00:14 +08:00
|
|
|
|
private Texture background;
|
|
|
|
|
public Texture Background
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (background != null) return background;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
background = new TextureStore(new RawTextureLoaderStore(reader)).Get(BeatmapInfo.Metadata.BackgroundFile);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
|
|
|
|
|
return background;
|
|
|
|
|
}
|
|
|
|
|
set { background = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 19:24:14 +08:00
|
|
|
|
private Beatmap beatmap;
|
|
|
|
|
public Beatmap Beatmap
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (beatmap != null) return beatmap;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2016-11-05 19:00:14 +08:00
|
|
|
|
using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path)))
|
2016-10-28 19:24:14 +08:00
|
|
|
|
beatmap = BeatmapDecoder.GetDecoder(stream)?.Decode(stream);
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
|
|
|
|
|
return beatmap;
|
|
|
|
|
}
|
|
|
|
|
set { beatmap = value; }
|
|
|
|
|
}
|
2016-10-28 13:14:45 +08:00
|
|
|
|
|
|
|
|
|
private AudioTrack track;
|
|
|
|
|
public AudioTrack Track
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-28 18:55:48 +08:00
|
|
|
|
if (track != null) return track;
|
|
|
|
|
|
|
|
|
|
try
|
2016-10-28 13:14:45 +08:00
|
|
|
|
{
|
2016-11-05 19:00:14 +08:00
|
|
|
|
var trackData = reader.GetStream(BeatmapInfo.Metadata.AudioFile);
|
2016-10-28 18:55:48 +08:00
|
|
|
|
if (trackData != null)
|
|
|
|
|
track = new AudioTrackBass(trackData);
|
2016-10-28 13:14:45 +08:00
|
|
|
|
}
|
2016-10-28 18:55:48 +08:00
|
|
|
|
catch { }
|
2016-10-28 13:14:45 +08:00
|
|
|
|
|
|
|
|
|
return track;
|
|
|
|
|
}
|
|
|
|
|
set { track = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-05 17:16:15 +08:00
|
|
|
|
public WorkingBeatmap(Beatmap beatmap)
|
|
|
|
|
{
|
|
|
|
|
this.beatmap = beatmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WorkingBeatmap(BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, BeatmapDatabase database)
|
2016-10-28 13:14:45 +08:00
|
|
|
|
{
|
2016-10-28 20:08:32 +08:00
|
|
|
|
this.BeatmapInfo = beatmapInfo;
|
2016-11-05 17:16:15 +08:00
|
|
|
|
this.BeatmapSetInfo = beatmapSetInfo;
|
|
|
|
|
this.database = database;
|
2016-10-28 13:14:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool isDisposed;
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
if (!isDisposed)
|
|
|
|
|
{
|
|
|
|
|
track?.Dispose();
|
2016-11-05 17:16:15 +08:00
|
|
|
|
reader?.Dispose();
|
2016-10-28 13:14:45 +08:00
|
|
|
|
isDisposed = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
}
|
2016-10-28 19:24:14 +08:00
|
|
|
|
|
|
|
|
|
public void TransferTo(WorkingBeatmap working)
|
|
|
|
|
{
|
2016-10-28 20:08:32 +08:00
|
|
|
|
if (track != null && working.BeatmapInfo.Metadata.AudioFile == BeatmapInfo.Metadata.AudioFile && working.BeatmapInfo.BeatmapSet.Path == BeatmapInfo.BeatmapSet.Path)
|
2016-10-28 19:24:14 +08:00
|
|
|
|
working.track = track;
|
|
|
|
|
}
|
2016-10-28 13:14:45 +08:00
|
|
|
|
}
|
|
|
|
|
}
|