2019-01-24 16:43:03 +08: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 14:09:03 +08:00
|
|
|
|
|
2020-10-16 11:58:34 +08:00
|
|
|
|
using System;
|
2018-06-13 14:09:03 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2019-05-31 13:40:53 +08:00
|
|
|
|
using osu.Framework.Audio;
|
2018-06-13 14:09:03 +08:00
|
|
|
|
using osu.Framework.Audio.Track;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.IO.Archives;
|
2020-11-13 16:51:01 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2021-05-22 01:21:00 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2020-02-05 17:14:44 +08:00
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
2019-01-28 17:19:57 +08:00
|
|
|
|
using osu.Game.Tests.Resources;
|
2018-06-13 14:09:03 +08:00
|
|
|
|
|
|
|
|
|
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.
|
2018-06-13 14:09:03 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public class WaveformTestBeatmap : WorkingBeatmap
|
|
|
|
|
{
|
2020-02-05 17:14:44 +08:00
|
|
|
|
private readonly Beatmap beatmap;
|
2019-05-31 13:40:53 +08:00
|
|
|
|
private readonly ITrackStore trackStore;
|
2018-06-13 14:09:03 +08:00
|
|
|
|
|
2020-11-13 16:51:01 +08:00
|
|
|
|
public WaveformTestBeatmap(AudioManager audioManager, RulesetInfo rulesetInfo = null)
|
|
|
|
|
: this(audioManager, new TestBeatmap(rulesetInfo ?? new OsuRuleset().RulesetInfo))
|
2018-06-13 14:09:03 +08:00
|
|
|
|
{
|
2020-02-05 17:14:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WaveformTestBeatmap(AudioManager audioManager, Beatmap beatmap)
|
|
|
|
|
: base(beatmap.BeatmapInfo, audioManager)
|
|
|
|
|
{
|
|
|
|
|
this.beatmap = beatmap;
|
2019-12-19 18:48:48 +08:00
|
|
|
|
trackStore = audioManager.GetTrackStore(getZipReader());
|
2018-06-13 14:09:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-10 16:01:41 +08:00
|
|
|
|
~WaveformTestBeatmap()
|
2018-06-13 14:09:03 +08:00
|
|
|
|
{
|
2020-02-10 16:01:41 +08:00
|
|
|
|
// Remove the track store from the audio manager
|
2019-05-31 13:40:53 +08:00
|
|
|
|
trackStore?.Dispose();
|
2018-06-13 14:09:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 17:14:44 +08:00
|
|
|
|
private static Stream getStream() => TestResources.GetTestBeatmapStream();
|
2019-12-20 17:07:39 +08:00
|
|
|
|
|
2020-02-05 17:14:44 +08:00
|
|
|
|
private static ZipArchiveReader getZipReader() => new ZipArchiveReader(getStream());
|
2019-12-20 17:07:39 +08:00
|
|
|
|
|
2020-02-05 17:14:44 +08:00
|
|
|
|
protected override IBeatmap GetBeatmap() => beatmap;
|
2018-06-13 14:09:03 +08:00
|
|
|
|
|
|
|
|
|
protected override Texture GetBackground() => null;
|
|
|
|
|
|
2019-05-31 13:57:11 +08:00
|
|
|
|
protected override Waveform GetWaveform() => new Waveform(trackStore.GetStream(firstAudioFile));
|
2018-06-13 14:09:03 +08:00
|
|
|
|
|
2021-08-16 00:38:01 +08:00
|
|
|
|
protected internal override ISkin GetSkin() => null;
|
2021-05-22 01:21:00 +08:00
|
|
|
|
|
2021-04-17 23:47:13 +08:00
|
|
|
|
public override Stream GetStream(string storagePath) => null;
|
|
|
|
|
|
2020-08-07 21:31:41 +08:00
|
|
|
|
protected override Track GetBeatmapTrack() => trackStore.Get(firstAudioFile);
|
2019-05-31 13:57:11 +08:00
|
|
|
|
|
2019-12-19 18:48:48 +08:00
|
|
|
|
private string firstAudioFile
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
using (var reader = getZipReader())
|
2020-10-16 11:58:34 +08:00
|
|
|
|
return reader.Filenames.First(f => f.EndsWith(".mp3", StringComparison.Ordinal));
|
2019-12-19 18:48:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-13 14:09:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|