public static float checkFloat(string id, ModifierInfo mi)
 {
     float ret = 0;
     //Type t = mi.fpInfos[id].GetValue().GetType();
     var val = mi.fpInfos[id].GetValue();
     if (val is Vector2) //not sure if this works, might need a typeof
     {
         Vector2 vect = (Vector2)(val);
         ret = (vect.X + vect.Y) / 10;
     }
     else
     {
         ret = (float)val;
     }
     return ret;
 }
        public static void VectorSineComposite(Dictionary<string, dynamic> args, ModifierInfo mi)
        {
            Vector2 vector = ((Vector2)mi.fpInfos["v1"].GetValue());
            float timer = (Defaultered("m1", mi, -9999));
            float amp = (Defaultered("amp", args, (OrbIt.ScreenHeight / 5)));
            float period = (Defaultered("period", args, (OrbIt.ScreenWidth / 4)));
            float vshift = (Defaultered("vshift", args, (OrbIt.ScreenHeight / 2)));
            int times = (int)(Defaultered("composite", args, 2));
            //float min = (Defaultered("min", args, 0.1f));
            //float highest = (Defaultered("highest", args, 20f));
            //float o1 = velocity.Length() / highest;
            //o1 = o1 * (max - min) + min;
            //vector.Y = (float)Math.Sin(vector.X / (period / (Math.PI * 2))) * amp + Game1.sHeight / 2;

            //vector.Y = SineComposite(vector.X, amp, period, vshift, times);
            //float test = args["test"];
            //test++;
            //args["test"] = test;
            float x = timer;
            if (x == -9999)
            {
                x = vector.X;
            }

            args["yval"] = SineComposite(x, amp, period, vshift, times);

            mi.fpInfos["v1"].SetValue(vector);
        }
 public static void VelocityToOutput(Dictionary<string, dynamic> args, ModifierInfo mi)
 {
     Vector2 velocity = ((Node)mi.fpInfos["v1"].ob).body.velocity;
     float max = (Defaultered("max", args, 2f));
     float min = (Defaultered("min", args, 0.1f));
     float highest = (Defaultered("highest", args, 20f));
     float o1 = velocity.Length() / highest;
     o1 = o1 * (max - min) + min;
     mi.fpInfos["v1"].SetValue(o1);
 }
        public static void VectorSine(Dictionary<string, dynamic> args, ModifierInfo mi)
        {
            Vector2 vector = ((Vector2)mi.fpInfos["v1"].GetValue());
            float amp = (Defaultered("amp", args, (OrbIt.ScreenHeight / 5)));
            float period = (Defaultered("period", args, (OrbIt.ScreenWidth / 4)));
            //float min = (Defaultered("min", args, 0.1f));
            //float highest = (Defaultered("highest", args, 20f));
            //float o1 = velocity.Length() / highest;
            //o1 = o1 * (max - min) + min;
            vector.Y = (float)Math.Sin(vector.X / (period / (Math.PI * 2))) * amp + OrbIt.ScreenHeight / 2;

            mi.fpInfos["v1"].SetValue(vector);
        }
 public static void TriangleArgs(Dictionary<string, dynamic> args, ModifierInfo mi)
 {
     float o1;// = (float)mi.fpInfos["o1"].GetValue(); //if you'd like to use output in the calculation, include this call (o1 always exists)
     float m1 = Defaultered("m1",mi, 5);
     int mod = (int)(Defaultered("mod", args, 10)) * 10;
     //int mod = 100;
     //scale = ((float)Math.Pow((double)(((int)position.X / 10) % mod) - (mod / 2),2)/2)/(mod*5)+0.5f;
     //scale = ((float)Math.Abs((double)(((int)position.X / 10) % mod) - (mod / 2)) / (mod * 5)) + 0.5f;
     o1 = (mod - (float)Math.Abs(((int)(m1) % (2 * mod) - mod))) / (mod / 5) + 0.5f;
     mi.fpInfos["o1"].SetValue(o1);
 }
 public static void Mod(Dictionary<string, dynamic> args, ModifierInfo mi)
 {
     float o1;// = (float)mi.fpInfos["o1"].GetValue(); //if you'd like to use output in the calculation, include this call (o1 always exists)
     float m1 = Defaultered("m1", mi, 5);
     int mod = (int)(Defaultered("mod",args,10));
     o1 = m1 % mod;
     mi.fpInfos["o1"].SetValue(o1);
 }
 public static float Defaultered(string id, ModifierInfo mi, float defaultval)
 {
     float ret;
     if (mi.fpInfos.ContainsKey(id))
     {
         var val = mi.fpInfos[id].GetValue();
         if (val.GetType() == typeof(float))
         {
             //Console.WriteLine(val.GetType());
             return (float)val;
         }
         else if (val.GetType() == typeof(int))
         {
             return (int)val;
         }
         else if (val.GetType() == typeof(Vector2))
         {
             Vector2 vect = (Vector2)(val);
             ret = (vect.X + vect.Y) / 10;
         }
         else
         {
             ret = defaultval;
         }
     }
     else
     {
         ret = defaultval;
     }
     return ret;
 }
        public static void CloneComponent(Component sourceComp, Component destComp)
        {
            List<FieldInfo> fields = sourceComp.GetType().GetFields().ToList();
            fields.AddRange(sourceComp.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance).ToList());
            List<PropertyInfo> properties = sourceComp.GetType().GetProperties().ToList();
            foreach (PropertyInfo property in properties)
            {
                if (property.PropertyType == typeof(ModifierInfo)) continue;
                if (property.PropertyType == typeof(Node))
                {
                    var cust = property.GetCustomAttributes(typeof(CopyNodeProperty), false);
                    if (cust.Length > 0)
                    {
                        Node n = (Node)property.GetValue(sourceComp, null);
                        Node nclone = n.CreateClone(sourceComp.room);
                        property.SetValue(destComp, nclone, null);
                        //Console.WriteLine("CLONING : " + property.Name);
                    }
                    continue;
                }
                if (Utils.isToggle(property.PropertyType))
                {
                    dynamic tog = property.GetValue(sourceComp, null);
                    dynamic newtog = tog.Clone();
                    property.SetValue(destComp, newtog, null);
                    continue;
                }
                if (property.PropertyType.IsClass)
                {
                    if (!typeof(Delegate).IsAssignableFrom(property.PropertyType) && !(property.PropertyType == typeof(Link)))
                    {
                        //Console.WriteLine("We should be aware of this.");
                    }
                }
                if (property.GetSetMethod() != null)
                property.SetValue(destComp, property.GetValue(sourceComp, null), null);
            }
            foreach (FieldInfo field in fields)
            {
                if (field.Name.Equals("shape")) continue;
                if (field.FieldType == typeof(Dictionary<string,ModifierInfo>))
                {
                    Modifier mod = (Modifier) sourceComp;

                    Dictionary<string, ModifierInfo> newmodinfos = new Dictionary<string, ModifierInfo>();
                    foreach (KeyValuePair<string, ModifierInfo> kvp in mod.modifierInfos)
                    {
                        string key = kvp.Key;
                        ModifierInfo modifierInfo = kvp.Value;
                        Dictionary<string, FPInfo> newFpInfos = new Dictionary<string, FPInfo>();
                        Dictionary<string, object> newFpInfosObj = new Dictionary<string, object>();
                        foreach (string key2 in modifierInfo.fpInfos.Keys)
                        {
                            FPInfo fpinfo = new FPInfo(modifierInfo.fpInfos[key2]);

                            newFpInfos.Add(key2, fpinfo);
                            newFpInfosObj.Add(key2, null);
                        }
                        Dictionary<string, dynamic> newargs = new Dictionary<string, dynamic>();
                        foreach (string key2 in modifierInfo.args.Keys)
                        {
                            newargs.Add(key2, modifierInfo.args[key2]); //by reference (for now)
                        }

                        ModifierInfo modInfo = new ModifierInfo(newFpInfos, newFpInfosObj, newargs, modifierInfo.modifierDelegate);
                        modInfo.delegateName = modifierInfo.delegateName;
                        newmodinfos.Add(key, modInfo);
                    }
                    field.SetValue(destComp, newmodinfos);

                }
                //no longer checking for dictionaries, parent(Node)
                if ((field.FieldType == typeof(int))
                    || (field.FieldType == typeof(Single))
                    || (field.FieldType == typeof(bool))
                    || (field.FieldType == typeof(string)))
                {
                    field.SetValue(destComp, field.GetValue(sourceComp));
                }
                else if (field.FieldType == typeof(Vector2))
                {
                    Vector2 vect = (Vector2)field.GetValue(sourceComp);
                    Vector2 newvect = new Vector2(vect.X, vect.Y);
                    field.SetValue(destComp, newvect);
                }
                else if (field.FieldType == typeof(Color))
                {
                    Color col = (Color)field.GetValue(sourceComp);
                    Color newcol = new Color(col.R, col.G, col.B, col.A);
                    field.SetValue(destComp, newcol);
                }
                else
                {
                    //this would be an object field
                    if (field.Name.Equals("room"))
                    {
                        field.SetValue(destComp, field.GetValue(sourceComp));
                    }
                }
                //field.SetValue(newobj, field.GetValue(obj));
            }
            destComp.InitializeLists();
            destComp.AfterCloning();
        }