From e162fd56da39f5bcf67ef3a21af13ea08c6cf8ec Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 7 Feb 2023 16:22:51 +0900 Subject: [PATCH] Change the way initial state saving works in `EditorChangeHandler` to be closer to first change --- .../Screens/Edit/BeatmapEditorChangeHandler.cs | 3 --- osu.Game/Screens/Edit/EditorChangeHandler.cs | 15 +++++++++++++++ .../Screens/Edit/TransactionalCommitComponent.cs | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Edit/BeatmapEditorChangeHandler.cs b/osu.Game/Screens/Edit/BeatmapEditorChangeHandler.cs index b9349a31af..3c19994a8a 100644 --- a/osu.Game/Screens/Edit/BeatmapEditorChangeHandler.cs +++ b/osu.Game/Screens/Edit/BeatmapEditorChangeHandler.cs @@ -26,9 +26,6 @@ public BeatmapEditorChangeHandler(EditorBeatmap editorBeatmap) editorBeatmap.SaveStateTriggered += SaveState; patcher = new LegacyEditorBeatmapPatcher(editorBeatmap); - - // Initial state. - SaveState(); } protected override void WriteCurrentStateToStream(MemoryStream stream) diff --git a/osu.Game/Screens/Edit/EditorChangeHandler.cs b/osu.Game/Screens/Edit/EditorChangeHandler.cs index 4511b654b6..0bb17e4c5d 100644 --- a/osu.Game/Screens/Edit/EditorChangeHandler.cs +++ b/osu.Game/Screens/Edit/EditorChangeHandler.cs @@ -31,6 +31,8 @@ public string CurrentStateHash { get { + ensureStateSaved(); + using (var stream = new MemoryStream(savedStates[currentState])) return stream.ComputeSHA2Hash(); } @@ -40,6 +42,19 @@ public string CurrentStateHash public const int MAX_SAVED_STATES = 50; + public override void BeginChange() + { + ensureStateSaved(); + + base.BeginChange(); + } + + private void ensureStateSaved() + { + if (savedStates.Count == 0) + SaveState(); + } + protected override void UpdateState() { if (isRestoring) diff --git a/osu.Game/Screens/Edit/TransactionalCommitComponent.cs b/osu.Game/Screens/Edit/TransactionalCommitComponent.cs index f8362523f1..92f1e19e6f 100644 --- a/osu.Game/Screens/Edit/TransactionalCommitComponent.cs +++ b/osu.Game/Screens/Edit/TransactionalCommitComponent.cs @@ -33,7 +33,7 @@ public abstract partial class TransactionalCommitComponent : Component /// /// Signal the beginning of a change. /// - public void BeginChange() + public virtual void BeginChange() { if (bulkChangesStarted++ == 0) TransactionBegan?.Invoke();