-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventLog.cs
More file actions
63 lines (56 loc) · 2.01 KB
/
EventLog.cs
File metadata and controls
63 lines (56 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using CodeName.Serialization.Validation;
using JetBrains.Annotations;
using Newtonsoft.Json;
namespace CodeName.EventEngine
{
[ValidateSerializeByValue]
public class EventLog<TGameState>
{
[JsonConstructor]
private EventLog() {}
/// <summary>
/// Creates a new event log.
/// </summary>
/// <remarks>
/// Parameters are not cloned.
/// </remarks>
public EventLog(GameEventNode<TGameState> events, TGameState originalState = default, TGameState expectedState = default)
{
OriginalState = originalState;
ExpectedState = expectedState;
Events = events;
}
/// <summary>
/// The events that occurred.
/// </summary>
[NotNull]
[SerializeByValue] public GameEventNode<TGameState> Events { get; set; }
/// <summary>
/// The original state prior to applying the <see cref="Events"/>.
/// Applying the <see cref="Events"/> to the <see cref="OriginalState"/> should result in the <see cref="ExpectedState"/>, if it is available.
/// </summary>
/// <remarks>
/// It is up to the user to decide whether to provide this value or not.
/// </remarks>
[CanBeNull]
[SerializeByValue] public TGameState OriginalState { get; set; }
/// <summary>
/// The expected state after applying the <see cref="Events"/>.
/// </summary>
/// <remarks>
/// It is up to the user to decide whether to provide this value or not.
/// </remarks>
[CanBeNull]
[SerializeByValue] public TGameState ExpectedState { get; set; }
/// <summary>
/// Creates a new event log using the values of this log.
/// </summary>
/// <remarks>
/// Values are not cloned.
/// </remarks>
public EventLog<TGameState> ShallowClone()
{
return new EventLog<TGameState>(Events, OriginalState, ExpectedState);
}
}
}