Exemple #1
0
        /// <summary>
        /// Exports a behaviour to the given file.
        /// </summary>
        /// <param name="file">The file we want to export to.</param>
        /// <param name="behavior">The behaviour we want to export.</param>
        protected void ExportBehavior(BsonSerializer file, BehaviorNode behavior)
        {
            if (behavior.FileManager == null)
            {
                return;
            }

            file.WriteComment("EXPORTED BY TOOL, DON'T MODIFY IT!");
            file.WriteComment("Source File: " + behavior.MakeRelative(behavior.FileManager.Filename));

            file.WriteStartElement("behavior");

            Behavior b = behavior as Behavior;

            Debug.Check(b != null);
            Debug.Check(b.Id == -1);

            //'\\' ->'/'
            string behaviorName = b.MakeRelative(b.Filename);

            behaviorName = behaviorName.Replace('\\', '/');
            int pos = behaviorName.IndexOf(".xml");

            if (pos != -1)
            {
                behaviorName = behaviorName.Remove(pos);
            }

            file.WriteString(behaviorName);
            file.WriteString(b.AgentType.AgentTypeName);
            file.WriteBool(b.IsFSM);
            file.WriteString(b.Version.ToString());

            this.ExportProperties(file, b);

            this.ExportPars(file, b);

            if (!b.IsFSM)
            {
                this.ExportAttachments(file, b);
            }

            if (b.IsFSM)
            {
                file.WriteStartElement("node");

                file.WriteString("FSM");
                file.WriteString("-1");

                file.WriteStartElement("properties");
                file.WriteAttributeString("initialid", behavior.InitialStateId.ToString());
                file.WriteEndElement();

                foreach (Node child in ((Node)behavior).FSMNodes)
                {
                    this.ExportNode(file, behavior, child);
                }

                file.WriteEndElement();
            }
            else
            {
                // export the children
                foreach (Node child in ((Node)behavior).Children)
                {
                    this.ExportNode(file, behavior, child);
                }
            }

            file.WriteEndElement();
        }
Exemple #2
0
        static private void WritePropertyValue(BsonSerializer file, DesignerPropertyInfo property, object o)
        {
            string str = property.GetExportValue(o);

            string[] tokens      = str.Split(' ');
            string   valueString = null;

            if (tokens.Length == 3 && tokens[0] == "const")
            {
                valueString = tokens[2];
            }
            else if (tokens.Length == 1)
            {
                valueString = str;
            }

            bool bW = false;

            if (valueString != null)
            {
                object obj = property.Property.GetValue(o, null);

                object v = null;

                Type        valueType = null;
                VariableDef varType   = obj as VariableDef;

                if (varType != null)
                {
                    valueType = varType.ValueType;
                }
                else
                {
                    RightValueDef rvarType = obj as RightValueDef;

                    if (rvarType != null)
                    {
                        if (rvarType.Method == null)
                        {
                            valueType = rvarType.ValueType;
                        }
                    }
                    else
                    {
                        MethodDef mType = obj as MethodDef;

                        if (mType != null)
                        {
                            Debug.Check(true);
                        }
                        else
                        {
                            valueType = obj.GetType();
                        }
                    }
                }

                if (valueType != null && Plugin.InvokeTypeParser(null, valueType, valueString, (object value) => v = value, null))
                {
                    file.WriteAttribute(property.Property.Name, v);
                    bW = true;
                }
            }

            if (!bW)
            {
                file.WriteAttributeString(property.Property.Name, str);
            }
        }
Exemple #3
0
        static private void WritePropertyString(BsonSerializer file, DesignerPropertyInfo property, object o)
        {
            string str = property.GetExportValue(o);

            file.WriteAttributeString(property.Property.Name, str);
        }
Exemple #4
0
 static private void WriteProperty(BsonSerializer file, DesignerPropertyInfo property, object o)
 {
     //WritePropertyValue(file, property, o);
     WritePropertyString(file, property, o);
 }
Exemple #5
0
 static private void WritePar(BsonSerializer file, string valueName, ParInfo par)
 {
     //WriteParValue(file, valueName, par);
     WriteParString(file, valueName, par);
 }
Exemple #6
0
        private void ExportProperties(BsonSerializer file, Attachments.Attachment a)
        {
            DesignerPropertyInfo propertyEffector = new DesignerPropertyInfo();

            file.WriteStartElement("properties");
            IList <DesignerPropertyInfo> properties = a.GetDesignerProperties(true);

            foreach (DesignerPropertyInfo p in properties)
            {
                // we skip properties which are not marked to be exported
                if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                {
                    continue;
                }

                object v       = p.Property.GetValue(a, null);
                bool   bExport = !Plugin.IsExportArray(v);

                if (bExport)
                {
                    if (p.Property.Name == "Effectors")
                    {
                        propertyEffector = p;
                    }
                    else
                    {
                        WriteProperty(file, p, a);
                    }
                }
            }

            file.WriteEndElement();

            if (propertyEffector.Property != null)
            {
                List <TransitionEffector> listV = (List <TransitionEffector>)propertyEffector.Property.GetValue(a, null);

                if (listV != null)
                {
                    file.WriteStartElement("attachments");
                    foreach (TransitionEffector te in listV)
                    {
                        file.WriteStartElement("attachment");
                        file.WriteStartElement("properties");
                        IList <DesignerPropertyInfo> effectorProperties = te.GetDesignerProperties();
                        foreach (DesignerPropertyInfo p in effectorProperties)
                        {
                            // we skip properties which are not marked to be exported
                            if (p.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoExport))
                            {
                                continue;
                            }

                            WriteProperty(file, p, te);
                        }

                        file.WriteEndElement();
                        file.WriteEndElement();
                    }

                    file.WriteEndElement();
                }
            }
        }