public void SerializeActorDefinition(string definitionName, Actor myActor)
        {
            definitionName = definitionName.Trim();

            if (definitionName.Length == 0)
                return;

            StringBuilder sb = new StringBuilder(@"Config\");
            sb.Append(s_ActorTemplateDirectory);
            sb.Append(definitionName);
            sb.Append(".adf");

            ConstructorInfo constructor = myActor.GetType().GetConstructor(new Type[] {});
            if (constructor == null)
            {
                Log.Instance.Log("[WARN] Could not serialize actor definition. Actor type '" + myActor.GetType().Name + "' does not have a default constructuor.");
                return;
            }

            Actor template = (Actor)constructor.Invoke(null);

            using (StreamWriter stream = new StreamWriter(sb.ToString()))
            {
                stream.WriteLine("ActorFactory.InitializeActor(" + myActor.GetType().Name + ".Create())");
                SerializeActorProperties(stream, template, myActor);
            }

            // This actor is now of this definition
            myActor.ActorDefinition = definitionName;
        }
 private void SerializeActorProperties(TextWriter stream, Actor template, Actor myActor)
 {
     // Compare all console properties in the current Actor to those of a created version
     PropertyInfo[] properties = template.GetType().GetProperties();
     foreach (PropertyInfo info in properties)
     {
         if (info.GetCustomAttributes(typeof(ConsolePropertyAttribute), true).Length > 0)
         {
             if (!info.GetValue(template, null).Equals(info.GetValue(myActor, null)))
             {
                 object newValue = info.GetValue(myActor, null);
                 stream.Write('\t');
                 stream.Write(info.Name);
                 stream.Write(" = ");
                 // String is a special case as it needs to be enclosed in quotes
                 if (newValue is string)
                 {
                     stream.Write('"');
                     stream.Write(newValue.ToString());
                     stream.Write('"');
                 }
                 // Check if the console has this type registered, meaning it will have
                 // special syntax to write it out.
                 else
                 {
                     ConsoleType type = DeveloperConsole.Instance.ItemManager.GetConsoleType(newValue.GetType());
                     if (type != null)
                     {
                         stream.Write(type.Serialize(newValue));
                     }
                     else
                         stream.Write(newValue.ToString());
                 }
                 stream.WriteLine();
             }
         }
     }
 }
        public void SerializeActor(TextWriter stream, Actor myActor)
        {
            Actor template = null;
            if(myActor.ActorDefinition != null)
            {
                stream.WriteLine("BeginActor(\"" + myActor.ActorDefinition + "\")");
                template = CreateActor(myActor.ActorDefinition);
            }
            else
            {
                ConstructorInfo constructor = myActor.GetType().GetConstructor(new Type[] { });
                if (constructor != null)
                {
                    stream.WriteLine("ActorFactory.InitializeActor(" + myActor.GetType().Name + ".Create())");
                    template = (Actor)constructor.Invoke(null);
                }
            }

            if(template == null)
            {
                Log.Instance.Log("[WARN] Could not serialize actor '" + myActor.Name + "'.  Could not create a template for the actor.");
                return;
            }

            SerializeActorProperties(stream, template, myActor);

            // Write out all tags for the actor
            foreach (string tag in myActor.GetTags())
                stream.WriteLine("\tTag(\"" + tag + "\")");

            stream.WriteLine("EndActor()");
            stream.WriteLine();
        }