mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 20:53:04 +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.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Screens.Edit.Setup;
|
||||||
using osu.Game.Storyboards;
|
using osu.Game.Storyboards;
|
||||||
|
using osu.Game.Tests.Resources;
|
||||||
|
using SharpCompress.Archives;
|
||||||
|
using SharpCompress.Archives.Zip;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Editing
|
namespace osu.Game.Tests.Visual.Editing
|
||||||
{
|
{
|
||||||
@ -13,6 +20,8 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
{
|
{
|
||||||
protected override Ruleset CreateEditorRuleset() => new OsuRuleset();
|
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);
|
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null) => new DummyWorkingBeatmap(Audio, null);
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -21,5 +30,31 @@ namespace osu.Game.Tests.Visual.Editing
|
|||||||
AddStep("save beatmap", () => Editor.Save());
|
AddStep("save beatmap", () => Editor.Save());
|
||||||
AddAssert("new beatmap persisted", () => EditorBeatmap.BeatmapInfo.ID > 0);
|
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 difficultyTextBox;
|
||||||
private LabelledTextBox audioTrackTextBox;
|
private LabelledTextBox audioTrackTextBox;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private FileStore files { get; set; }
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private MusicController music { get; set; }
|
||||||
|
|
||||||
|
[Resolved(canBeNull: true)]
|
||||||
|
private Editor editor { get; set; }
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
@ -137,29 +146,17 @@ namespace osu.Game.Screens.Edit.Setup
|
|||||||
item.OnCommit += onCommit;
|
item.OnCommit += onCommit;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Resolved]
|
public bool ChangeAudioTrack(string path)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
var info = new FileInfo(filePath.NewValue);
|
var info = new FileInfo(path);
|
||||||
|
|
||||||
if (!info.Exists)
|
if (!info.Exists)
|
||||||
{
|
return false;
|
||||||
audioTrackTextBox.Current.Value = filePath.OldValue;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var beatmapFiles = Beatmap.Value.BeatmapSetInfo.Files;
|
var beatmapFiles = Beatmap.Value.BeatmapSetInfo.Files;
|
||||||
|
|
||||||
// remove the old file
|
// 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)
|
if (oldFile != null)
|
||||||
{
|
{
|
||||||
@ -184,6 +181,13 @@ namespace osu.Game.Screens.Edit.Setup
|
|||||||
music.ForceReloadCurrentBeatmap();
|
music.ForceReloadCurrentBeatmap();
|
||||||
|
|
||||||
editor.UpdateClockSource();
|
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)
|
private void onCommit(TextBox sender, bool newText)
|
||||||
|
@ -26,13 +26,15 @@ namespace osu.Game.Tests.Visual
|
|||||||
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
|
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()
|
public override void SetUpSteps()
|
||||||
{
|
{
|
||||||
base.SetUpSteps();
|
base.SetUpSteps();
|
||||||
|
|
||||||
AddStep("load editor", () => LoadScreen(Editor = CreateEditor()));
|
AddStep("load editor", () => LoadScreen(Editor = CreateEditor()));
|
||||||
AddUntilStep("wait for editor to load", () => Editor.ChildrenOfType<HitObjectComposer>().FirstOrDefault()?.IsLoaded == true
|
AddUntilStep("wait for editor to load", () => EditorComponentsReady);
|
||||||
&& Editor.ChildrenOfType<TimelineArea>().FirstOrDefault()?.IsLoaded == true);
|
|
||||||
AddStep("get beatmap", () => EditorBeatmap = Editor.ChildrenOfType<EditorBeatmap>().Single());
|
AddStep("get beatmap", () => EditorBeatmap = Editor.ChildrenOfType<EditorBeatmap>().Single());
|
||||||
AddStep("get clock", () => EditorClock = Editor.ChildrenOfType<EditorClock>().Single());
|
AddStep("get clock", () => EditorClock = Editor.ChildrenOfType<EditorClock>().Single());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user