osu/osu.Game.Tests/WaveformTestBeatmap.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.3 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.
2020-10-16 03:58:34 +00:00
using System;
using System.IO;
using System.Linq;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps;
using osu.Game.IO.Archives;
2020-11-13 08:51:01 +00:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Skinning;
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;
2020-11-13 08:51:01 +00:00
public WaveformTestBeatmap(AudioManager audioManager, RulesetInfo rulesetInfo = null)
: this(audioManager, new TestBeatmap(rulesetInfo ?? new OsuRuleset().RulesetInfo))
{
}
public WaveformTestBeatmap(AudioManager audioManager, Beatmap beatmap)
: base(beatmap.BeatmapInfo, audioManager)
{
this.beatmap = beatmap;
trackStore = audioManager.GetTrackStore(getZipReader());
}
2020-02-10 08:01:41 +00:00
~WaveformTestBeatmap()
{
2020-02-10 08:01:41 +00:00
// Remove the track store from the audio manager
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-05-31 05:57:11 +00:00
protected override Waveform GetWaveform() => new Waveform(trackStore.GetStream(firstAudioFile));
protected internal override ISkin GetSkin() => null;
public override Stream GetStream(string storagePath) => null;
2020-08-07 13:31:41 +00:00
protected override Track GetBeatmapTrack() => trackStore.Get(firstAudioFile);
2019-05-31 05:57:11 +00:00
private string firstAudioFile
{
get
{
using (var reader = getZipReader())
2020-10-16 03:58:34 +00:00
return reader.Filenames.First(f => f.EndsWith(".mp3", StringComparison.Ordinal));
}
}
}
}