From 3b01720d6632674f8e6d72d9adffc3b8a09612b3 Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Wed, 10 Oct 2018 13:35:57 -0400 Subject: [PATCH] change-record group --- history/SceneChanges.cs | 55 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/history/SceneChanges.cs b/history/SceneChanges.cs index fcab8ce..eb9b9f4 100644 --- a/history/SceneChanges.cs +++ b/history/SceneChanges.cs @@ -397,4 +397,59 @@ public override OpStatus Cull() } } + + + + /// + /// Collection of changes that will be applied in-order, and + /// reverted in opposite order. + /// + public class ChangeSet : BaseChangeOp + { + List Changes; + + public override string Identifier() { return "ChangeSet"; } + + public ChangeSet() { + Changes = new List(); + } + public ChangeSet(IEnumerable all) { + Changes = new List(all); + } + + public override OpStatus Apply() + { + OpStatus totalResult = OpStatus.Success; + foreach (var change in Changes) { + var result = change.Apply(); + if (result.code != OpStatus.Success.code) + totalResult = result; + } + return totalResult; + } + public override OpStatus Revert() + { + OpStatus totalResult = OpStatus.Success; + int N = Changes.Count; + for ( int i = N-1; i >= 0; --i ) { + var change = Changes[i]; + var result = change.Revert(); + if (result.code != OpStatus.Success.code) + totalResult = result; + } + return totalResult; + } + public override OpStatus Cull() + { + OpStatus totalResult = OpStatus.Success; + foreach (var change in Changes) { + var result = change.Cull(); + if (result.code != OpStatus.Success.code) + totalResult = result; + } + return totalResult; + } + } + + }