2019-05-31 05:40:53 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 08:43:03 +00:00
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-04-22 10:49:21 +00:00
|
|
|
using System.Linq;
|
2020-06-03 21:47:10 +00:00
|
|
|
using JetBrains.Annotations;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Framework.Allocation;
|
2021-05-28 05:33:06 +00:00
|
|
|
using osu.Framework.Audio;
|
2021-05-31 10:35:54 +00:00
|
|
|
using osu.Framework.IO.Stores;
|
2021-05-28 05:33:06 +00:00
|
|
|
using osu.Framework.Platform;
|
2020-04-22 10:49:21 +00:00
|
|
|
using osu.Framework.Testing;
|
2021-05-28 05:33:06 +00:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Database;
|
|
|
|
using osu.Game.Online.API;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Rulesets;
|
2020-04-22 10:49:21 +00:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Screens.Edit;
|
2020-04-22 10:49:21 +00:00
|
|
|
using osu.Game.Screens.Edit.Compose.Components.Timeline;
|
2021-09-11 18:43:17 +00:00
|
|
|
using osu.Game.Screens.Menu;
|
2021-05-28 05:33:06 +00:00
|
|
|
using osu.Game.Skinning;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2019-05-14 19:37:25 +00:00
|
|
|
public abstract class EditorTestScene : ScreenTestScene
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2021-09-11 18:43:17 +00:00
|
|
|
private TestEditorLoader editorLoader;
|
|
|
|
|
|
|
|
protected TestEditor Editor => editorLoader.Editor;
|
2020-09-14 06:27:08 +00:00
|
|
|
|
2021-09-12 11:40:06 +00:00
|
|
|
protected EditorBeatmap EditorBeatmap => Editor.ChildrenOfType<EditorBeatmap>().Single();
|
|
|
|
protected EditorClock EditorClock => Editor.ChildrenOfType<EditorClock>().Single();
|
2020-04-22 10:49:21 +00:00
|
|
|
|
2021-05-28 05:33:06 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Whether any saves performed by the editor should be isolate (and not persist) to the underlying <see cref="BeatmapManager"/>.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual bool IsolateSavingFromDatabase => true;
|
|
|
|
|
2021-09-11 18:43:17 +00:00
|
|
|
// required for screen transitions to work properly
|
|
|
|
// (see comment in EditorLoader.LogoArriving).
|
|
|
|
[Cached]
|
|
|
|
private OsuLogo logo = new OsuLogo
|
|
|
|
{
|
|
|
|
Alpha = 0
|
|
|
|
};
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2021-05-28 05:33:06 +00:00
|
|
|
private void load(GameHost host, AudioManager audio, RulesetStore rulesets)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2021-09-11 18:43:17 +00:00
|
|
|
Add(logo);
|
|
|
|
|
2021-05-28 05:33:06 +00:00
|
|
|
var working = CreateWorkingBeatmap(Ruleset.Value);
|
|
|
|
|
|
|
|
Beatmap.Value = working;
|
|
|
|
|
|
|
|
if (IsolateSavingFromDatabase)
|
2021-05-31 10:35:54 +00:00
|
|
|
Dependencies.CacheAs<BeatmapManager>(new TestBeatmapManager(LocalStorage, ContextFactory, rulesets, null, audio, Resources, host, Beatmap.Default, working));
|
2020-02-07 07:42:56 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 13:00:13 +00:00
|
|
|
protected virtual bool EditorComponentsReady => Editor.ChildrenOfType<HitObjectComposer>().FirstOrDefault()?.IsLoaded == true
|
|
|
|
&& Editor.ChildrenOfType<TimelineArea>().FirstOrDefault()?.IsLoaded == true;
|
|
|
|
|
2020-02-07 07:42:56 +00:00
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
|
|
|
base.SetUpSteps();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2021-05-31 05:24:46 +00:00
|
|
|
AddStep("load editor", LoadEditor);
|
2020-09-24 13:00:13 +00:00
|
|
|
AddUntilStep("wait for editor to load", () => EditorComponentsReady);
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
2020-04-23 01:37:05 +00:00
|
|
|
|
2021-05-31 05:24:46 +00:00
|
|
|
protected virtual void LoadEditor()
|
|
|
|
{
|
2021-09-11 18:43:17 +00:00
|
|
|
LoadScreen(editorLoader = new TestEditorLoader());
|
2021-05-31 05:24:46 +00:00
|
|
|
}
|
|
|
|
|
2020-06-03 21:47:10 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Creates the ruleset for providing a corresponding beatmap to load the editor on.
|
|
|
|
/// </summary>
|
|
|
|
[NotNull]
|
|
|
|
protected abstract Ruleset CreateEditorRuleset();
|
|
|
|
|
|
|
|
protected sealed override Ruleset CreateRuleset() => CreateEditorRuleset();
|
|
|
|
|
2021-09-11 18:43:17 +00:00
|
|
|
protected class TestEditorLoader : EditorLoader
|
|
|
|
{
|
|
|
|
public TestEditor Editor { get; private set; }
|
|
|
|
|
|
|
|
protected sealed override Editor CreateEditor() => Editor = CreateTestEditor(this);
|
|
|
|
|
|
|
|
protected virtual TestEditor CreateTestEditor(EditorLoader loader) => new TestEditor(loader);
|
|
|
|
}
|
2020-09-14 06:27:08 +00:00
|
|
|
|
|
|
|
protected class TestEditor : Editor
|
|
|
|
{
|
|
|
|
public new void Undo() => base.Undo();
|
|
|
|
|
|
|
|
public new void Redo() => base.Redo();
|
|
|
|
|
|
|
|
public new void Save() => base.Save();
|
|
|
|
|
|
|
|
public new void Cut() => base.Cut();
|
|
|
|
|
|
|
|
public new void Copy() => base.Copy();
|
|
|
|
|
|
|
|
public new void Paste() => base.Paste();
|
|
|
|
|
2021-09-12 11:55:48 +00:00
|
|
|
public new void SwitchToDifficulty(BeatmapInfo beatmapInfo) => base.SwitchToDifficulty(beatmapInfo);
|
|
|
|
|
2020-09-14 06:27:08 +00:00
|
|
|
public new bool HasUnsavedChanges => base.HasUnsavedChanges;
|
2021-09-11 18:43:17 +00:00
|
|
|
|
|
|
|
public TestEditor(EditorLoader loader = null)
|
|
|
|
: base(loader)
|
|
|
|
{
|
|
|
|
}
|
2020-09-14 06:27:08 +00:00
|
|
|
}
|
2021-05-28 05:33:06 +00:00
|
|
|
|
|
|
|
private class TestBeatmapManager : BeatmapManager
|
|
|
|
{
|
|
|
|
private readonly WorkingBeatmap testBeatmap;
|
|
|
|
|
2021-05-31 10:35:54 +00:00
|
|
|
public TestBeatmapManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, GameHost host, WorkingBeatmap defaultBeatmap, WorkingBeatmap testBeatmap)
|
2021-07-05 15:52:39 +00:00
|
|
|
: base(storage, contextFactory, rulesets, api, audioManager, resources, host, defaultBeatmap)
|
2021-05-28 05:33:06 +00:00
|
|
|
{
|
|
|
|
this.testBeatmap = testBeatmap;
|
|
|
|
}
|
|
|
|
|
2021-09-30 07:45:32 +00:00
|
|
|
protected override BeatmapModelManager CreateBeatmapModelManager(Storage storage, IDatabaseContextFactory contextFactory, RulesetStore rulesets, IAPIProvider api, GameHost host)
|
|
|
|
{
|
|
|
|
return new TestBeatmapModelManager(storage, contextFactory, rulesets, api, host);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override WorkingBeatmapCache CreateWorkingBeatmapCache(AudioManager audioManager, IResourceStore<byte[]> resources, IResourceStore<byte[]> storage, WorkingBeatmap defaultBeatmap, GameHost host)
|
|
|
|
{
|
|
|
|
return new TestWorkingBeatmapCache(this, audioManager, resources, storage, defaultBeatmap, host);
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestWorkingBeatmapCache : WorkingBeatmapCache
|
|
|
|
{
|
|
|
|
private readonly TestBeatmapManager testBeatmapManager;
|
2021-05-28 05:33:06 +00:00
|
|
|
|
2021-09-30 07:45:32 +00:00
|
|
|
public TestWorkingBeatmapCache(TestBeatmapManager testBeatmapManager, AudioManager audioManager, IResourceStore<byte[]> resourceStore, IResourceStore<byte[]> storage, WorkingBeatmap defaultBeatmap, GameHost gameHost)
|
2021-11-09 08:27:07 +00:00
|
|
|
: base(testBeatmapManager.BeatmapTrackStore, audioManager, resourceStore, storage, defaultBeatmap, gameHost)
|
2021-09-30 07:45:32 +00:00
|
|
|
{
|
|
|
|
this.testBeatmapManager = testBeatmapManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo)
|
|
|
|
=> testBeatmapManager.testBeatmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
internal class TestBeatmapModelManager : BeatmapModelManager
|
|
|
|
{
|
|
|
|
public TestBeatmapModelManager(Storage storage, IDatabaseContextFactory databaseContextFactory, RulesetStore rulesetStore, IAPIProvider apiProvider, GameHost gameHost)
|
2021-09-30 09:21:16 +00:00
|
|
|
: base(storage, databaseContextFactory, rulesetStore, gameHost)
|
2021-09-30 07:45:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-10-24 14:48:46 +00:00
|
|
|
protected override string ComputeHash(BeatmapSetInfo item)
|
2021-09-30 07:45:32 +00:00
|
|
|
=> string.Empty;
|
|
|
|
}
|
2021-05-28 05:33:06 +00:00
|
|
|
|
|
|
|
public override void Save(BeatmapInfo info, IBeatmap beatmapContent, ISkin beatmapSkin = null)
|
|
|
|
{
|
|
|
|
// don't actually care about saving for this context.
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
}
|