public static bool CanReference(DomNodeType domtype, IResource resource) { var type = domtype.GetTag(Annotations.ReferenceConstraint.ResourceType) as string; if (type != null) { return(type == resource.Type); } return(false); }
/// <summary> /// Gets display information for the item</summary> /// <param name="item">Item</param> /// <param name="info">Information object, which client can fill out</param> public void GetInfo(object item, ItemInfo info) { DomNodeType nodeType = (DomNodeType)item; NodeTypePaletteItem paletteItem = nodeType.GetTag <NodeTypePaletteItem>(); if (paletteItem != null) { info.Label = paletteItem.Name; info.Description = paletteItem.Description; info.ImageIndex = info.GetImageList().Images.IndexOfKey(paletteItem.ImageName); } }
/// <summary> /// Converts the palette item into an object that can be inserted into an /// IInstancingContext</summary> /// <param name="item">Item to convert</param> /// <returns>Object that can be inserted into an IInstancingContext</returns> public object Convert(object item) { DomNodeType nodeType = (DomNodeType)item; DomNode node = new DomNode(nodeType); NodeTypePaletteItem paletteItem = nodeType.GetTag <NodeTypePaletteItem>(); if (paletteItem != null) { node.SetAttribute(nodeType.IdAttribute, paletteItem.Name); } return(node); }
private static bool CanReference(DomNodeType domtype, IResource resource) { var restraintType = domtype.GetTag(Annotations.ReferenceConstraint.ResourceType) as string; if (restraintType == null) { return(false); } var types = restraintType.Split(','); return(types.Where(x => string.Equals(x, resource.Type, StringComparison.OrdinalIgnoreCase)).FirstOrDefault() != null); }
public static bool CanReference(DomNodeType domtype, IResource resource) { if (domtype == null || resource == null || !Schema.resourceReferenceType.Type.IsAssignableFrom(domtype)) { return(false); } // valid resource file extensions HashSet <string> exts = (HashSet <string>)domtype.GetTag(Annotations.ReferenceConstraint.ValidResourceFileExts); string reExt = Path.GetExtension(resource.Uri.LocalPath).ToLower(); bool canReference = exts == null || exts.Contains(".*") || exts.Contains(reExt); return(canReference); }
/// <summary> /// Gets the palette image for the specified type</summary> /// <remarks>If there is no image for the specified type, it iterates /// through the base class hierarchy to find one</remarks> /// <param name="nodeType">DomNodeType</param> /// <param name="imageList">ImageList to use for finding the image</param> /// <returns>Index of the image if found, -1 if unsuccessful</returns> public static int GetTypeImageIndex(DomNodeType nodeType, ImageList imageList) { int imageIndex = -1; if (nodeType != null) { NodeTypePaletteItem paletteItem = nodeType.GetTag <NodeTypePaletteItem>(); if (paletteItem != null) { imageIndex = imageList.Images.IndexOfKey(paletteItem.ImageName); } } return(imageIndex); }
object IPaletteClient.Convert(object item) { DomNodeType nodeType = (DomNodeType)item; DomNode node = new DomNode(nodeType); NodeTypePaletteItem paletteItem = nodeType.GetTag <NodeTypePaletteItem>(); AttributeInfo idAttribute = nodeType.IdAttribute; if (paletteItem != null && idAttribute != null) { node.SetAttribute(idAttribute, paletteItem.Name); } return(node); }
internal static NativeAttributeInfo GetSecondaryAttribute(DomNodeType type, string name) { var secondaryAttribs = type.GetTag <NativeAttributeInfo[]>(); if (secondaryAttribs != null) { foreach (var a in secondaryAttribs) { if (a.Name.Equals(name)) { return(a); } } } return(null); }
/// <summary> /// Finishes initializing component by adding state and annotation type to palette</summary> void IInitializable.Initialize() { string category = "FSM"; // add state type to palette DomNodeType stateType = Schema.stateType.Type; NodeTypePaletteItem paletteItem = stateType.GetTag <NodeTypePaletteItem>(); if (paletteItem != null) { m_paletteService.AddItem(stateType, category, this); } // add annotation type to palette NodeTypePaletteItem annotationItem = Schema.annotationType.Type.GetTag <NodeTypePaletteItem>(); if (annotationItem != null) { m_paletteService.AddItem(Schema.annotationType.Type, category, this); } }
void IPaletteClient.GetInfo(object item, ItemInfo info) { DomNodeType nodeType = item as DomNodeType; if (nodeType != null) { NodeTypePaletteItem paletteItem = nodeType.GetTag <NodeTypePaletteItem>(); if (paletteItem != null) { info.Label = paletteItem.Name; info.Description = paletteItem.Description; info.ImageIndex = info.GetImageList().Images.IndexOfKey(paletteItem.ImageName); } if (info.ImageIndex == -1) { info.ImageIndex = Util.GetTypeImageIndex(nodeType, info.GetImageList()); } } }
/// <summary> /// Converts the palette item into an object that can be inserted into an /// IInstancingContext</summary> /// <param name="item">Item to convert</param> /// <returns>Object that can be inserted into an IInstancingContext</returns> object IPaletteClient.Convert(object item) { DomNodeType nodeType = (DomNodeType)item; DomNode node = new DomNode(nodeType); NodeTypePaletteItem paletteItem = nodeType.GetTag <NodeTypePaletteItem>(); if (paletteItem != null) { if (nodeType.IdAttribute != null) { node.SetAttribute(nodeType.IdAttribute, paletteItem.Name); // unique id, for referencing } if (nodeType == Schema.stateType.Type) { node.SetAttribute(Schema.stateType.labelAttribute, paletteItem.Name); // user visible name for state } } return(node); }
/// <summary> /// Converts the palette item into an object that can be inserted into an /// IInstancingContext</summary> /// <param name="item">Item to convert</param> /// <returns>Object that can be inserted into an IInstancingContext</returns> object IPaletteClient.Convert(object item) { DomNodeType nodeType = (DomNodeType)item; DomNode node = new DomNode(nodeType); NodeTypePaletteItem paletteItem = nodeType.GetTag <NodeTypePaletteItem>(); if (paletteItem != null) { if (nodeType.IdAttribute != null) { node.SetAttribute(nodeType.IdAttribute, paletteItem.Name); // unique id, for referencing } if (bitBoxSchema.nodeType.Type.IsAssignableFrom(nodeType)) { //string nodeName = m_uniqueNamer.Name(); node.SetAttribute(bitBoxSchema.nodeType.nameAttribute, paletteItem.Name); } } return(node); }
void IInitializable.Initialize() { // parse resource metadata annotation. HashSet <string> metafileExts = new HashSet <string>(); char[] sep = { ';' }; foreach (ChildInfo chInfo in m_schemaLoader.GetRootElements()) { DomNodeType domtype = chInfo.Type; IEnumerable <XmlNode> annotations = domtype.GetTag <IEnumerable <XmlNode> >(); if (annotations == null) { continue; } foreach (XmlElement annot in annotations) { if (annot.LocalName != "ResourceMetadata") { continue; } string metaExt = annot.GetAttribute("metadataFileExt").ToLower(); metafileExts.Add(metaExt); string[] resExts = annot.GetAttribute("resourceFileExts").ToLower().Split(sep, StringSplitOptions.RemoveEmptyEntries); foreach (string ext in resExts) { ResourceMetadataInfo metadataInfo = new ResourceMetadataInfo(chInfo, metaExt); m_extMap.Add(ext, metadataInfo); } } } m_metadataFileExts = new string[metafileExts.Count]; metafileExts.CopyTo(m_metadataFileExts); }
/// <summary> /// Converts the palette item into an object that can be inserted into an /// IInstancingContext</summary> /// <param name="item">Item to convert</param> /// <returns>Object that can be inserted into an IInstancingContext</returns> object IPaletteClient.Convert(object item) { DomNodeType nodeType = (DomNodeType)item; DomNode node = new DomNode(nodeType); NodeTypePaletteItem paletteItem = nodeType.GetTag <NodeTypePaletteItem>(); if (paletteItem != null) { if (nodeType.IdAttribute != null) { node.SetAttribute(nodeType.IdAttribute, paletteItem.Name); // unique id, for referencing } if (nodeType == DomTypes.eventType.Type) { node.SetAttribute(DomTypes.eventType.nameAttribute, paletteItem.Name); } else if (DomTypes.resourceType.Type.IsAssignableFrom(nodeType)) { node.SetAttribute(DomTypes.resourceType.nameAttribute, paletteItem.Name); } } return(node); }
void IInitializable.Initialize() { m_controlInfo = new ControlInfo("DesignView", "DesignView", StandardControlGroup.CenterPermanent); m_controlHostService.RegisterControl(m_designView.HostControl, m_controlInfo, this); Application.ApplicationExit += delegate { Util3D.Shutdown(); GameEngine.Shutdown(); }; GameEngine.RefreshView += (sender, e) => m_designView.InvalidateViews(); m_gameDocumentRegistry.DocumentAdded += m_gameDocumentRegistry_DocumentAdded; m_gameDocumentRegistry.DocumentRemoved += m_gameDocumentRegistry_DocumentRemoved; string ns = m_schemaLoader.NameSpace; // register GridRenderer on grid child. DomNodeType gridType = m_schemaLoader.TypeCollection.GetNodeType(ns, "gridType"); gridType.Define(new ExtensionInfo <GridRenderer>()); // register NativeGameWorldAdapter on game type. m_schemaLoader.GameType.Define(new ExtensionInfo <NativeGameWorldAdapter>()); // parse schema annotation. foreach (DomNodeType domType in m_schemaLoader.TypeCollection.GetNodeTypes()) { IEnumerable <XmlNode> annotations = domType.GetTagLocal <IEnumerable <XmlNode> >(); if (annotations == null) { continue; } // collect all the properties that only exist in native side. List <NativeAttributeInfo> nativeAttribs = new List <NativeAttributeInfo>(); foreach (XmlNode annot in annotations) { XmlElement elm = annot as XmlElement; if (elm.LocalName == NativeAnnotations.NativeType) { string typeName = elm.GetAttribute(NativeAnnotations.NativeName); domType.SetTag(NativeAnnotations.NativeType, GameEngine.GetObjectTypeId(typeName)); if (domType.IsAbstract == false) { domType.Define(new ExtensionInfo <NativeObjectAdapter>()); } } else if (elm.LocalName == NativeAnnotations.NativeProperty) { // find a prop name and added to the attribute. string nativePropName = elm.GetAttribute(NativeAnnotations.NativeName); string attribName = elm.GetAttribute(NativeAnnotations.Name); uint typeId = (uint)domType.GetTag(NativeAnnotations.NativeType); uint propId = GameEngine.GetObjectPropertyId(typeId, nativePropName); if (!string.IsNullOrEmpty(attribName)) { AttributeInfo attribInfo = domType.GetAttributeInfo(elm.GetAttribute(NativeAnnotations.Name)); attribInfo.SetTag(NativeAnnotations.NativeProperty, propId); } else { NativeAttributeInfo attribInfo = new NativeAttributeInfo(domType, nativePropName, typeId, propId); nativeAttribs.Add(attribInfo); } } else if (elm.LocalName == NativeAnnotations.NativeElement) { ChildInfo info = domType.GetChildInfo(elm.GetAttribute(NativeAnnotations.Name)); uint typeId = (uint)domType.GetTag(NativeAnnotations.NativeType); string name = elm.GetAttribute(NativeAnnotations.NativeName); info.SetTag(NativeAnnotations.NativeElement, GameEngine.GetObjectChildListId(typeId, name)); } } if (nativeAttribs.Count > 0) { domType.SetTag(nativeAttribs.ToArray()); } } // register BoundableObject m_schemaLoader.GameObjectType.Define(new ExtensionInfo <BoundableObject>()); m_schemaLoader.GameObjectFolderType.Define(new ExtensionInfo <BoundableObject>()); #region code to handle gameObjectFolder { // This code is fragile and need to be updated whenever // any relevant part of the schema changes. // purpose: // gameObjectFolderType does not exist in C++ // this code will map gameObjectFolderType to gameObjectGroupType. DomNodeType gobFolderType = m_schemaLoader.GameObjectFolderType; DomNodeType groupType = m_schemaLoader.GameObjectGroupType; // map native bound attrib from gameObject to GobFolder NativeAttributeInfo[] nativeAttribs = m_schemaLoader.GameObjectType.GetTag <NativeAttributeInfo[]>(); foreach (var attrib in nativeAttribs) { if (attrib.Name == "Bounds") { gobFolderType.SetTag(new NativeAttributeInfo[] { attrib }); break; } } // map type. gobFolderType.Define(new ExtensionInfo <NativeObjectAdapter>()); gobFolderType.SetTag(NativeAnnotations.NativeType, groupType.GetTag(NativeAnnotations.NativeType)); // map all native attributes of gameObjectGroup to gameFolder foreach (AttributeInfo srcAttrib in groupType.Attributes) { object nativeIdObject = srcAttrib.GetTag(NativeAnnotations.NativeProperty); if (nativeIdObject == null) { continue; } AttributeInfo destAttrib = gobFolderType.GetAttributeInfo(srcAttrib.Name); if (destAttrib == null) { continue; } destAttrib.SetTag(NativeAnnotations.NativeProperty, nativeIdObject); destAttrib.SetTag(NativeAnnotations.MappedAttribute, srcAttrib); } // map native element from gameObjectGroupType to gameObjectFolderType. object gobsId = groupType.GetChildInfo("gameObject").GetTag(NativeAnnotations.NativeElement); foreach (ChildInfo srcChildInfo in gobFolderType.Children) { if (srcChildInfo.IsList) { srcChildInfo.SetTag(NativeAnnotations.NativeElement, gobsId); } } m_schemaLoader.GameType.GetChildInfo("gameObjectFolder").SetTag(NativeAnnotations.NativeElement, gobsId); } #endregion }
unsafe private void UpdateNativeProperty(AttributeInfo attribInfo) { object idObj = attribInfo.GetTag(NativeAnnotations.NativeProperty); if (idObj == null) { return; } uint id = (uint)idObj; if (this.InstanceId == 0) { return; } AttributeInfo mappedAttribute = attribInfo.GetTag(NativeAnnotations.MappedAttribute) as AttributeInfo; DomNodeType definingType = (mappedAttribute != null) ? mappedAttribute.DefiningType : attribInfo.DefiningType; uint typeId = (uint)definingType.GetTag(NativeAnnotations.NativeType); Type clrType = attribInfo.Type.ClrType; Type elmentType = clrType.GetElementType(); object data = this.DomNode.GetAttribute(attribInfo); if (clrType.IsArray && elmentType.IsPrimitive) { GCHandle pinHandle = new GCHandle(); try { pinHandle = GCHandle.Alloc(data, GCHandleType.Pinned); IntPtr ptr = pinHandle.AddrOfPinnedObject(); int sz = Marshal.SizeOf(elmentType); GameEngine.SetObjectProperty(typeId, InstanceId, id, ptr, sz * attribInfo.Type.Length); } finally { if (pinHandle.IsAllocated) { pinHandle.Free(); } } } else { IntPtr ptr = IntPtr.Zero; int sz = 0; if (clrType == typeof(string)) { string str = (string)data; if (!string.IsNullOrEmpty(str)) { fixed(char *chptr = str) { ptr = new IntPtr((void *)chptr); sz = str.Length * 2; GameEngine.SetObjectProperty(typeId, InstanceId, id, ptr, sz); } return; } } else if (clrType == typeof(DateTime)) { DateTime dt = (DateTime)data; float seconds = (float)(dt.Hour * 60 * 60 + dt.Minute * 60 + dt.Second); float secondsInADay = 60.0f * 60.0f * 24.0f; // sec per minute * min per hour * hour per day float normalizedTime = seconds / secondsInADay; // normalize 0.0 to 1.0 ptr = new IntPtr(&normalizedTime); sz = sizeof(float); } else if (clrType == typeof(bool)) { bool val = (bool)data; ptr = new IntPtr(&val); sz = sizeof(bool); } else if (clrType == typeof(byte)) { byte val = (byte)data; ptr = new IntPtr(&val); sz = sizeof(byte); } else if (clrType == typeof(sbyte)) { sbyte val = (sbyte)data; ptr = new IntPtr(&val); sz = sizeof(sbyte); } else if (clrType == typeof(short)) { short val = (short)data; ptr = new IntPtr(&val); sz = sizeof(short); } else if (clrType == typeof(ushort)) { ushort val = (ushort)data; ptr = new IntPtr(&val); sz = sizeof(ushort); } else if (clrType == typeof(int)) { int val = (int)data; ptr = new IntPtr(&val); sz = sizeof(int); } else if (clrType == typeof(uint)) { uint val = (uint)data; ptr = new IntPtr(&val); sz = sizeof(uint); } else if (clrType == typeof(long)) { long val = (long)data; ptr = new IntPtr(&val); sz = sizeof(long); } else if (clrType == typeof(ulong)) { ulong val = (ulong)data; ptr = new IntPtr(&val); sz = sizeof(ulong); } else if (clrType == typeof(float)) { float val = (float)data; ptr = new IntPtr(&val); sz = sizeof(float); } else if (clrType == typeof(double)) { double val = (double)data; ptr = new IntPtr(&val); sz = sizeof(double); } else if (clrType == typeof(System.Uri)) { if (data != null && !string.IsNullOrWhiteSpace(data.ToString())) { Uri uri = (Uri)data; string str = uri.LocalPath; fixed(char *chptr = str) { ptr = new IntPtr((void *)chptr); sz = str.Length * 2; GameEngine.SetObjectProperty(typeId, InstanceId, id, ptr, sz); } return; } } else if (clrType == typeof(DomNode)) { // this is a 'reference' to an object DomNode node = (DomNode)data; NativeObjectAdapter nativeGob = node.As <NativeObjectAdapter>(); if (nativeGob != null) { ptr = new IntPtr((void *)nativeGob.InstanceId); sz = sizeof(ulong); } } GameEngine.SetObjectProperty(typeId, InstanceId, id, ptr, sz); } }
/// <summary> /// Gets the palette image for the specified type</summary> /// <remarks>If there is no image for the specified type, it iterates /// through the base class hierarchy to find one</remarks> /// <param name="nodeType">DomNodeType</param> /// <param name="imageList">ImageList to use for finding the image</param> /// <returns>Index of the image if found, -1 if unsuccessful</returns> public static int GetTypeImageIndex(DomNodeType nodeType, ImageList imageList) { int imageIndex = -1; if (nodeType != null) { NodeTypePaletteItem paletteItem = nodeType.GetTag<NodeTypePaletteItem>(); if (paletteItem != null) imageIndex = imageList.Images.IndexOfKey(paletteItem.ImageName); } return imageIndex; }