Change the way initial state saving works in `EditorChangeHandler` to be closer to first change

This commit is contained in:
Dean Herbert 2023-02-07 16:22:51 +09:00
parent dad348111d
commit e162fd56da
3 changed files with 16 additions and 4 deletions

View File

@ -26,9 +26,6 @@ public BeatmapEditorChangeHandler(EditorBeatmap editorBeatmap)
editorBeatmap.SaveStateTriggered += SaveState;
patcher = new LegacyEditorBeatmapPatcher(editorBeatmap);
// Initial state.
SaveState();
}
protected override void WriteCurrentStateToStream(MemoryStream stream)

View File

@ -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)

View File

@ -33,7 +33,7 @@ public abstract partial class TransactionalCommitComponent : Component
/// <summary>
/// Signal the beginning of a change.
/// </summary>
public void BeginChange()
public virtual void BeginChange()
{
if (bulkChangesStarted++ == 0)
TransactionBegan?.Invoke();