/// <summary> /// Constructor. /// </summary> public MiNode() : base() { ID = Identifiable.NewStringID(nameof(MiNode <T>)); Parent = null; m_children = new List <T>(); }
/// <summary> /// Registers a type to a type ID. /// </summary> /// <param name="typeid"> /// Type ID. /// </param> /// <param name="type"> /// Object type. /// </param> /// <param name="replace"> /// If a type is already registered to the type ID, should it be replaced? /// </param> /// <returns> /// True if the type was registered successfully; false if typeid is not a valid ID, type /// is null, or a type is already registered to the ID and replace is false. /// </returns> public bool Register(string typeid, Type type, bool replace = true) { if (!Identifiable.IsValid(typeid)) { return(false); } if (type is null && !m_allownull) { return(false); } if (type is not null && !type.IsSubclassOf(typeof(RT))) { return(false); } if (Registered(typeid)) { if (!replace) { return(true); } m_typemap.Remove(typeid); } m_typemap.Add(typeid, type); return(true); }
/// <summary> /// Creates an array containing the names of all components incompatible with the existing /// components. /// </summary> public string[] GetIncompatibleComponents() { List <string> list = new(); bool ContainsString(string s) { if (!Identifiable.IsValid(s)) { return(false); } for (int i = 0; i < list.Count; i++) { if (list[i].Equals(s)) { return(true); } } return(false); } for (int c = 0; c < ComponentCount; c++) { for (int i = 0; i < list.Count; i++) { if (!ContainsString(m_components[c].IncompatibleComponents[i])) { list.Add(m_components[c].IncompatibleComponents[i]); } } } return(list.ToArray()); }
/// <summary> /// Gets the rect xml string. /// </summary> /// <param name="rect"> /// The rect. /// </param> /// <param name="name"> /// Xml element name. /// </param> /// <param name="indent"> /// Indentation level. /// </param> /// <returns> /// The given rect as an xml string. /// </returns> public static string ToString(IntRect rect, string name = null, uint indent = 0) { if (!Identifiable.IsValid(name)) { name = nameof(IntRect); } StringBuilder sb = new(name.Length + 2); for (int i = 0; i < name.Length + 2; i++) { sb.Append(' '); } string spaces = sb.ToString(); sb.Clear(); sb.Append('<').Append(name).Append(' ') .Append(nameof(IntRect.Left)).Append("=\"").Append(rect.Left).Append("\" ") .Append(nameof(IntRect.Top)).Append("=\"").Append(rect.Top).AppendLine("\"") .Append(spaces) .Append(nameof(IntRect.Width)).Append("=\"").Append(rect.Width).Append("\" ") .Append(nameof(IntRect.Height)).Append("=\"").Append(rect.Height).Append("\"/>"); return(Indent(sb.ToString(), indent)); }
/// <summary> /// Gets the vector xml string. /// </summary> /// <param name="vec"> /// The vector. /// </param> /// <param name="name"> /// Xml element name. /// </param> /// <param name="indent"> /// Indentation level. /// </param> /// <returns> /// The given vector as an xml string. /// </returns> public static string ToString(Vector2i vec, string name = null, uint indent = 0) { if (!Identifiable.IsValid(name)) { name = nameof(Vector2i); } StringBuilder sb = new(); sb.Append('<').Append(name).Append(' ') .Append(nameof(Vector2i.X)[0]).Append("=\"").Append(vec.X).Append("\" ") .Append(nameof(Vector2i.Y)[0]).Append("=\"").Append(vec.Y).Append("\"/>"); return(Indent(sb.ToString(), indent)); }
/// <summary> /// Gets the video mode xml string. /// </summary> /// <param name="vm"> /// The video mode. /// </param> /// <param name="name"> /// Xml element name. /// </param> /// <param name="indent"> /// Indentation level. /// </param> /// <returns> /// The given video mode as an xml string. /// </returns> public static string ToString(VideoMode vm, string name = null, uint indent = 0) { if (!Identifiable.IsValid(name)) { name = nameof(VideoMode); } StringBuilder sb = new(); sb.Append('<').Append(name).Append(' ') .Append(nameof(VideoMode.Width)).Append("=\"").Append(vm.Width).Append("\" ") .Append(nameof(VideoMode.Height)).Append("=\"").Append(vm.Height).Append("\" ") .Append(nameof(VideoMode.BitsPerPixel)).Append("=\"").Append(vm.BitsPerPixel).Append("\"/>"); return(Indent(sb.ToString(), indent)); }
/// <summary> /// Gets the rect xml string. /// </summary> /// <param name="col"> /// The rect. /// </param> /// <param name="name"> /// Xml element name. /// </param> /// <param name="indent"> /// Indentation level. /// </param> /// <returns> /// The given rect as an xml string. /// </returns> public static string ToString(Color col, string name = null, uint indent = 0) { if (!Identifiable.IsValid(name)) { name = nameof(Color); } StringBuilder sb = new(); sb.Append('<').Append(name).Append(' ') .Append(nameof(Color.R)[0]).Append("=\"").Append(col.R).Append("\" ") .Append(nameof(Color.G)[0]).Append("=\"").Append(col.G).Append("\" ") .Append(nameof(Color.B)[0]).Append("=\"").Append(col.B).Append("\" ") .Append(nameof(Color.A)[0]).Append("=\"").Append(col.A).Append("\"/>"); return(Indent(sb.ToString(), indent)); }
/// <summary> /// Registers a type. /// </summary> /// <typeparam name="T"> /// The type. /// </typeparam> /// <param name="typeid"> /// The type ID. /// </param> /// <param name="replace"> /// If an already registered type should be replaced. /// </param> /// <returns> /// True if the type was registered successfully; false if typeid is not a valid ID or a /// type is already registered to the ID and replace is false. /// </returns> public bool Register <T>(string typeid, bool replace = true) where T : class, RT, new() { if (!Identifiable.IsValid(typeid)) { return(false); } if (Registered <T>()) { if (!replace) { return(true); } m_typemap.Remove(typeid); } m_typemap.Add(typeid, typeof(T)); return(true); }