public Delegator(Node parent)
 {
     this.parent = parent;
     datastores = new Dictionary<string, DataStore>();
     delegates = new Dictionary<string, MethodEntry>();
     foreach(string key in DelegatorMethods.delegates.Keys)
     {
         delegates[key] = new MethodEntry(this, key);
     }
 }
 public override void AfterCloning()
 {
     if (delegates == null) delegates = new Dictionary<string, MethodEntry>();
     foreach (string key in DelegatorMethods.delegates.Keys)
     {
         if (!delegates.ContainsKey(key))
         {
             delegates[key] = new MethodEntry(this, key);
         }
         else
         {
             MethodEntry me = delegates[key];
             delegates[key] = new MethodEntry(this, key);
             delegates[key].enabled = me.enabled;
         }
     }
 }
 public void RemoveMethodEntry(MethodEntry methodEntry)
 {
     if (methodEntry == null) return;
     string n = methodEntry.name;
     if (!DelegatorMethods.delegates.ContainsKey(n) || !DelegatorMethods.delegateTypes.ContainsKey(n)) return;
     Type type = DelegatorMethods.delegateTypes[n];
     if (type == typeof(Action<Node>))
     {
         if (aSelfDelegates != null && aSelfDelegates.ContainsKey(n)) aSelfDelegates.Remove(n);
         if ((aSelfDelegates != null || aSelfDelegates.Count == 0) && (aSelfDelegatesDS == null || aSelfDelegatesDS.Count == 0)) compType &= ~mtypes.affectself;
     }
     else if (type == typeof(Action<Node, Node>))
     {
         if (aOtherDelegates != null && aOtherDelegates.ContainsKey(n)) aOtherDelegates.Remove(n);
         if ((aOtherDelegates == null || aOtherDelegates.Count == 0) && (aOtherDelegatesDS == null || aOtherDelegatesDS.Count == 0)) compType &= ~mtypes.affectother;
     }
     else if (type == typeof(Action<Node, SpriteBatch>))
     {
         if (drawDelegates != null && drawDelegates.ContainsKey(n)) drawDelegates.Remove(n);
         if ((drawDelegates == null || drawDelegates.Count == 0) && (drawDelegatesDS == null || drawDelegatesDS.Count == 0)) compType &= ~(mtypes.draw | mtypes.minordraw);
     }
     else
     {
         if (type == typeof(Action<Node, DataStore>))
         {
             if (aSelfDelegatesDS != null && aSelfDelegatesDS.ContainsKey(n)) aSelfDelegatesDS.Remove(n);
             if ((aSelfDelegatesDS == null || aSelfDelegatesDS.Count == 0) && (aSelfDelegates == null || aSelfDelegates.Count == 0)) compType &= ~mtypes.affectself;
         }
         else if (type == typeof(Action<Node, Node, DataStore>))
         {
             if (aOtherDelegatesDS != null && aOtherDelegatesDS.ContainsKey(n)) aOtherDelegatesDS.Remove(n);
             if ((aOtherDelegatesDS == null || aOtherDelegatesDS.Count == 0) && (aOtherDelegates == null || aOtherDelegates.Count == 0)) compType &= ~mtypes.affectother;
         }
         else if (type == typeof(Action<Node, SpriteBatch, DataStore>))
         {
             if (drawDelegatesDS != null && drawDelegatesDS.ContainsKey(n)) drawDelegatesDS.Remove(n);
             if ((drawDelegatesDS == null || drawDelegatesDS.Count == 0) && (drawDelegates == null || drawDelegates.Count == 0)) compType &= ~(mtypes.draw | mtypes.minordraw);
         }
     }
     if (datastores.ContainsKey(n)) datastores.Remove(n);
 }
 public void AddMethodEntry(MethodEntry methodEntry)
 {
     if (methodEntry == null) return;
     string n = methodEntry.name;
     if (!DelegatorMethods.delegates.ContainsKey(n) || !DelegatorMethods.delegateTypes.ContainsKey(n)) return;
     Type type = DelegatorMethods.delegateTypes[n];
     dynamic del = DelegatorMethods.delegates[n];
     if (type == typeof(Action<Node>))
     {
         AddAffectSelf(n, del);
     }
     else if (type == typeof(Action<Node, Node>))
     {
         AddAffectOther(n, del);
     }
     else if (type == typeof(Action<Node>))
     {
         AddDraw(n, del);
     }
     else
     {
         DataStore ds = DelegatorMethods.getDataStore(n);
         if (ds == null) return;
         if (type == typeof(Action<Node, DataStore>))
         {
             AddAffectSelfAndDS(n, del, ds);
         }
         else if (type == typeof(Action<Node, Node, DataStore>))
         {
             AddAffectOtherAndDS(n, del, ds);
         }
         else if (type == typeof(Action<Node, SpriteBatch, DataStore>))
         {
             AddDrawAndDS(n, del, ds);
         }
     }
 }