private static void GenerateInitializers(DomNodeType nodeType, string typeName, StringBuilder sb) { string ns = ""; string name = nodeType.Name; int separator = name.LastIndexOf(':'); // find colon separating ns from name if (separator >= 0) { ns = name.Substring(0, separator); name = name.Substring(separator + 1); } WriteLine(sb, " {0}.Type = getNodeType(\"{1}\", \"{2}\");", typeName, ns, name); foreach (AttributeInfo attributeInfo in nodeType.Attributes) { string attrInfoName = CreateIdentifier(attributeInfo.Name + "Attribute"); WriteLine(sb, " {1}.{0} = {1}.Type.GetAttributeInfo(\"{2}\");", attrInfoName, typeName, attributeInfo.Name); } foreach (ChildInfo childInfo in nodeType.Children) { string childInfoName = CreateIdentifier(childInfo.Name + "Child"); WriteLine(sb, " {1}.{0} = {1}.Type.GetChildInfo(\"{2}\");", childInfoName, typeName, childInfo.Name); } Dictionary <string, XmlNode> attributeTags = new Dictionary <string, XmlNode>(); var localTags = nodeType.GetTagLocal <IEnumerable <XmlNode> >(); if (localTags != null) { foreach (var tag in localTags) { if (tag.Name == "scea.dom.extension") { var extension = GetXmlAttribute(tag, "name"); if (extension != null) { WriteLine(sb, " {0}.Type.Define(new ExtensionInfo<{1}>());", typeName, extension); } } else if (tag.Name == "scea.dom.editors.attribute") { var attrName = GetXmlAttribute(tag, "name"); if (attrName == null) { return; } GenerateAttributeDefault(nodeType, typeName, tag, sb); attributeTags.Add(attrName, tag); } else if (tag.Name == "scea.dom.editors.objectPalette") { GeneratePaletteTag(nodeType, typeName, tag, sb); } } } GenerateAttributeProperties(nodeType, typeName, attributeTags, sb); }
/// <summary> /// Gets all the annotation with given name for /// the given type all the way to the root. /// <remarks> If name is null or empty then get all the annotations.</remarks> /// </summary> public static IEnumerable <XmlElement> GetAllAnnotation(DomNodeType type, string name) { if (type == null) { throw new ArgumentNullException("type"); } var list = new List <XmlElement>(); DomNodeType nodetype = type; while (nodetype != null) { IEnumerable <XmlNode> annotations = nodetype.GetTagLocal <IEnumerable <XmlNode> >(); if (annotations != null) { foreach (var annot in annotations) { if (string.IsNullOrWhiteSpace(name) || annot.LocalName == name) { list.Add((XmlElement)annot); } } } nodetype = nodetype.BaseType; } return(list); }
/// <summary> /// Gets the Xml node with the given local name, searching the type /// and all of its base types</summary> /// <param name="type">DomNodeType whose Tag contains an IEnumerable of XmlNodes</param> /// <param name="name">Node's local name</param> /// <returns>Xml node with the given local name, or null</returns> public static XmlNode FindLocalAnnotation(DomNodeType type, string name) { IEnumerable<XmlNode> annotations = type.GetTagLocal<IEnumerable<XmlNode>>(); if (annotations != null) { foreach (XmlNode xmlNode in annotations) { if (xmlNode.LocalName == name) return xmlNode; } } return null; }
/// <summary> /// Gets the Xml node with the given local name, searching the type /// and all of its base types</summary> /// <param name="type">DomNodeType whose Tag contains an IEnumerable of XmlNodes</param> /// <param name="name">Node's local name</param> /// <returns>Xml node with the given local name, or null</returns> public static XmlNode FindLocalAnnotation(DomNodeType type, string name) { IEnumerable <XmlNode> annotations = type.GetTagLocal <IEnumerable <XmlNode> >(); if (annotations != null) { foreach (XmlNode xmlNode in annotations) { if (xmlNode.LocalName == name) { return(xmlNode); } } } return(null); }
protected override void ParseAnnotations( XmlSchemaSet schemaSet, IDictionary <NamedMetadata, IList <XmlNode> > annotations) { base.ParseAnnotations(schemaSet, annotations); foreach (var kv in annotations) { DomNodeType nodeType = kv.Key as DomNodeType; if (kv.Value.Count == 0) { continue; } // create a hash of hidden attributes HashSet <string> hiddenprops = new HashSet <string>(); foreach (XmlNode xmlnode in kv.Value) { if (xmlnode.LocalName == "scea.dom.editors.attribute") { XmlAttribute hiddenAttrib = xmlnode.Attributes["hide"]; if (hiddenAttrib != null && hiddenAttrib.Value == "true") { XmlAttribute nameAttrib = xmlnode.Attributes["name"]; string name = (nameAttrib != null) ? nameAttrib.Value : null; if (!string.IsNullOrWhiteSpace(name)) { hiddenprops.Add(name); } } LevelEditorXLE.Patches.PatchSchemaAnnotation(xmlnode); } } if (hiddenprops.Count > 0) { nodeType.SetTag(HiddenProperties, hiddenprops); } PropertyDescriptorCollection localDescriptor = nodeType.GetTagLocal <PropertyDescriptorCollection>(); PropertyDescriptorCollection annotationDescriptor = Sce.Atf.Dom.PropertyDescriptor.ParseXml(nodeType, kv.Value); // if the type already have local property descriptors // then add annotation driven property descriptors to it. if (localDescriptor != null) { foreach (System.ComponentModel.PropertyDescriptor propDecr in annotationDescriptor) { localDescriptor.Add(propDecr); } } else { localDescriptor = annotationDescriptor; } if (localDescriptor.Count > 0) { nodeType.SetTag <PropertyDescriptorCollection>(localDescriptor); } // process annotations resourceReferenceTypes. XmlNode rfNode = FindElement(kv.Value, Annotations.ReferenceConstraint.Name); if (rfNode != null) { HashSet <string> extSet = null; string exts = FindAttribute(rfNode, Annotations.ReferenceConstraint.ValidResourceFileExts); if (!string.IsNullOrWhiteSpace(exts)) { exts = exts.ToLower(); char[] sep = { ',' }; extSet = new HashSet <string>(exts.Split(sep, StringSplitOptions.RemoveEmptyEntries)); } else if (m_gameEngine != null) { string restype = FindAttribute(rfNode, Annotations.ReferenceConstraint.ResourceType); ResourceInfo resInfo = m_gameEngine.Info.ResourceInfos.GetByType(restype); if (resInfo != null) { extSet = new HashSet <string>(resInfo.FileExts); } } if (extSet != null) { nodeType.SetTag(Annotations.ReferenceConstraint.ValidResourceFileExts, extSet); } nodeType.SetTag( Annotations.ReferenceConstraint.ResourceType, FindAttribute(rfNode, Annotations.ReferenceConstraint.ResourceType)); } // todo use schema annotation to mark Palette types. XmlNode xmlNode = FindElement(kv.Value, "scea.dom.editors"); if (xmlNode != null) { string name = FindAttribute(xmlNode, "name"); string description = FindAttribute(xmlNode, "description"); string image = FindAttribute(xmlNode, "image"); string category = FindAttribute(xmlNode, "category"); string menuText = FindAttribute(xmlNode, "menuText"); if (!string.IsNullOrEmpty(category)) { NodeTypePaletteItem item = new NodeTypePaletteItem(nodeType, name, description, image, category, menuText); nodeType.SetTag <NodeTypePaletteItem>(item); } } // handle special extensions foreach (XmlNode annot in kv.Value) { if (annot.LocalName == "LeGe.OpaqueListable") { var labelAttrib = annot.Attributes["label"]; if (labelAttrib != null) { string label = labelAttrib.Value; nodeType.SetTag("OpaqueListable", label); } nodeType.Define(new ExtensionInfo <DomNodeAdapters.OpaqueListable>()); } else if (annot.LocalName == "LeGe.GameObjectProperties") { nodeType.Define(new ExtensionInfo <DomNodeAdapters.GameObjectProperties>()); } else if (annot.LocalName == "LeGe.TransformUpdater") { nodeType.Define(new ExtensionInfo <DomNodeAdapters.TransformUpdater>()); } else if (annot.LocalName == "LeGe.TransformObject") { nodeType.Define(new ExtensionInfo <DomNodeAdapters.TransformObject>()); } else if (annot.LocalName == "LeGe.GameContext") { nodeType.Define(new ExtensionInfo <GameContext>()); } else if (annot.LocalName == "LeGe.VisibleLockable") { nodeType.Define(new ExtensionInfo <DomNodeAdapters.VisibleLockable>()); } } } }
protected override void ParseAnnotations( XmlSchemaSet schemaSet, IDictionary <NamedMetadata, IList <XmlNode> > annotations) { base.ParseAnnotations(schemaSet, annotations); foreach (var kv in annotations) { DomNodeType nodeType = kv.Key as DomNodeType; if (nodeType == null || kv.Value.Count == 0) { continue; } // create a hash of hidden attributes HashSet <string> hiddenprops = new HashSet <string>(); foreach (XmlNode xmlnode in kv.Value) { if (xmlnode.LocalName == "scea.dom.editors.attribute") { XmlAttribute hiddenAttrib = xmlnode.Attributes["hide"]; if (hiddenAttrib != null && hiddenAttrib.Value == "true") { XmlAttribute nameAttrib = xmlnode.Attributes["name"]; string name = (nameAttrib != null) ? nameAttrib.Value : null; if (!string.IsNullOrWhiteSpace(name)) { hiddenprops.Add(name); } } } } if (hiddenprops.Count > 0) { nodeType.SetTag(HiddenProperties, hiddenprops); } PropertyDescriptorCollection localDescriptor = nodeType.GetTagLocal <PropertyDescriptorCollection>(); PropertyDescriptorCollection annotationDescriptor = Sce.Atf.Dom.PropertyDescriptor.ParseXml(nodeType, kv.Value); // if the type already have local property descriptors // then add annotation driven property descriptors to it. if (localDescriptor != null) { foreach (System.ComponentModel.PropertyDescriptor propDecr in annotationDescriptor) { localDescriptor.Add(propDecr); } } else { localDescriptor = annotationDescriptor; } if (localDescriptor.Count > 0) { nodeType.SetTag <PropertyDescriptorCollection>(localDescriptor); } // annotations resourceReferenceTypes. XmlNode rfNode = FindElement(kv.Value, Annotations.ReferenceConstraint.Name); if (rfNode != null) { string exts = FindAttribute(rfNode, Annotations.ReferenceConstraint.ValidResourceFileExts); char[] sep = { ';' }; HashSet <string> extSet = new HashSet <string>(exts.Split(sep, StringSplitOptions.RemoveEmptyEntries)); nodeType.SetTag(Annotations.ReferenceConstraint.ValidResourceFileExts, extSet); } // todo use schema annotation to mark Palette types. XmlNode xmlNode = FindElement(kv.Value, "scea.dom.editors"); if (xmlNode != null) { string name = FindAttribute(xmlNode, "name"); string description = FindAttribute(xmlNode, "description"); string image = FindAttribute(xmlNode, "image"); string category = FindAttribute(xmlNode, "category"); string menuText = FindAttribute(xmlNode, "menuText"); NodeTypePaletteItem item = new NodeTypePaletteItem(nodeType, name, description, image, category, menuText); nodeType.SetTag <NodeTypePaletteItem>(item); } } }