mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:27:29 +08:00
Add test coverage of audio track changing
This commit is contained in:
parent
cc9ae32811
commit
011b176244
@ -1,11 +1,18 @@
|
||||
// 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 NUnit.Framework;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Screens.Edit.Setup;
|
||||
using osu.Game.Storyboards;
|
||||
using osu.Game.Tests.Resources;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Zip;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Editing
|
||||
{
|
||||
@ -13,6 +20,8 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
{
|
||||
protected override Ruleset CreateEditorRuleset() => new OsuRuleset();
|
||||
|
||||
protected override bool EditorComponentsReady => Editor.ChildrenOfType<SetupScreen>().FirstOrDefault()?.IsLoaded == true;
|
||||
|
||||
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) => new DummyWorkingBeatmap(Audio, null);
|
||||
|
||||
[Test]
|
||||
@ -21,5 +30,31 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
AddStep("save beatmap", () => Editor.Save());
|
||||
AddAssert("new beatmap persisted", () => EditorBeatmap.BeatmapInfo.ID > 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAddAudioTrack()
|
||||
{
|
||||
AddAssert("switch track to real track", () =>
|
||||
{
|
||||
var setup = Editor.ChildrenOfType<SetupScreen>().First();
|
||||
|
||||
var temp = TestResources.GetTestBeatmapForImport();
|
||||
|
||||
string extractedFolder = $"{temp}_extracted";
|
||||
Directory.CreateDirectory(extractedFolder);
|
||||
|
||||
using (var zip = ZipArchive.Open(temp))
|
||||
zip.WriteToDirectory(extractedFolder);
|
||||
|
||||
bool success = setup.ChangeAudioTrack(Path.Combine(extractedFolder, "03. Renatus - Soleily 192kbps.mp3"));
|
||||
|
||||
File.Delete(temp);
|
||||
Directory.Delete(extractedFolder, true);
|
||||
|
||||
return success;
|
||||
});
|
||||
|
||||
AddAssert("track length changed", () => Beatmap.Value.Track.Length > 60000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,15 @@ namespace osu.Game.Screens.Edit.Setup
|
||||
private LabelledTextBox difficultyTextBox;
|
||||
private LabelledTextBox audioTrackTextBox;
|
||||
|
||||
[Resolved]
|
||||
private FileStore files { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private MusicController music { get; set; }
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private Editor editor { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
@ -137,29 +146,17 @@ namespace osu.Game.Screens.Edit.Setup
|
||||
item.OnCommit += onCommit;
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private FileStore files { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private MusicController music { get; set; }
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private Editor editor { get; set; }
|
||||
|
||||
private void audioTrackChanged(ValueChangedEvent<string> filePath)
|
||||
public bool ChangeAudioTrack(string path)
|
||||
{
|
||||
var info = new FileInfo(filePath.NewValue);
|
||||
var info = new FileInfo(path);
|
||||
|
||||
if (!info.Exists)
|
||||
{
|
||||
audioTrackTextBox.Current.Value = filePath.OldValue;
|
||||
return;
|
||||
}
|
||||
return false;
|
||||
|
||||
var beatmapFiles = Beatmap.Value.BeatmapSetInfo.Files;
|
||||
|
||||
// remove the old file
|
||||
var oldFile = beatmapFiles.FirstOrDefault(f => f.Filename == filePath.OldValue);
|
||||
var oldFile = beatmapFiles.FirstOrDefault(f => f.Filename == Beatmap.Value.Metadata.AudioFile);
|
||||
|
||||
if (oldFile != null)
|
||||
{
|
||||
@ -184,6 +181,13 @@ namespace osu.Game.Screens.Edit.Setup
|
||||
music.ForceReloadCurrentBeatmap();
|
||||
|
||||
editor.UpdateClockSource();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void audioTrackChanged(ValueChangedEvent<string> filePath)
|
||||
{
|
||||
if (!ChangeAudioTrack(filePath.NewValue))
|
||||
audioTrackTextBox.Current.Value = filePath.OldValue;
|
||||
}
|
||||
|
||||
private void onCommit(TextBox sender, bool newText)
|
||||
|
@ -26,13 +26,15 @@ namespace osu.Game.Tests.Visual
|
||||
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
|
||||
}
|
||||
|
||||
protected virtual bool EditorComponentsReady => Editor.ChildrenOfType<HitObjectComposer>().FirstOrDefault()?.IsLoaded == true
|
||||
&& Editor.ChildrenOfType<TimelineArea>().FirstOrDefault()?.IsLoaded == true;
|
||||
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("load editor", () => LoadScreen(Editor = CreateEditor()));
|
||||
AddUntilStep("wait for editor to load", () => Editor.ChildrenOfType<HitObjectComposer>().FirstOrDefault()?.IsLoaded == true
|
||||
&& Editor.ChildrenOfType<TimelineArea>().FirstOrDefault()?.IsLoaded == true);
|
||||
AddUntilStep("wait for editor to load", () => EditorComponentsReady);
|
||||
AddStep("get beatmap", () => EditorBeatmap = Editor.ChildrenOfType<EditorBeatmap>().Single());
|
||||
AddStep("get clock", () => EditorClock = Editor.ChildrenOfType<EditorClock>().Single());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user