Skip to content

Commit

Permalink
change-record group
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed Oct 10, 2018
1 parent 42b2e2f commit 3b01720
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions history/SceneChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,59 @@ public override OpStatus Cull()
}
}




/// <summary>
/// Collection of changes that will be applied in-order, and
/// reverted in opposite order.
/// </summary>
public class ChangeSet : BaseChangeOp
{
List<BaseChangeOp> Changes;

public override string Identifier() { return "ChangeSet"; }

public ChangeSet() {
Changes = new List<BaseChangeOp>();
}
public ChangeSet(IEnumerable<BaseChangeOp> all) {
Changes = new List<BaseChangeOp>(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;
}
}


}

0 comments on commit 3b01720

Please sign in to comment.