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