2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2019-05-31 05:40:53 +00:00
|
|
|
|
using osu.Framework.Audio;
|
2018-06-13 06:09:03 +00:00
|
|
|
|
using osu.Framework.Audio.Track;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2019-08-30 23:42:26 +00:00
|
|
|
|
using osu.Framework.Graphics.Video;
|
2018-06-13 06:09:03 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Beatmaps.Formats;
|
2019-09-09 22:43:30 +00:00
|
|
|
|
using osu.Game.IO;
|
2018-06-13 06:09:03 +00:00
|
|
|
|
using osu.Game.IO.Archives;
|
2019-01-28 09:19:57 +00:00
|
|
|
|
using osu.Game.Tests.Resources;
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
|
|
|
|
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.
|
2018-06-13 06:09:03 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public class WaveformTestBeatmap : WorkingBeatmap
|
|
|
|
|
{
|
|
|
|
|
private readonly ZipArchiveReader reader;
|
2019-01-28 09:19:57 +00:00
|
|
|
|
private readonly Stream stream;
|
2019-05-31 05:40:53 +00:00
|
|
|
|
private readonly ITrackStore trackStore;
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
2019-05-31 05:40:53 +00:00
|
|
|
|
public WaveformTestBeatmap(AudioManager audioManager)
|
|
|
|
|
: base(new BeatmapInfo(), audioManager)
|
2018-06-13 06:09:03 +00:00
|
|
|
|
{
|
2019-01-28 09:19:57 +00:00
|
|
|
|
stream = TestResources.GetTestBeatmapStream();
|
2018-06-13 06:09:03 +00:00
|
|
|
|
reader = new ZipArchiveReader(stream);
|
2019-05-31 05:40:53 +00:00
|
|
|
|
trackStore = audioManager.GetTrackStore(reader);
|
2018-06-13 06:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-27 04:56:36 +00:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2018-06-13 06:09:03 +00:00
|
|
|
|
{
|
2019-06-27 05:08:58 +00:00
|
|
|
|
base.Dispose(isDisposing);
|
2018-06-13 06:09:03 +00:00
|
|
|
|
stream?.Dispose();
|
|
|
|
|
reader?.Dispose();
|
2019-05-31 05:40:53 +00:00
|
|
|
|
trackStore?.Dispose();
|
2018-06-13 06:09:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IBeatmap GetBeatmap() => createTestBeatmap();
|
|
|
|
|
|
|
|
|
|
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));
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
2019-05-31 05:57:11 +00:00
|
|
|
|
protected override Track GetTrack() => trackStore.Get(firstAudioFile);
|
|
|
|
|
|
|
|
|
|
private string firstAudioFile => reader.Filenames.First(f => f.EndsWith(".mp3"));
|
2018-06-13 06:09:03 +00:00
|
|
|
|
|
|
|
|
|
private Stream getBeatmapStream() => reader.GetStream(reader.Filenames.First(f => f.EndsWith(".osu")));
|
|
|
|
|
|
|
|
|
|
private Beatmap createTestBeatmap()
|
|
|
|
|
{
|
|
|
|
|
using (var beatmapStream = getBeatmapStream())
|
2019-09-09 22:43:30 +00:00
|
|
|
|
using (var beatmapReader = new LineBufferedReader(beatmapStream))
|
2018-06-13 06:09:03 +00:00
|
|
|
|
return Decoder.GetDecoder<Beatmap>(beatmapReader).Decode(beatmapReader);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|