osu/osu.Game.Tests/WaveformTestBeatmap.cs

86 lines
2.7 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-30 23:42:26 +00:00
using osu.Framework.Graphics.Video;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
using osu.Game.IO;
using osu.Game.IO.Archives;
using osu.Game.Rulesets.Catch;
using osu.Game.Tests.Beatmaps;
2019-01-28 09:19:57 +00:00
using osu.Game.Tests.Resources;
namespace osu.Game.Tests
{
/// <summary>
2019-05-15 09:32:29 +00:00
/// A <see cref="WorkingBeatmap"/> that is used for test scenes that include waveforms.
/// </summary>
public class WaveformTestBeatmap : WorkingBeatmap
{
private readonly Beatmap beatmap;
private readonly ITrackStore trackStore;
public WaveformTestBeatmap(AudioManager audioManager)
: this(audioManager, new WaveformBeatmap())
{
}
public WaveformTestBeatmap(AudioManager audioManager, Beatmap beatmap)
: base(beatmap.BeatmapInfo, audioManager)
{
this.beatmap = beatmap;
trackStore = audioManager.GetTrackStore(getZipReader());
}
2019-06-27 04:56:36 +00:00
protected override void Dispose(bool isDisposing)
{
2019-06-27 05:08:58 +00:00
base.Dispose(isDisposing);
trackStore?.Dispose();
}
private static Stream getStream() => TestResources.GetTestBeatmapStream();
2019-12-20 09:07:39 +00:00
private static ZipArchiveReader getZipReader() => new ZipArchiveReader(getStream());
2019-12-20 09:07:39 +00:00
protected override IBeatmap GetBeatmap() => beatmap;
protected override Texture GetBackground() => null;
2019-08-30 23:42:26 +00:00
protected override VideoSprite GetVideo() => null;
2019-05-31 05:57:11 +00:00
protected override Waveform GetWaveform() => new Waveform(trackStore.GetStream(firstAudioFile));
2019-05-31 05:57:11 +00:00
protected override Track GetTrack() => trackStore.Get(firstAudioFile);
private string firstAudioFile
{
get
{
using (var reader = getZipReader())
return reader.Filenames.First(f => f.EndsWith(".mp3"));
}
}
private class WaveformBeatmap : TestBeatmap
{
public WaveformBeatmap()
: base(new CatchRuleset().RulesetInfo)
{
}
protected override Beatmap CreateBeatmap()
{
using (var reader = getZipReader())
using (var beatmapStream = reader.GetStream(reader.Filenames.First(f => f.EndsWith(".osu"))))
using (var beatmapReader = new LineBufferedReader(beatmapStream))
return Decoder.GetDecoder<Beatmap>(beatmapReader).Decode(beatmapReader);
}
}
}
}