1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 16:12:57 +08:00

Extract class for clipboard contents for DI purposes

This commit is contained in:
Bartłomiej Dach 2021-11-10 12:36:23 +01:00
parent 410e9159d1
commit 5e31e890ae
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
5 changed files with 29 additions and 11 deletions

View File

@ -5,7 +5,6 @@ using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
@ -23,8 +22,8 @@ namespace osu.Game.Rulesets.Mania.Tests.Editor
[Resolved]
private SkinManager skins { get; set; }
[Cached(Name = nameof(Screens.Edit.Editor.Clipboard))]
private Bindable<string> clipboard = new Bindable<string>();
[Cached]
private EditorClipboard clipboard = new EditorClipboard();
[SetUpSteps]
public void SetUpSteps()

View File

@ -3,7 +3,6 @@
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Osu;
@ -27,8 +26,8 @@ namespace osu.Game.Tests.Visual.Editing
}
});
[Cached(Name = nameof(Editor.Clipboard))]
private Bindable<string> clipboard = new Bindable<string>();
[Cached]
private EditorClipboard clipboard = new EditorClipboard();
[BackgroundDependencyLoader]
private void load()

View File

@ -28,7 +28,6 @@ namespace osu.Game.Screens.Edit.Compose
[Resolved]
private EditorClock clock { get; set; }
[Resolved(Name = nameof(Editor.Clipboard))]
private Bindable<string> clipboard { get; set; }
private HitObjectComposer composer;
@ -77,6 +76,12 @@ namespace osu.Game.Screens.Edit.Compose
return new EditorSkinProvidingContainer(EditorBeatmap).WithChild(content);
}
[BackgroundDependencyLoader]
private void load(EditorClipboard clipboard)
{
this.clipboard = clipboard.Content.GetBoundCopy();
}
protected override void LoadComplete()
{
base.LoadComplete();

View File

@ -103,8 +103,8 @@ namespace osu.Game.Screens.Edit
[Resolved]
private MusicController music { get; set; }
[Cached(Name = nameof(Clipboard))]
public readonly Bindable<string> Clipboard = new Bindable<string>();
[Cached]
public readonly EditorClipboard Clipboard = new EditorClipboard();
public Editor(EditorLoader loader = null)
{
@ -317,7 +317,7 @@ namespace osu.Game.Screens.Edit
public void RestoreState([NotNull] EditorState state) => Schedule(() =>
{
clock.Seek(state.Time);
Clipboard.Value = state.ClipboardContent;
Clipboard.Content.Value = state.ClipboardContent;
});
protected void Save()
@ -743,7 +743,7 @@ namespace osu.Game.Screens.Edit
protected void SwitchToDifficulty(BeatmapInfo nextBeatmap) => loader?.ScheduleDifficultySwitch(nextBeatmap, new EditorState
{
Time = clock.CurrentTimeAccurate,
ClipboardContent = editorBeatmap.BeatmapInfo.RulesetID == nextBeatmap.RulesetID ? Clipboard.Value : string.Empty
ClipboardContent = editorBeatmap.BeatmapInfo.RulesetID == nextBeatmap.RulesetID ? Clipboard.Content.Value : string.Empty
});
private void cancelExit()

View File

@ -0,0 +1,15 @@
// 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 osu.Framework.Bindables;
namespace osu.Game.Screens.Edit
{
/// <summary>
/// Wraps the contents of the editor clipboard.
/// </summary>
public class EditorClipboard
{
public Bindable<string> Content { get; } = new Bindable<string>();
}
}