예제 #1
0
        private static object ObjectifyField(object obj, FieldInfo fieldInfo)
        {
            object val = fieldInfo.GetValue(obj);

            if (val != null)
            {
                Type type = val.GetType();

                if (val is FontFamily)
                {
                    return((val as FontFamily).Name);
                }
                else if (val is List <ScriptStep> )
                {
                    return(ScriptLabScript.FromToken((ConfigToken)obj));
                }
                else if (IsSerializable(type))
                {
                    return(val);
                }
                else
                {
                    return(MembersToObjectArray(val));
                }
            }
            return(null);
        }
예제 #2
0
 public ScriptLabScript(ScriptLabScript CopyMe)
 {
     allproperties = new List <object[]>(CopyMe.Properties);
     allfields     = new List <object[]>(CopyMe.Fields);
     alleffects    = new List <string>(CopyMe.Effects);
     allnames      = new List <string>(CopyMe.Names);
     allcolors     = new List <Pair <ColorBgra, ColorBgra> >(CopyMe.Colors);
 }
예제 #3
0
        public static ScriptLabScript FromToken(ConfigToken token)
        {
            ScriptLabScript sls = new ScriptLabScript();

            foreach (ScriptStep step in token.effects)
            {
                if (step.EffectType == null)
                {
                    sls.Add(step.Name, step.Name, new object[0], new object[0], Pair.Create(step.PrimaryColor, step.SecondaryColor));
                }
                else if (step.Token == null)
                {
                    sls.Add(step.EffectType.FullName + ":" + step.Name, step.Name, null, null, Pair.Create(step.PrimaryColor, step.SecondaryColor));
                }
                else if (step.Token is PropertyBasedEffectConfigToken)
                {
                    PropertyBasedEffectConfigToken pbect = step.Token as PropertyBasedEffectConfigToken;

                    object[] properties = new object[pbect.Properties.Count];
                    IEnumerator <Property> enumerator = pbect.Properties.Properties.GetEnumerator();

                    for (int i = 0; i < pbect.Properties.Count; i++)
                    {
                        enumerator.MoveNext();

                        if (enumerator.Current.Value is FontFamily)
                        {
                            properties[i] = (enumerator.Current.Value as FontFamily).Name;
                        }
                        else if (enumerator.Current.Value.GetType().IsSerializable)
                        {
                            properties[i] = enumerator.Current.Value;
                        }
                    }

                    sls.Add(step.EffectType.FullName + ":" + step.Name, step.Name, properties, null, Pair.Create(step.PrimaryColor, step.SecondaryColor));
                }
                else
                {
                    object[][] propertiesAndFields = MembersToObjectArray(step.Token);

                    sls.Add(step.EffectType.FullName + ":" + step.Name, step.Name, propertiesAndFields[0], propertiesAndFields[1], Pair.Create(step.PrimaryColor, step.SecondaryColor));
                }
            }

            return(sls);
        }
예제 #4
0
        private bool LoadFile(string filename, out Exception exception)
        {
            exception = null;
            object o;

            if (FileMan.LoadFileBinary(filename, out o, true) || FileMan.LoadFileBinary(filename, out o, false))
            {
                ScriptLabScript sls = o as ScriptLabScript;
                sls.ForceCompatibility();
                ConfigToken token = sls.ToToken(AvailableEffects, Services, EffectSourceSurface);
                lbScript.Items.Clear();
                ((ConfigToken)theEffectToken).effects.Clear();
                ((ConfigToken)theEffectToken).effects.AddRange(token.effects);
                lbScript.Items.AddRange(token.effects.ConvertAll(step => step.Name).ToArray());
                FinishTokenUpdate();
                return(true);
            }
            else
            {
                exception = (Exception)o;
                return(false);
            }
        }
예제 #5
0
        private bool SaveTxtFile(string path, out Exception exception)
        {
            exception = null;
            ScriptLabScript sls = ScriptLabScript.FromToken((ConfigToken)theEffectToken);
            FileStream      fs  = null;

            try
            {
                fs = new FileStream(path, FileMode.Create);
                StreamWriter sw = new StreamWriter(fs);
                for (int i = 0; i < sls.Effects.Count; i++)
                {
                    sw.Write(sls.Names[i]);
                    sw.Write("\t(");
                    sw.Write(sls.Effects[i]);
                    sw.WriteLine(")");
                    sw.Write("\tPrimary:\t#");
                    sw.WriteLine(sls.Colors[i].First.ToHexString());
                    sw.Write("\tSecondary:\t#");
                    sw.WriteLine(sls.Colors[i].Second.ToHexString());
                    sw.WriteLine();

                    string effectname = sls.Effects[i];
                    Type   effecttype;
                    if (AvailableEffects.TryGetValue(effectname, out effecttype))
                    {
                        Effect effect = (Effect)effecttype.GetConstructor(Type.EmptyTypes).Invoke(new object[0]);
                        effect.EnvironmentParameters = Effect.EnvironmentParameters;
                        effect.Services = Services;
                        if (effect.CheckForEffectFlags(EffectFlags.Configurable))
                        {
                            EffectConfigDialog dialog = effect.CreateConfigDialog();
                            EffectConfigToken  token  = dialog.EffectToken;
                            if (effect is PropertyBasedEffect)
                            {
                                PropertyBasedEffectConfigToken pbect      = token as PropertyBasedEffectConfigToken;
                                IEnumerator <Property>         enumerator = pbect.Properties.Properties.GetEnumerator();
                                for (int ii = 0; ii < pbect.Properties.Count; ii++)
                                {
                                    enumerator.MoveNext();
                                    sw.Write("\t");
                                    sw.Write(enumerator.Current.Name);
                                    sw.Write(":\t");
                                    sw.WriteLine(sls.Properties[i][ii]);
                                }
                            }
                            else
                            {
                                Type           tokentype = token.GetType();
                                PropertyInfo[] pi        = tokentype.GetProperties();
                                FieldInfo[]    fi        = tokentype.GetFields();
                                for (int ii = 0; ii < pi.Length; ii++)
                                {
                                    sw.Write("\t");
                                    sw.Write(pi[ii].Name);
                                    sw.Write(":\t");
                                    sw.WriteLine(sls.Properties[i][ii]);
                                }
                                for (int ii = 0; ii < fi.Length; ii++)
                                {
                                    sw.Write("\t");
                                    sw.Write(fi[ii].Name);
                                    sw.Write(":\t");
                                    sw.WriteLine(sls.Fields[i][ii]);
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int ii = 0; ii < sls.Properties.Count; ii++)
                        {
                            sw.Write("\tUnknown Property:\t");
                            sw.WriteLine(sls.Properties[i][ii]);
                        }
                        for (int ii = 0; ii < sls.Fields.Count; ii++)
                        {
                            sw.Write("\tUnknown Field:\t");
                            sw.WriteLine(sls.Fields[i][ii]);
                        }
                    }
                    sw.WriteLine();
                }
                sw.Flush();

                return(true);
            }
            catch (Exception e)
            {
                exception = e;
                return(false);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Dispose();
                }
            }
        }
예제 #6
0
 private bool SaveSlsFile(string path, out Exception exception)
 {
     return(FileMan.SaveFileBinary(path, ScriptLabScript.FromToken((ConfigToken)theEffectToken), out exception, true));
 }