Make restoring state a public call on Editor

This commit is contained in:
Dean Herbert 2021-09-14 23:36:17 +09:00
parent 2a894e7a3f
commit f8bdca542d
2 changed files with 18 additions and 12 deletions

View File

@ -317,6 +317,16 @@ namespace osu.Game.Screens.Edit
/// </summary>
public void UpdateClockSource() => clock.ChangeSource(Beatmap.Value.Track);
/// <summary>
/// Restore the editor to a provided state.
/// </summary>
/// <param name="state">The state to restore.</param>
public void RestoreState([NotNull] EditorState state) => Schedule(() =>
{
clock.Seek(state.Time);
clipboard.Value = state.ClipboardContent;
});
protected void Save()
{
// no longer new after first user-triggered save.
@ -476,8 +486,6 @@ namespace osu.Game.Screens.Edit
});
resetTrack(true);
if (loader?.State != null)
restoreState(loader.State);
}
public override bool OnExiting(IScreen next)
@ -745,17 +753,9 @@ 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 : null
ClipboardContent = editorBeatmap.BeatmapInfo.RulesetID == nextBeatmap.RulesetID ? clipboard.Value : string.Empty
});
private void restoreState([NotNull] EditorState state)
{
if (state.Time != null)
clock.Seek(state.Time.Value);
clipboard.Value = state.ClipboardContent ?? clipboard.Value;
}
private void cancelExit() => loader?.CancelPendingDifficultySwitch();
public double SnapTime(double time, double? referenceTime) => editorBeatmap.SnapTime(time, referenceTime);

View File

@ -91,7 +91,13 @@ namespace osu.Game.Screens.Edit
private void pushEditor()
{
this.Push(CreateEditor());
var editor = CreateEditor();
this.Push(editor);
if (state != null)
editor.RestoreState(state);
ValidForResume = false;
}