/// <summary> /// Import the data of another <see cref="PrototypeFlattenerHelper"/> /// </summary> /// <param name="helper">the other helper</param> public void Import(PrototypeFlattenerHelper helper) { foreach (var conv in helper.Conversion) { Conversion[conv.Key] = conv.Value; } foreach (var anim in helper.Animations) { Animations[anim.Key] = anim.Value; } }
/// <summary> /// Flatten this whole inheritance tree to a single prototype. After this all changes to /// the inheritance tree are ignored to the previous flatten result. /// All the current informations are stored in the helper. /// </summary> /// <param name="helper"> /// in this helper the information about this objectare stored /// </param> /// <returns>The flattened result</returns> public FlatPrototype Flatten(PrototypeFlattenerHelper helper) { var flat = new FlatPrototype(); Flatten(flat, helper); //flat.Container.AddRange(Container.ConvertAll((pb) => pb.Flatten())); if (flat.RenderName == null) { flat.RenderName = typeof(PrototypeBase).FullName; } flat.Name = Name; return(flat); }
/// <summary> /// Move all reference targets of the flatten result to its variables /// </summary> /// <param name="helper">helper informations</param> /// <param name="prot">flattened result</param> void MoveTargets(PrototypeFlattenerHelper helper, FlatPrototype prot) { foreach (var a in prot.Animations) { a.MoveTargets(helper); } foreach (var c in prot.Container) { MoveTargets(helper, c); } foreach (var p in prot.Parameter) { p.Value.MoveTargets(helper); } }
/// <summary> /// flatten this prototype /// </summary> /// <param name="flat">target of informations</param> /// <param name="helper">information that helps this flattening</param> private void Flatten(FlatPrototype flat, PrototypeFlattenerHelper helper) { if (BasePrototype != null) { BasePrototype.Flatten(flat, helper); } flat.Container.AddRange(Container.ConvertAll((p) => { var h = new PrototypeFlattenerHelper(); var f = p.Flatten(h); helper.Import(h); return(f); })); foreach (var p in flat.Parameter.ToArray()) { if (Parameter.ContainsKey(p.Key)) { var par = p.Value; var current = Parameter[p.Key]; var newPar = current.Clone(); helper.Conversion[par] = newPar; helper.Conversion[current] = newPar; flat.Parameter[p.Key] = newPar; } } foreach (var p in Parameter) { if (!flat.Parameter.ContainsKey(p.Key)) { var par = p.Value.Clone(); helper.Conversion[p.Value] = par; flat.Parameter[p.Key] = par; } } foreach (var a in Animations) { var anim = a.Clone(); helper.Animations[a] = anim; flat.Animations.Add(anim); } MoveTargets(helper, flat); if (RenderName != null) { flat.RenderName = RenderName; } }