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-03-12 10:38:23 +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;
|
2022-03-22 06:28:31 +00:00
|
|
|
using osu.Framework.Screens;
|
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;
|
2022-03-22 06:28:31 +00:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.Dialog;
|
2018-03-12 10:38:23 +00:00
|
|
|
using osu.Game.Rulesets;
|
2020-04-22 10:49:21 +00:00
|
|
|
using osu.Game.Rulesets.Edit;
|
2018-03-12 10:38:23 +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
|
|
|
|
2018-03-12 10:38:23 +00:00
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2019-05-14 19:37:25 +00:00
|
|
|
public abstract class EditorTestScene : ScreenTestScene
|
2018-03-12 10:38:23 +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
|
|
|
|
};
|
|
|
|
|
2022-01-18 04:22:55 +00:00
|
|
|
private TestBeatmapManager testBeatmapManager;
|
|
|
|
|
2018-03-12 10:38:23 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2021-05-28 05:33:06 +00:00
|
|
|
private void load(GameHost host, AudioManager audio, RulesetStore rulesets)
|
2018-03-12 10:38:23 +00:00
|
|
|
{
|
2021-09-11 18:43:17 +00:00
|
|
|
Add(logo);
|
|
|
|
|
2021-05-28 05:33:06 +00:00
|
|
|
if (IsolateSavingFromDatabase)
|
2022-01-25 03:58:15 +00:00
|
|
|
Dependencies.CacheAs<BeatmapManager>(testBeatmapManager = new TestBeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default));
|
2022-01-18 04:22:55 +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-03-12 10:38:23 +00:00
|
|
|
}
|
2020-04-23 01:37:05 +00:00
|
|
|
|
2021-05-31 05:24:46 +00:00
|
|
|
protected virtual void LoadEditor()
|
|
|
|
{
|
2022-01-25 10:01:30 +00:00
|
|
|
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
|
|
|
|
|
|
|
|
if (testBeatmapManager != null)
|
|
|
|
testBeatmapManager.TestBeatmap = Beatmap.Value;
|
|
|
|
|
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
|
|
|
|
{
|
2022-03-22 06:28:31 +00:00
|
|
|
[Resolved(canBeNull: true)]
|
2022-03-22 21:10:05 +00:00
|
|
|
[CanBeNull]
|
2022-04-18 09:09:14 +00:00
|
|
|
private IDialogOverlay dialogOverlay { get; set; }
|
2022-03-22 06:28:31 +00:00
|
|
|
|
2020-09-14 06:27:08 +00:00
|
|
|
public new void Undo() => base.Undo();
|
|
|
|
|
|
|
|
public new void Redo() => base.Redo();
|
|
|
|
|
2022-01-23 18:50:02 +00:00
|
|
|
public new bool Save() => base.Save();
|
2020-09-14 06:27:08 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2022-01-23 17:34:33 +00:00
|
|
|
public new void CreateNewDifficulty(RulesetInfo rulesetInfo) => base.CreateNewDifficulty(rulesetInfo);
|
|
|
|
|
2020-09-14 06:27:08 +00:00
|
|
|
public new bool HasUnsavedChanges => base.HasUnsavedChanges;
|
2021-09-11 18:43:17 +00:00
|
|
|
|
2022-04-21 15:52:44 +00:00
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2022-03-22 06:28:31 +00:00
|
|
|
{
|
|
|
|
// For testing purposes allow the screen to exit without saving on second attempt.
|
2022-03-22 21:10:05 +00:00
|
|
|
if (!ExitConfirmed && dialogOverlay?.CurrentDialog is PromptForSaveDialog saveDialog)
|
2022-03-22 06:28:31 +00:00
|
|
|
{
|
|
|
|
saveDialog.PerformAction<PopupDialogDangerousButton>();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-21 15:52:44 +00:00
|
|
|
return base.OnExiting(e);
|
2022-03-22 06:28:31 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2022-01-18 04:22:55 +00:00
|
|
|
public WorkingBeatmap TestBeatmap;
|
2021-05-28 05:33:06 +00:00
|
|
|
|
2022-01-24 10:59:58 +00:00
|
|
|
public TestBeatmapManager(Storage storage, RealmAccess realm, RulesetStore rulesets, IAPIProvider api, [NotNull] AudioManager audioManager, IResourceStore<byte[]> resources, GameHost host, WorkingBeatmap defaultBeatmap)
|
|
|
|
: base(storage, realm, rulesets, api, audioManager, resources, host, defaultBeatmap)
|
2021-05-28 05:33:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-24 10:59:58 +00:00
|
|
|
protected override BeatmapModelManager CreateBeatmapModelManager(Storage storage, RealmAccess realm, RulesetStore rulesets, BeatmapOnlineLookupQueue onlineLookupQueue)
|
2021-09-30 07:45:32 +00:00
|
|
|
{
|
2022-02-01 20:39:52 +00:00
|
|
|
return new TestBeatmapModelManager(storage, realm, onlineLookupQueue);
|
2021-09-30 07:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-02-14 19:56:05 +00:00
|
|
|
public override WorkingBeatmap CreateNewDifficulty(BeatmapSetInfo targetBeatmapSet, WorkingBeatmap referenceWorkingBeatmap, RulesetInfo rulesetInfo)
|
|
|
|
{
|
|
|
|
// don't actually care about properly creating a difficulty for this context.
|
|
|
|
return TestBeatmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override WorkingBeatmap CopyExistingDifficulty(BeatmapSetInfo targetBeatmapSet, WorkingBeatmap referenceWorkingBeatmap)
|
2022-01-23 18:58:21 +00:00
|
|
|
{
|
|
|
|
// don't actually care about properly creating a difficulty for this context.
|
|
|
|
return TestBeatmap;
|
|
|
|
}
|
|
|
|
|
2021-09-30 07:45:32 +00:00
|
|
|
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)
|
2022-01-18 04:22:55 +00:00
|
|
|
=> testBeatmapManager.TestBeatmap;
|
2021-09-30 07:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal class TestBeatmapModelManager : BeatmapModelManager
|
|
|
|
{
|
2022-02-01 20:39:52 +00:00
|
|
|
public TestBeatmapModelManager(Storage storage, RealmAccess databaseAccess, BeatmapOnlineLookupQueue beatmapOnlineLookupQueue)
|
2022-01-24 10:59:58 +00:00
|
|
|
: base(databaseAccess, storage, beatmapOnlineLookupQueue)
|
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-03-12 10:38:23 +00:00
|
|
|
}
|
|
|
|
}
|