Fix TypedChildren shared across ContainerState.

This commit is contained in:
2023-02-09 18:12:33 +08:00
parent 682fe38d40
commit d6c2ac6be6

View File

@@ -87,7 +87,7 @@ namespace Cryville.Crtr.Event {
Container = _ev; Container = _ev;
if (parent != null) { if (parent != null) {
AddChild(_ev, this, parent); AddChild(_ev, parent);
Parent = parent; Parent = parent;
} }
@@ -99,11 +99,13 @@ namespace Cryville.Crtr.Event {
rootPrototype = this; rootPrototype = this;
} }
static void AddChild(EventContainer c, ContainerState s, ContainerState target) { void AddChild(EventContainer c, ContainerState parent) {
target.Children.Add(c, s); parent.Children.Add(c, this);
Type t = c.GetType(); Type t = c.GetType();
if (!target.TypedChildren.ContainsKey(t)) target.TypedChildren.Add(t, new List<ContainerState>()); List<ContainerState> tc;
target.TypedChildren[t].Add(s); if (!parent.TypedChildren.TryGetValue(t, out tc))
parent.TypedChildren.Add(t, tc = new List<ContainerState>());
tc.Add(this);
} }
public ContainerState Clone(byte ct) { public ContainerState Clone(byte ct) {
@@ -119,10 +121,11 @@ namespace Cryville.Crtr.Event {
r.CachedValues = cvs; r.CachedValues = cvs;
r.Children = new Dictionary<EventContainer, ContainerState>(); r.Children = new Dictionary<EventContainer, ContainerState>();
r.TypedChildren = new Dictionary<Type, List<ContainerState>>();
foreach (var child in Children) { foreach (var child in Children) {
var cc = child.Value.Clone(ct); var cc = child.Value.Clone(ct);
cc.Parent = r; cc.Parent = r;
AddChild(child.Key, cc, r); cc.AddChild(child.Key, r);
} }
r.ActiveChildren = new HashSet<EventContainer>(); r.ActiveChildren = new HashSet<EventContainer>();