1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-25 16:52:55 +08:00
osu-lazer/osu.Game.Tests/WaveformTestBeatmap.cs

65 lines
2.2 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.IO;
using System.Linq;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures;
2019-08-31 07:42:26 +08:00
using osu.Framework.Graphics.Video;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
using osu.Game.IO;
using osu.Game.IO.Archives;
2019-01-28 17:19:57 +08:00
using osu.Game.Tests.Resources;
namespace osu.Game.Tests
{
/// <summary>
2019-05-15 17:32:29 +08:00
/// A <see cref="WorkingBeatmap"/> that is used for test scenes that include waveforms.
/// </summary>
public class WaveformTestBeatmap : WorkingBeatmap
{
private readonly ZipArchiveReader reader;
2019-01-28 17:19:57 +08:00
private readonly Stream stream;
private readonly ITrackStore trackStore;
public WaveformTestBeatmap(AudioManager audioManager)
: base(new BeatmapInfo(), audioManager)
{
2019-01-28 17:19:57 +08:00
stream = TestResources.GetTestBeatmapStream();
reader = new ZipArchiveReader(stream);
trackStore = audioManager.GetTrackStore(reader);
}
2019-06-27 12:56:36 +08:00
protected override void Dispose(bool isDisposing)
{
2019-06-27 13:08:58 +08:00
base.Dispose(isDisposing);
stream?.Dispose();
reader?.Dispose();
trackStore?.Dispose();
}
protected override IBeatmap GetBeatmap() => createTestBeatmap();
protected override Texture GetBackground() => null;
2019-08-31 07:42:26 +08:00
protected override VideoSprite GetVideo() => null;
2019-05-31 13:57:11 +08:00
protected override Waveform GetWaveform() => new Waveform(trackStore.GetStream(firstAudioFile));
2019-05-31 13:57:11 +08:00
protected override Track GetTrack() => trackStore.Get(firstAudioFile);
private string firstAudioFile => reader.Filenames.First(f => f.EndsWith(".mp3"));
private Stream getBeatmapStream() => reader.GetStream(reader.Filenames.First(f => f.EndsWith(".osu")));
private Beatmap createTestBeatmap()
{
using (var beatmapStream = getBeatmapStream())
using (var beatmapReader = new LineBufferedReader(beatmapStream))
return Decoder.GetDecoder<Beatmap>(beatmapReader).Decode(beatmapReader);
}
}
}