private void ExportDescritorRefs(BsonSerializer file, Behavior b) { if (Plugin.IsQueryFiltered) { return; } if (b.DescriptorRefs.Count > 0) { string propValue = DesignerArray.RetrieveExportValue(b.DescriptorRefs); file.WriteAttributeString("DescriptorRefs", propValue); } string propValue2 = b.Domains; if (!string.IsNullOrEmpty(propValue2)) { file.WriteAttributeString("Domains", propValue2); } }
private void ExportDescritorRefs(BsonSerializer file, Behavior b) { if (b.DescriptorRefs.Count == 0) { return; } string propValue = DesignerArray.RetrieveExportValue(b.DescriptorRefs); file.WriteAttributeString("DescriptorRefs", propValue); }
/// <summary> /// Exports all the properties of a ode and assigns them. /// </summary> /// <param name="file">The file we are exporting to.</param> /// <param name="nodeName">The name of the node we are setting the properties for.</param> /// <param name="node">The node whose properties we are exporting.</param> /// <param name="indent">The indent for the currently generated code.</param> private void ExportProperties(BsonSerializer file, Node n) { IList <DesignerPropertyInfo> properties = n.GetDesignerProperties(); file.WriteStartElement("properties"); 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(n, null); bool bExport = !Plugin.IsExportArray(v);; if (bExport) { // create the code which assigns the value to the node's property //file.Write(string.Format("{0}\t{1}.{2} = {3};\r\n", indent, nodeName, properties[p].Property.Name, properties[p].GetExportValue(node))); string propValue = p.GetExportValue(n); if (propValue != string.Empty && propValue != "\"\"") { WriteProperty(file, p, n); } } } if (n is Task) { Task task = n as Task; file.WriteAttributeString("IsHTN", task.IsHTN ? "true" : "false"); } #if QUERY_EANBLED Behavior b = n as Behavior; if (b != null) { this.ExportDescritorRefs(file, b); } #endif file.WriteEndElement(); }
/// <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) { 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(); }
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.GetValueType(); } 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); } }
static private void WritePropertyString(BsonSerializer file, DesignerPropertyInfo property, object o) { string str = property.GetExportValue(o); file.WriteAttributeString(property.Property.Name, str); }