From b0c6067555025dad380a4902ffc5cd58a0be7f0d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 17 Jul 2024 18:21:13 +0200 Subject: [PATCH] removed all non-recent obsolete methods, properties and types --- CHANGELOG.md | 8 + MLEM.Data/CopyExtensions.cs | 126 ------ MLEM.Data/DynamicEnum.cs | 410 ------------------ MLEM.Data/Json/DynamicEnumConverter.cs | 31 -- MLEM.Data/Json/JsonConverters.cs | 3 - .../Json/JsonTypeSafeGenericDataHolder.cs | 6 - MLEM.Data/NetBufferSerializer.cs | 106 ----- MLEM.Data/NetExtensions.cs | 120 ----- MLEM.Startup/MlemGame.cs | 3 - MLEM.Ui/Elements/Element.cs | 114 +---- MLEM.Ui/Elements/Tooltip.cs | 22 +- MLEM.Ui/Style/StyleProp.cs | 50 +-- MLEM.Ui/UiSystem.cs | 59 +-- MLEM/Extensions/CharExtensions.cs | 29 -- MLEM/Font/GenericFont.cs | 3 - MLEM/Formatting/Codes/Code.cs | 11 - MLEM/Formatting/TextFormatter.cs | 21 +- MLEM/Formatting/TokenizedString.cs | 6 - MLEM/Input/InputHandler.cs | 285 +----------- MLEM/Input/Keybind.cs | 71 --- MLEM/Misc/EnumHelper.cs | 72 --- MLEM/Misc/GenericDataHolder.cs | 14 - 22 files changed, 27 insertions(+), 1543 deletions(-) delete mode 100644 MLEM.Data/CopyExtensions.cs delete mode 100644 MLEM.Data/DynamicEnum.cs delete mode 100644 MLEM.Data/Json/DynamicEnumConverter.cs delete mode 100644 MLEM.Data/NetBufferSerializer.cs delete mode 100644 MLEM.Data/NetExtensions.cs delete mode 100644 MLEM/Extensions/CharExtensions.cs delete mode 100644 MLEM/Misc/EnumHelper.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f136ae..ead7edb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Improvements Removals - Marked SpriteAnimation.ByName obsolete in favor of the new indexer +- **Removed obsolete methods and types CharExtensions, GenericFont.OneEmSpace, Code.GetReplacementString, TokenizedString.Measure, Keybind.GetDownTime, Keybind.GetUpTime, Keybind.GetTimeSincePress, EnumHelper, non-generic GenericDataHolder methods, as well as InputHandler key, gamepad and mouse-specific methods** ### MLEM.Ui Additions @@ -49,11 +50,18 @@ Fixes - Fixed auto-sized elements sometimes updating their location based on outdated parent positions - Fixed Panel.ScrollToElement not scrolling correctly when the panel's area is dirty +Removals +- **Removed obsolete methods and properties Element.BeginImpl, Element.OnDisposed, parameter-heavy versions of Element.DrawTransformed and Element.Draw, Element.DrawEarly, Element.Dispose, Element.BeginDelegate, Tooltip.Paragraph, UiSystem.BlendState, UiSystem.SamplerState, UiSystem.DepthStencilState, UiSystem.Effect, as well as the StyleProp equality members** + ### MLEM.Extended Improvements - **Added compatibility for MonoGame.Extended 4.0.0** - Added compatibility for FNA.Extended +### MLEM.Data +Removals +- **Removed obsolete types DynamicEnumConverter, CopyExtensions, DynamicEnum, NetBufferSerializer, and NetExtensions** + ## 6.3.1 No code changes diff --git a/MLEM.Data/CopyExtensions.cs b/MLEM.Data/CopyExtensions.cs deleted file mode 100644 index a4faf83..0000000 --- a/MLEM.Data/CopyExtensions.cs +++ /dev/null @@ -1,126 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -#if NET6_0_OR_GREATER -using System.Diagnostics.CodeAnalysis; -#endif - -namespace MLEM.Data { - /// - /// A set of extensions for dealing with copying objects. - /// - [Obsolete("CopyExtensions has major flaws and insufficient speed compared to other libraries specifically designed for copying objects.")] -#if NET6_0_OR_GREATER - [UnconditionalSuppressMessage("Aot", "IL3050"), UnconditionalSuppressMessage("Aot", "IL2070"), UnconditionalSuppressMessage("Aot", "IL2090")] -#endif - public static class CopyExtensions { - - private const BindingFlags DefaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; - private static readonly Dictionary ConstructorCache = new Dictionary(); - - /// - /// Creates a shallow copy of the object and returns it. - /// Object creation occurs using a constructor with the or, if none is present, the first constructor with the correct . - /// - /// The object to create a shallow copy of - /// The binding flags for field searching - /// A predicate that determines whether or not the given field should be copied. If null, all fields will be copied. - /// The type of the object to copy - /// A shallow copy of the object - [Obsolete("CopyExtensions has major flaws and insufficient speed compared to other libraries specifically designed for copying objects.")] - public static T Copy(this T obj, BindingFlags flags = CopyExtensions.DefaultFlags, Predicate fieldInclusion = null) { - var copy = (T) CopyExtensions.Construct(typeof(T), flags); - obj.CopyInto(copy, flags, fieldInclusion); - return copy; - } - - /// - /// Creates a deep copy of the object and returns it. - /// Object creation occurs using a constructor with the or, if none is present, the first constructor with the correct . - /// - /// The object to create a deep copy of - /// The binding flags for field searching - /// A predicate that determines whether or not the given field should be copied. If null, all fields will be copied. - /// The type of the object to copy - /// A deep copy of the object - [Obsolete("CopyExtensions has major flaws and insufficient speed compared to other libraries specifically designed for copying objects.")] - public static T DeepCopy(this T obj, BindingFlags flags = CopyExtensions.DefaultFlags, Predicate fieldInclusion = null) { - var copy = (T) CopyExtensions.Construct(typeof(T), flags); - obj.DeepCopyInto(copy, flags, fieldInclusion); - return copy; - } - - /// - /// Copies the given object into the given object in a shallow manner. - /// - /// The object to create a shallow copy of - /// The object to copy into - /// The binding flags for field searching - /// A predicate that determines whether or not the given field should be copied. If null, all fields will be copied. - /// The type of the object to copy - [Obsolete("CopyExtensions has major flaws and insufficient speed compared to other libraries specifically designed for copying objects.")] - public static void CopyInto(this T obj, T otherObj, BindingFlags flags = CopyExtensions.DefaultFlags, Predicate fieldInclusion = null) { - foreach (var field in typeof(T).GetFields(flags)) { - if (fieldInclusion == null || fieldInclusion(field)) - field.SetValue(otherObj, field.GetValue(obj)); - } - } - - /// - /// Copies the given object into the given object in a deep manner. - /// Object creation occurs using a constructor with the or, if none is present, the first constructor with the correct . - /// - /// The object to create a deep copy of - /// The object to copy into - /// The binding flags for field searching - /// A predicate that determines whether or not the given field should be copied. If null, all fields will be copied. - /// The type of the object to copy - [Obsolete("CopyExtensions has major flaws and insufficient speed compared to other libraries specifically designed for copying objects.")] - public static void DeepCopyInto(this T obj, T otherObj, BindingFlags flags = CopyExtensions.DefaultFlags, Predicate fieldInclusion = null) { - foreach (var field in obj.GetType().GetFields(flags)) { - if (fieldInclusion != null && !fieldInclusion(field)) - continue; - var val = field.GetValue(obj); - if (val == null || field.FieldType.IsValueType) { - // if we're a value type (struct or primitive) or null, we can just set the value - field.SetValue(otherObj, val); - } else { - var otherVal = field.GetValue(otherObj); - // if the object we want to copy into doesn't have a value yet, we create one - if (otherVal == null) { - otherVal = CopyExtensions.Construct(field.FieldType, flags); - field.SetValue(otherObj, otherVal); - } - val.DeepCopyInto(otherVal, flags); - } - } - } - - private static object Construct(Type t, BindingFlags flags) { - if (!CopyExtensions.ConstructorCache.TryGetValue(t, out var constructor)) { - var constructors = t.GetConstructors(flags); - // find a contructor with the correct attribute - constructor = constructors.FirstOrDefault(c => c.GetCustomAttribute() != null); - // find a parameterless construcotr - if (constructor == null) - constructor = t.GetConstructor(flags, null, Type.EmptyTypes, null); - // fall back to the first constructor - if (constructor == null) - constructor = constructors.FirstOrDefault(); - if (constructor == null) - throw new NullReferenceException($"Type {t} does not have a constructor with the required visibility"); - CopyExtensions.ConstructorCache.Add(t, constructor); - } - return constructor.Invoke(new object[constructor.GetParameters().Length]); - } - - } - - /// - /// An attribute that, when added to a constructor, will make that constructor the one used by , and . - /// - [AttributeUsage(AttributeTargets.Constructor), Obsolete("CopyExtensions has major flaws and insufficient speed compared to other libraries specifically designed for copying objects.")] - public class CopyConstructorAttribute : Attribute {} -} diff --git a/MLEM.Data/DynamicEnum.cs b/MLEM.Data/DynamicEnum.cs deleted file mode 100644 index f8c6c41..0000000 --- a/MLEM.Data/DynamicEnum.cs +++ /dev/null @@ -1,410 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Reflection; -using MLEM.Data.Json; -using Newtonsoft.Json; - -namespace MLEM.Data { - /// - /// A dynamic enum is a class that represents enum-like single-instance value behavior with additional capabilities, including dynamic addition of new arbitrary values. - /// A dynamic enum uses as its underlying type, allowing for an arbitrary number of enum values to be created, even when a -like structure is used that would only allow for up to 64 values in a regular enum. - /// All enum operations including , , and are supported and can be implemented in derived classes using operator overloads. - /// To create a custom dynamic enum, simply create a class that extends . New values can then be added using , or . - /// - /// - /// To include enum-like operator overloads in a dynamic enum named MyEnum, the following code can be used: - /// - /// public static implicit operator BigInteger(MyEnum value) => GetValue(value); - /// public static implicit operator MyEnum(BigInteger value) => GetEnumValue<MyEnum>(value); - /// public static MyEnum operator |(MyEnum left, MyEnum right) => Or(left, right); - /// public static MyEnum operator &(MyEnum left, MyEnum right) => And(left, right); - /// public static MyEnum operator ^(MyEnum left, MyEnum right) => Xor(left, right); - /// public static MyEnum operator ~(MyEnum value) => Neg(value); - /// - /// - [Obsolete("DynamicEnum has been moved into the DynamicEnums library: https://www.nuget.org/packages/DynamicEnums"), JsonConverter(typeof(DynamicEnumConverter))] -#if NET6_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Aot", "IL2067")] -#endif - public abstract class DynamicEnum { - - private static readonly Dictionary Storages = new Dictionary(); - private readonly BigInteger value; - - private Dictionary allFlagsCache; - private Dictionary anyFlagsCache; - private string name; - - /// - /// Creates a new dynamic enum instance. - /// This constructor is protected as it is only invoked via reflection. - /// - /// The name of the enum value - /// The value - protected DynamicEnum(string name, BigInteger value) { - this.value = value; - this.name = name; - } - - /// - /// Returns true if this enum value has ALL of the given flags on it. - /// This operation is equivalent to . - /// - /// - /// The flags to query - /// True if all of the flags are present, false otherwise - public bool HasFlag(DynamicEnum flags) { - if (this.allFlagsCache == null) - this.allFlagsCache = new Dictionary(); - if (!this.allFlagsCache.TryGetValue(flags, out var ret)) { - ret = (DynamicEnum.GetValue(this) & DynamicEnum.GetValue(flags)) == DynamicEnum.GetValue(flags); - this.allFlagsCache.Add(flags, ret); - } - return ret; - } - - /// - /// Returns true if this enum value has ANY of the given flags on it - /// - /// - /// The flags to query - /// True if one of the flags is present, false otherwise - public bool HasAnyFlag(DynamicEnum flags) { - if (this.anyFlagsCache == null) - this.anyFlagsCache = new Dictionary(); - if (!this.anyFlagsCache.TryGetValue(flags, out var ret)) { - ret = (DynamicEnum.GetValue(this) & DynamicEnum.GetValue(flags)) != 0; - this.anyFlagsCache.Add(flags, ret); - } - return ret; - } - - /// Returns a string that represents the current object. - /// A string that represents the current object. - public override string ToString() { - if (this.name == null) { - var included = new List(); - if (DynamicEnum.GetValue(this) != 0) { - foreach (var v in DynamicEnum.GetValues(this.GetType())) { - if (this.HasFlag(v) && DynamicEnum.GetValue(v) != 0) - included.Add(v); - } - } - this.name = included.Count > 0 ? string.Join(" | ", included) : DynamicEnum.GetValue(this).ToString(); - } - return this.name; - } - - /// - /// Adds a new enum value to the given enum type - /// - /// The name of the enum value to add - /// The value to add - /// The type to add this value to - /// The newly created enum value - /// Thrown if the name or value passed are already present - public static T Add(string name, BigInteger value) where T : DynamicEnum { - var storage = DynamicEnum.GetStorage(typeof(T)); - - // cached parsed values and names might be incomplete with new values - storage.ClearCaches(); - - if (storage.Values.ContainsKey(value)) - throw new ArgumentException($"Duplicate value {value}", nameof(value)); - foreach (var v in storage.Values.Values) { - if (v.name == name) - throw new ArgumentException($"Duplicate name {name}", nameof(name)); - } - - var ret = DynamicEnum.Construct(typeof(T), name, value); - storage.Values.Add(value, ret); - return (T) ret; - } - - /// - /// Adds a new enum value to the given enum type . - /// This method differs from in that it automatically determines a value. - /// The value determined will be the next free number in a sequence, which represents the default behavior in an enum if enum values are not explicitly numbered. - /// - /// The name of the enum value to add - /// The type to add this value to - /// The newly created enum value - public static T AddValue(string name) where T : DynamicEnum { - BigInteger value = 0; - while (DynamicEnum.IsDefined(typeof(T), value)) - value++; - return DynamicEnum.Add(name, value); - } - - /// - /// Adds a new flag enum value to the given enum type . - /// This method differs from in that it automatically determines a value. - /// The value determined will be the next free power of two, allowing enum values to be combined using bitwise operations to create -like behavior. - /// - /// The name of the enum value to add - /// The type to add this value to - /// The newly created enum value - public static T AddFlag(string name) where T : DynamicEnum { - BigInteger value = 1; - while (DynamicEnum.IsDefined(typeof(T), value)) - value <<= 1; - return DynamicEnum.Add(name, value); - } - - /// - /// Returns a collection of all of the enum values that are explicitly defined for the given dynamic enum type . - /// A value counts as explicitly defined if it has been added using , or . - /// - /// The type whose values to get - /// The defined values for the given type - public static IEnumerable GetValues() where T : DynamicEnum { - return DynamicEnum.GetValues(typeof(T)).Cast(); - } - - /// - /// Returns a collection of all of the enum values that are explicitly defined for the given dynamic enum type . - /// A value counts as explicitly defined if it has been added using , or . - /// - /// The type whose values to get - /// The defined values for the given type - public static IEnumerable GetValues(Type type) { - return DynamicEnum.GetStorage(type).Values.Values; - } - - /// - /// Returns all of the defined values from the given dynamic enum type which are contained in . - /// Note that, if combined flags are defined in , and contains them, they will also be returned. - /// - /// The combined flags whose individual flags to return. - /// Whether the enum value 0 should also be returned, if contains one. - /// The type of enum. - /// All of the flags that make up . - public static IEnumerable GetFlags(T combinedFlag, bool includeZero = true) where T : DynamicEnum { - foreach (var flag in DynamicEnum.GetValues()) { - if (combinedFlag.HasFlag(flag) && (includeZero || DynamicEnum.GetValue(flag) != BigInteger.Zero)) - yield return flag; - } - } - - /// - /// Returns all of the defined unique flags from the given dynamic enum type which are contained in . - /// Any combined flags (flags that aren't powers of two) which are defined in will not be returned. - /// - /// The combined flags whose individual flags to return. - /// The type of enum. - /// All of the unique flags that make up . - public static IEnumerable GetUniqueFlags(T combinedFlag) where T : DynamicEnum { - // we can't use the same method here as EnumHelper.GetUniqueFlags since DynamicEnum doesn't guarantee sorted values - var max = DynamicEnum.GetValues().Max(DynamicEnum.GetValue); - var uniqueFlag = BigInteger.One; - while (uniqueFlag <= max) { - if (DynamicEnum.IsDefined(typeof(T), uniqueFlag)) { - var uniqueFlagValue = DynamicEnum.GetEnumValue(uniqueFlag); - if (combinedFlag.HasFlag(uniqueFlagValue)) - yield return uniqueFlagValue; - } - uniqueFlag <<= 1; - } - } - - /// - /// Returns the bitwise OR (|) combination of the two dynamic enum values - /// - /// The left value - /// The right value - /// The type of the values - /// The bitwise OR (|) combination - public static T Or(T left, T right) where T : DynamicEnum { - var cache = DynamicEnum.GetStorage(typeof(T)).OrCache; - if (!cache.TryGetValue((left, right), out var ret)) { - ret = DynamicEnum.GetEnumValue(DynamicEnum.GetValue(left) | DynamicEnum.GetValue(right)); - cache.Add((left, right), ret); - } - return (T) ret; - } - - /// - /// Returns the bitwise AND (&) combination of the two dynamic enum values - /// - /// The left value - /// The right value - /// The type of the values - /// The bitwise AND (&) combination - public static T And(T left, T right) where T : DynamicEnum { - var cache = DynamicEnum.GetStorage(typeof(T)).AndCache; - if (!cache.TryGetValue((left, right), out var ret)) { - ret = DynamicEnum.GetEnumValue(DynamicEnum.GetValue(left) & DynamicEnum.GetValue(right)); - cache.Add((left, right), ret); - } - return (T) ret; - } - - /// - /// Returns the bitwise XOR (^) combination of the two dynamic enum values - /// - /// The left value - /// The right value - /// The type of the values - /// The bitwise XOR (^) combination - public static T Xor(T left, T right) where T : DynamicEnum { - var cache = DynamicEnum.GetStorage(typeof(T)).XorCache; - if (!cache.TryGetValue((left, right), out var ret)) { - ret = DynamicEnum.GetEnumValue(DynamicEnum.GetValue(left) ^ DynamicEnum.GetValue(right)); - cache.Add((left, right), ret); - } - return (T) ret; - } - - /// - /// Returns the bitwise NEG (~) combination of the dynamic enum value - /// - /// The value - /// The type of the values - /// The bitwise NEG (~) value - public static T Neg(T value) where T : DynamicEnum { - var cache = DynamicEnum.GetStorage(typeof(T)).NegCache; - if (!cache.TryGetValue(value, out var ret)) { - ret = DynamicEnum.GetEnumValue(~DynamicEnum.GetValue(value)); - cache.Add(value, ret); - } - return (T) ret; - } - - /// - /// Returns the representation of the given dynamic enum value - /// - /// The value whose number representation to get - /// The value's number representation - public static BigInteger GetValue(DynamicEnum value) { - return value?.value ?? 0; - } - - /// - /// Returns the defined or combined dynamic enum value for the given representation - /// - /// The value whose dynamic enum value to get - /// The type that the returned dynamic enum should have - /// The defined or combined dynamic enum value - public static T GetEnumValue(BigInteger value) where T : DynamicEnum { - return (T) DynamicEnum.GetEnumValue(typeof(T), value); - } - - /// - /// Returns the defined or combined dynamic enum value for the given representation - /// - /// The type that the returned dynamic enum should have - /// The value whose dynamic enum value to get - /// The defined or combined dynamic enum value - public static DynamicEnum GetEnumValue(Type type, BigInteger value) { - var storage = DynamicEnum.GetStorage(type); - - // get the defined value if it exists - if (storage.Values.TryGetValue(value, out var defined)) - return defined; - - // otherwise, cache the combined value - if (!storage.FlagCache.TryGetValue(value, out var combined)) { - combined = DynamicEnum.Construct(type, null, value); - storage.FlagCache.Add(value, combined); - } - return combined; - } - - /// - /// Parses the given into a dynamic enum value and returns the result. - /// This method supports defined enum values as well as values combined using the pipe (|) character and any number of spaces. - /// If no enum value can be parsed, null is returned. - /// - /// The string to parse into a dynamic enum value - /// The type of the dynamic enum value to parse - /// The parsed enum value, or null if parsing fails - public static T Parse(string strg) where T : DynamicEnum { - return (T) DynamicEnum.Parse(typeof(T), strg); - } - - /// - /// Parses the given into a dynamic enum value and returns the result. - /// This method supports defined enum values as well as values combined using the pipe (|) character and any number of spaces. - /// If no enum value can be parsed, null is returned. - /// - /// The type of the dynamic enum value to parse - /// The string to parse into a dynamic enum value - /// The parsed enum value, or null if parsing fails - public static DynamicEnum Parse(Type type, string strg) { - var cache = DynamicEnum.GetStorage(type).ParseCache; - if (!cache.TryGetValue(strg, out var cached)) { - BigInteger? accum = null; - foreach (var val in strg.Split('|')) { - foreach (var defined in DynamicEnum.GetValues(type)) { - if (defined.name == val.Trim()) { - accum = (accum ?? 0) | DynamicEnum.GetValue(defined); - break; - } - } - } - if (accum != null) - cached = DynamicEnum.GetEnumValue(type, accum.Value); - cache.Add(strg, cached); - } - return cached; - } - - /// - /// Returns whether the given is defined in the given dynamic enum . - /// A value counts as explicitly defined if it has been added using , or . - /// - /// The dynamic enum type to query. - /// The value to query. - /// Whether the is defined. - public static bool IsDefined(Type type, BigInteger value) { - return DynamicEnum.GetStorage(type).Values.ContainsKey(value); - } - - /// - /// Returns whether the given is defined in its dynamic enum type. - /// A value counts as explicitly defined if it has been added using , or . - /// - /// The value to query. - /// Whether the is defined. - public static bool IsDefined(DynamicEnum value) { - return value != null && DynamicEnum.IsDefined(value.GetType(), DynamicEnum.GetValue(value)); - } - - private static Storage GetStorage(Type type) { - if (!DynamicEnum.Storages.TryGetValue(type, out var storage)) { - storage = new Storage(); - DynamicEnum.Storages.Add(type, storage); - } - return storage; - } - - private static DynamicEnum Construct(Type type, string name, BigInteger value) { - return (DynamicEnum) Activator.CreateInstance(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] {name, value}, CultureInfo.InvariantCulture); - } - - private class Storage { - - public readonly Dictionary Values = new Dictionary(); - public readonly Dictionary FlagCache = new Dictionary(); - public readonly Dictionary ParseCache = new Dictionary(); - public readonly Dictionary<(DynamicEnum, DynamicEnum), DynamicEnum> OrCache = new Dictionary<(DynamicEnum, DynamicEnum), DynamicEnum>(); - public readonly Dictionary<(DynamicEnum, DynamicEnum), DynamicEnum> AndCache = new Dictionary<(DynamicEnum, DynamicEnum), DynamicEnum>(); - public readonly Dictionary<(DynamicEnum, DynamicEnum), DynamicEnum> XorCache = new Dictionary<(DynamicEnum, DynamicEnum), DynamicEnum>(); - public readonly Dictionary NegCache = new Dictionary(); - - public void ClearCaches() { - this.FlagCache.Clear(); - this.ParseCache.Clear(); - this.OrCache.Clear(); - this.AndCache.Clear(); - this.XorCache.Clear(); - this.NegCache.Clear(); - } - - } - - } -} diff --git a/MLEM.Data/Json/DynamicEnumConverter.cs b/MLEM.Data/Json/DynamicEnumConverter.cs deleted file mode 100644 index 69fc81b..0000000 --- a/MLEM.Data/Json/DynamicEnumConverter.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using Newtonsoft.Json; - -namespace MLEM.Data.Json { - /// - /// Converts a to and from JSON - /// - [Obsolete("DynamicEnum has been moved into the DynamicEnums library: https://www.nuget.org/packages/DynamicEnums"), JsonConverter(typeof(DynamicEnumConverter))] - public class DynamicEnumConverter : JsonConverter { - - /// Writes the JSON representation of the object. - /// The to write to. - /// The value. - /// The calling serializer. - public override void WriteJson(JsonWriter writer, DynamicEnum value, JsonSerializer serializer) { - writer.WriteValue(value.ToString()); - } - - /// Reads the JSON representation of the object. - /// The to read from. - /// Type of the object. - /// The existing value of object being read. If there is no existing value then null will be used. - /// The existing value has a value. - /// The calling serializer. - /// The object value. - public override DynamicEnum ReadJson(JsonReader reader, Type objectType, DynamicEnum existingValue, bool hasExistingValue, JsonSerializer serializer) { - return DynamicEnum.Parse(objectType, reader.Value.ToString()); - } - - } -} diff --git a/MLEM.Data/Json/JsonConverters.cs b/MLEM.Data/Json/JsonConverters.cs index f6fdace..77161c3 100644 --- a/MLEM.Data/Json/JsonConverters.cs +++ b/MLEM.Data/Json/JsonConverters.cs @@ -13,9 +13,6 @@ namespace MLEM.Data.Json { /// public static readonly JsonConverter[] Converters = { new Direction2Converter(), -#pragma warning disable CS0618 - new DynamicEnumConverter(), -#pragma warning restore CS0618 new PointConverter(), new RectangleConverter(), new RectangleFConverter(), diff --git a/MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs b/MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs index ebc1ae9..ef87d0d 100644 --- a/MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs +++ b/MLEM.Data/Json/JsonTypeSafeGenericDataHolder.cs @@ -19,12 +19,6 @@ namespace MLEM.Data.Json { [JsonProperty] private Dictionary data; - /// - [Obsolete("This method will be removed in a future update in favor of the generic SetData.")] - public void SetData(string key, object data) { - this.SetData(key, data); - } - /// public void SetData(string key, T data) { if (EqualityComparer.Default.Equals(data, default)) { diff --git a/MLEM.Data/NetBufferSerializer.cs b/MLEM.Data/NetBufferSerializer.cs deleted file mode 100644 index c06deb0..0000000 --- a/MLEM.Data/NetBufferSerializer.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using Lidgren.Network; -using Newtonsoft.Json; - -namespace MLEM.Data { - /// - /// A net buffer serializer allows easily writing generic objects into a Lidgren.Network . - /// It can be used both for serialization of outgoing packets, and deserialization of incoming packets. - /// Before serializing and deserializing an object, each of the object's fields has to have a handler. New handlers can be added using or . - /// - [Obsolete("Lidgren.Network support is deprecated. Consider using LiteNetLib or a custom implementation instead.")] -#if NET6_0_OR_GREATER - [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Aot", "IL2070")] -#endif - public class NetBufferSerializer { - - private readonly Dictionary> writeFunctions = new Dictionary>(); - private readonly Dictionary> readFunctions = new Dictionary>(); - private readonly Dictionary fieldCache = new Dictionary(); - - /// - /// Create a new net buffer serializer with some default serialization and deserialization implementations for various types. - /// - public NetBufferSerializer() { - foreach (var method in typeof(NetBuffer).GetMethods(BindingFlags.Instance | BindingFlags.Public)) { - if (method.GetParameters().Length == 0 && method.Name.StartsWith("Read", StringComparison.Ordinal) && method.Name.Substring(4) == method.ReturnType.Name) - this.readFunctions[method.ReturnType] = buffer => method.Invoke(buffer, null); - } - foreach (var method in typeof(NetBuffer).GetMethods(BindingFlags.Instance | BindingFlags.Public)) { - if (method.Name.Equals("Write", StringComparison.InvariantCulture)) { - var parameters = method.GetParameters(); - if (parameters.Length == 1) - this.writeFunctions[parameters[0].ParameterType] = (buffer, o) => method.Invoke(buffer, new[] {o}); - } - } - this.AddHandler((buffer, o) => buffer.Write(o), buffer => buffer.ReadVector2()); - this.AddHandler((buffer, o) => buffer.Write(o), buffer => buffer.ReadGuid()); - this.AddHandler((buffer, o) => buffer.Write(o), buffer => buffer.ReadDirection()); - } - - /// - /// Serializes the given object into the given net buffer. - /// Note that each field in the object has to have a handler () - /// - /// The buffer to serialize into - /// The object to serialize - /// The binding flags to search for fields in the object by - /// If any of the object's fields has no writer - public void Serialize(NetBuffer buffer, object o, BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) { - foreach (var field in this.GetFields(o.GetType(), flags)) { - if (!this.writeFunctions.TryGetValue(field.FieldType, out var func)) - throw new ArgumentException($"The type {field.FieldType} doesn't have a writer"); - func(buffer, field.GetValue(o)); - } - } - - /// - /// Deserializes the net buffer's content into the given object. - /// If this is used for packet serialization, a new instance of the required type has to be created before this method is called. - /// - /// The buffer to read the data from - /// The object to serialize into - /// The binding flags to search for fields in the object by - /// If any of the object's fields has no reader - public void Deserialize(NetBuffer buffer, object o, BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) { - foreach (var field in this.GetFields(o.GetType(), flags)) { - if (!this.readFunctions.TryGetValue(field.FieldType, out var func)) - throw new ArgumentException($"The type {field.FieldType} doesn't have a reader"); - field.SetValue(o, func(buffer)); - } - } - - private IEnumerable GetFields(Type type, BindingFlags flags) { - if (!this.fieldCache.TryGetValue(type, out var fields)) { - fields = type.GetFields(flags); - Array.Sort(fields, (f1, f2) => string.Compare(f1.Name, f2.Name, StringComparison.Ordinal)); - this.fieldCache.Add(type, fields); - } - return fields; - } - - /// - /// Adds a manually created deserialization and serialization handler to this net buffer serializer. - /// - /// The function to write the given object into the net buffer - /// The function to read the given object out of the net buffer - /// The type that will be serialized and deserialized - public void AddHandler(Action write, Func read) { - this.writeFunctions.Add(typeof(T), (buffer, o) => write(buffer, (T) o)); - this.readFunctions.Add(typeof(T), buffer => read(buffer)); - } - - /// - /// Adds a JSON-based deserialization and serialization handler to this net buffer serializer. - /// Objects that are serialized in this way are converted to JSON, and the resulting JSON is compressed. - /// - /// The JSON serializer to use - /// The type that will be serialized and deserialized - public void AddHandler(JsonSerializer serializer) { - this.AddHandler((buffer, o) => buffer.WriteObject(o, serializer), buffer => buffer.ReadObject(serializer)); - } - - } -} diff --git a/MLEM.Data/NetExtensions.cs b/MLEM.Data/NetExtensions.cs deleted file mode 100644 index 47adcd5..0000000 --- a/MLEM.Data/NetExtensions.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.IO.Compression; -using Lidgren.Network; -using Microsoft.Xna.Framework; -using MLEM.Misc; -using Newtonsoft.Json; -using Newtonsoft.Json.Bson; - -namespace MLEM.Data { - /// - /// A set of extensions for dealing with . - /// - public static class NetExtensions { - - /// - /// Writes a to the given net buffer - /// - /// The buffer to write to - /// The vector to write - [Obsolete("Lidgren.Network support is deprecated. Consider using LiteNetLib or a custom implementation instead.")] - public static void Write(this NetBuffer buffer, Vector2 vector) { - buffer.Write(vector.X); - buffer.Write(vector.Y); - } - - /// - /// Reads a from the given net buffer - /// - /// The buffer to read from - /// The read vector - [Obsolete("Lidgren.Network support is deprecated. Consider using LiteNetLib or a custom implementation instead.")] - public static Vector2 ReadVector2(this NetBuffer buffer) { - return new Vector2(buffer.ReadFloat(), buffer.ReadFloat()); - } - - /// - /// Writes a to the given net buffer - /// - /// The buffer to write to - /// The guid to write - [Obsolete("Lidgren.Network support is deprecated. Consider using LiteNetLib or a custom implementation instead.")] - public static void Write(this NetBuffer buffer, Guid guid) { - buffer.Write(guid.ToByteArray()); - } - - /// - /// Reads a from the given net buffer - /// - /// The buffer to read from - /// The read guid - [Obsolete("Lidgren.Network support is deprecated. Consider using LiteNetLib or a custom implementation instead.")] - public static Guid ReadGuid(this NetBuffer buffer) { - return new Guid(buffer.ReadBytes(16)); - } - - /// - /// Writes a to the given net buffer - /// - /// The buffer to write to - /// The direction to write - [Obsolete("Lidgren.Network support is deprecated. Consider using LiteNetLib or a custom implementation instead.")] - public static void Write(this NetBuffer buffer, Direction2 direction) { - buffer.Write((short) direction); - } - - /// - /// Reads a from the given net buffer - /// - /// The buffer to read from - /// The read direction - [Obsolete("Lidgren.Network support is deprecated. Consider using LiteNetLib or a custom implementation instead.")] - public static Direction2 ReadDirection(this NetBuffer buffer) { - return (Direction2) buffer.ReadInt16(); - } - - /// - /// Writes a generic object to the given net buffer using a . - /// - /// The buffer to write to - /// The object to write - /// The JSON serializer to use - /// The type of object written - [Obsolete("Lidgren.Network support is deprecated. Consider using LiteNetLib or a custom implementation instead.")] - public static void WriteObject(this NetBuffer buffer, T obj, JsonSerializer serializer) { - if (EqualityComparer.Default.Equals(obj, default)) { - buffer.Write(0); - return; - } - using (var memory = new MemoryStream()) { - using (var stream = new DeflateStream(memory, CompressionLevel.Fastest, true)) - serializer.Serialize(new BsonDataWriter(stream), obj, typeof(T)); - var arr = memory.ToArray(); - buffer.Write(arr.Length); - buffer.Write(arr); - } - } - - /// - /// Reads a generic object from the given buffer using a . - /// - /// The buffer to read from - /// The JSON serializer to use - /// The type of object read - /// The read object - [Obsolete("Lidgren.Network support is deprecated. Consider using LiteNetLib or a custom implementation instead.")] - public static T ReadObject(this NetBuffer buffer, JsonSerializer serializer) { - var length = buffer.ReadInt32(); - if (length <= 0) - return default; - var arr = buffer.ReadBytes(length); - using (var memory = new MemoryStream(arr)) { - using (var stream = new DeflateStream(memory, CompressionMode.Decompress, true)) - return serializer.Deserialize(new BsonDataReader(stream)); - } - } - - } -} diff --git a/MLEM.Startup/MlemGame.cs b/MLEM.Startup/MlemGame.cs index c40e99b..31e9631 100644 --- a/MLEM.Startup/MlemGame.cs +++ b/MLEM.Startup/MlemGame.cs @@ -116,9 +116,6 @@ namespace MLEM.Startup { this.PreDraw?.Invoke(this, gameTime); CoroutineHandler.RaiseEvent(CoroutineEvents.PreDraw); -#pragma warning disable CS0618 - this.UiSystem.DrawEarly(gameTime, this.SpriteBatch); -#pragma warning restore CS0618 this.DoDraw(gameTime); this.UiSystem.Draw(gameTime, this.SpriteBatch); diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index 31247f6..fedefd4 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -18,7 +18,7 @@ namespace MLEM.Ui.Elements { /// /// This class represents a generic base class for ui elements of a . /// - public abstract class Element : GenericDataHolder, IDisposable { + public abstract class Element : GenericDataHolder { /// /// This field holds an epsilon value used in element , position and resulting calculations to mitigate floating point rounding inaccuracies. @@ -202,14 +202,6 @@ namespace MLEM.Ui.Elements { /// Note that, when this is non-null, a new SpriteBatch.Begin call is used for this element. /// public Matrix Transform = Matrix.Identity; - /// - /// The call that this element should make to to begin drawing. - /// Note that, when this is non-null, a new SpriteBatch.Begin call is used for this element. - /// -#pragma warning disable CS0618 - [Obsolete("BeginImpl is deprecated. You can create a custom element class and override Draw instead.")] - public BeginDelegate BeginImpl; -#pragma warning restore CS0618 /// /// Set this field to false to disallow the element from being selected. /// An unselectable element is skipped by automatic navigation and its callback will never be called. @@ -486,12 +478,6 @@ namespace MLEM.Ui.Elements { /// Event that is called when this element is removed from a , that is, when this element's is set to . /// public GenericCallback OnRemovedFromUi; - /// - /// Event that is called when this element's method is called. - /// This event is useful for unregistering global event handlers when this object should be destroyed. - /// - [Obsolete("OnDisposed will be removed in a future update. To unregister custom event handlers, use OnRemovedFromUi instead.")] - public GenericCallback OnDisposed; /// /// A list of all of this element's direct children. @@ -570,12 +556,6 @@ namespace MLEM.Ui.Elements { this.SetSortedChildrenDirty(); } - /// - [Obsolete("Dispose will be removed in a future update. To unregister custom event handlers, use OnRemovedFromUi instead.")] - ~Element() { - this.Dispose(); - } - /// /// Adds a child to this element. /// @@ -1077,32 +1057,14 @@ namespace MLEM.Ui.Elements { /// /// Draws this element by calling internally. - /// If or is set, a new SpriteBatch.Begin call is also started. - /// - /// The game's time - /// The sprite batch to use for drawing - /// The alpha to draw this element and its children with - /// The blend state that is used for drawing - /// The sampler state that is used for drawing - /// The effect that is used for drawing - /// The depth stencil state that is used for drawing - /// The transformation matrix that is used for drawing - [Obsolete("Use DrawTransformed that takes a SpriteBatchContext instead")] - public void DrawTransformed(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, Effect effect, Matrix matrix) { - this.DrawTransformed(time, batch, alpha, new SpriteBatchContext(SpriteSortMode.Deferred, blendState, samplerState, depthStencilState, null, effect, matrix)); - } - - /// - /// Draws this element by calling internally. - /// If or is set, a new SpriteBatch.Begin call is also started. + /// If is set, a new SpriteBatch.Begin call is also started. /// /// The game's time /// The sprite batch to use for drawing /// The alpha to draw this element and its children with /// The sprite batch context to use for drawing public void DrawTransformed(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) { -#pragma warning disable CS0618 - var customDraw = this.BeginImpl != null || this.Transform != Matrix.Identity; + var customDraw = this.Transform != Matrix.Identity; var transformed = context; transformed.TransformMatrix = this.Transform * transformed.TransformMatrix; // TODO ending and beginning again when the matrix changes isn't ideal (https://github.com/MonoGame/MonoGame/issues/3156) @@ -1112,12 +1074,9 @@ namespace MLEM.Ui.Elements { // begin our own draw call batch.Begin(transformed); } -#pragma warning restore CS0618 // draw content in custom begin call -#pragma warning disable CS0618 - this.Draw(time, batch, alpha, transformed.BlendState, transformed.SamplerState, transformed.DepthStencilState, transformed.Effect, transformed.TransformMatrix); -#pragma warning restore CS0618 + this.Draw(time, batch, alpha, transformed); if (this.System != null) this.System.Metrics.Draws++; @@ -1129,23 +1088,6 @@ namespace MLEM.Ui.Elements { } } - /// - /// Draws this element and all of its children. Override this method to draw the content of custom elements. - /// Note that, when this is called, SpriteBatch.Begin has already been called with custom etc. applied. - /// - /// The game's time - /// The sprite batch to use for drawing - /// The alpha to draw this element and its children with - /// The blend state that is used for drawing - /// The sampler state that is used for drawing - /// The effect that is used for drawing - /// The depth stencil state that is used for drawing - /// The transformation matrix that is used for drawing - [Obsolete("Use Draw that takes a SpriteBatchContext instead")] - public virtual void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, Effect effect, Matrix matrix) { - this.Draw(time, batch, alpha, new SpriteBatchContext(SpriteSortMode.Deferred, blendState, samplerState, depthStencilState, null, effect, matrix)); - } - /// /// Draws this element and all of its children. Override this method to draw the content of custom elements. /// Note that, when this is called, SpriteBatch.Begin has already been called with custom etc. applied. @@ -1159,33 +1101,9 @@ namespace MLEM.Ui.Elements { if (this.IsSelected) this.System.InvokeOnSelectedElementDrawn(this, time, batch, alpha, context); - foreach (var child in this.GetRelevantChildren()) { - if (!child.IsHidden) { -#pragma warning disable CS0618 - child.DrawTransformed(time, batch, alpha * child.DrawAlpha, context.BlendState, context.SamplerState, context.DepthStencilState, context.Effect, context.TransformMatrix); -#pragma warning restore CS0618 - } - } - } - - /// - /// Draws this element and all of its early. - /// Drawing early involves drawing onto instances rather than onto the screen. - /// Note that, when this is called, SpriteBatch.Begin has not yet been called. - /// - /// The game's time - /// The sprite batch to use for drawing - /// The alpha to draw this element and its children with - /// The blend state that is used for drawing - /// The sampler state that is used for drawing - /// The effect that is used for drawing - /// The depth stencil state that is used for drawing - /// The transformation matrix that is used for drawing - [Obsolete("DrawEarly is deprecated. For custom implementations, see Panel.Draw for how to replace this method.")] - public virtual void DrawEarly(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, Effect effect, Matrix matrix) { foreach (var child in this.GetRelevantChildren()) { if (!child.IsHidden) - child.DrawEarly(time, batch, alpha * child.DrawAlpha, blendState, samplerState, depthStencilState, effect, matrix); + child.DrawTransformed(time, batch, alpha * child.DrawAlpha, context); } } @@ -1234,13 +1152,6 @@ namespace MLEM.Ui.Elements { return false; } - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - [Obsolete("Dispose will be removed in a future update. To unregister custom event handlers, use OnRemovedFromUi instead.")] - public virtual void Dispose() { - this.OnDisposed?.Invoke(this); - GC.SuppressFinalize(this); - } - /// public override string ToString() { var ret = this.GetType().Name; @@ -1418,20 +1329,5 @@ namespace MLEM.Ui.Elements { /// The element that is considered to be the next element by default public delegate Element GamepadNextElementCallback(Direction2 dir, Element usualNext); - /// - /// A delegate method used for - /// - /// The custom draw group - /// The game's time - /// The sprite batch used for drawing - /// This element's draw alpha - /// The blend state used for drawing - /// The sampler state used for drawing - /// The effect used for drawing - /// The depth stencil state used for drawing - /// The transform matrix used for drawing - [Obsolete("BeginDelegate is deprecated. You can create a custom element class and override Draw instead.")] - public delegate void BeginDelegate(Element element, GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, DepthStencilState depthStencilState, Effect effect, Matrix matrix); - } } diff --git a/MLEM.Ui/Elements/Tooltip.cs b/MLEM.Ui/Elements/Tooltip.cs index 9b16753..bae6a2a 100644 --- a/MLEM.Ui/Elements/Tooltip.cs +++ b/MLEM.Ui/Elements/Tooltip.cs @@ -80,11 +80,6 @@ namespace MLEM.Ui.Elements { } } - /// - /// The paragraph of text that this tooltip displays - /// - [Obsolete("Use Paragraphs instead, which allows for multiple paragraphs to be managed by one tooltip")] - public Paragraph Paragraph; /// /// Determines whether this tooltip should display when is true, which is when the UI is being controlled using a keyboard or gamepad. /// If this tooltip is displayed in auto-nav mode, it will display below the selected element with the applied. @@ -115,11 +110,8 @@ namespace MLEM.Ui.Elements { /// The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively public Tooltip(string text = null, Element elementToHover = null) : base(Anchor.TopLeft, Vector2.One, Vector2.Zero) { - if (text != null) { -#pragma warning disable CS0618 - this.Paragraph = this.AddParagraph(text); -#pragma warning restore CS0618 - } + if (text != null) + this.AddParagraph(text); this.Init(elementToHover); } @@ -130,9 +122,7 @@ namespace MLEM.Ui.Elements { /// The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively public Tooltip(Paragraph.TextCallback textCallback, Element elementToHover = null) : base(Anchor.TopLeft, Vector2.One, Vector2.Zero) { -#pragma warning disable CS0618 - this.Paragraph = this.AddParagraph(textCallback); -#pragma warning restore CS0618 + this.AddParagraph(textCallback); this.Init(elementToHover); } @@ -326,12 +316,6 @@ namespace MLEM.Ui.Elements { private void UpdateParagraphsStyles() { foreach (var paragraph in this.Paragraphs) this.UpdateParagraphStyle(paragraph); - -#pragma warning disable CS0618 - // still set style here in case someone changed the paragraph field manually - if (this.Paragraph != null) - this.UpdateParagraphStyle(this.Paragraph); -#pragma warning restore CS0618 } private void UpdateParagraphStyle(Paragraph paragraph) { diff --git a/MLEM.Ui/Style/StyleProp.cs b/MLEM.Ui/Style/StyleProp.cs index d657ea2..4988f39 100644 --- a/MLEM.Ui/Style/StyleProp.cs +++ b/MLEM.Ui/Style/StyleProp.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using MLEM.Ui.Elements; @@ -9,7 +8,7 @@ namespace MLEM.Ui.Style { /// Note that T implicitly converts to StyleProp{T} and vice versa. /// /// The type of style setting that this property stores - public readonly struct StyleProp : IEquatable> { + public readonly struct StyleProp { /// /// The empty style property, with no and a priority of 0. @@ -72,31 +71,6 @@ namespace MLEM.Ui.Style { return !EqualityComparer.Default.Equals(this.Value, default); } - /// Indicates whether the current object is equal to another object of the same type. - /// An object to compare with this object. - /// true if the current object is equal to the other parameter; otherwise, false. - [Obsolete("StyleProp equality is ambiguous as it is not clear whether priority is taken into account. Compare Values instead.")] - public bool Equals(StyleProp other) { - return EqualityComparer.Default.Equals(this.Value, other.Value); - } - - /// Indicates whether this instance and a specified object are equal. - /// The object to compare with the current instance. - /// true if obj and this instance are the same type and represent the same value; otherwise, false. - [Obsolete("StyleProp equality is ambiguous as it is not clear whether priority is taken into account. Compare Values instead.")] -#pragma warning disable CS0809 - public override bool Equals(object obj) { - return obj is StyleProp other && this.Equals(other); - } - - /// Returns the hash code for this instance. - /// A 32-bit signed integer that is the hash code for this instance. - [Obsolete("StyleProp equality is ambiguous as it is not clear whether priority is taken into account. Compare Values instead.")] - public override int GetHashCode() { - return EqualityComparer.Default.GetHashCode(this.Value); - } -#pragma warning restore CS0809 - /// Returns the fully qualified type name of this instance. /// The fully qualified type name. public override string ToString() { @@ -121,27 +95,5 @@ namespace MLEM.Ui.Style { return new StyleProp(prop); } - /// - /// Compares the two style properties and returns whether they are equal using . - /// - /// The left style property. - /// The right style property. - /// Whether the two style properties are equal. - [Obsolete("StyleProp equality is ambiguous as it is not clear whether priority is taken into account. Compare Values instead.")] - public static bool operator ==(StyleProp left, StyleProp right) { - return left.Equals(right); - } - - /// - /// Compares the two style properties and returns whether they are not equal using . - /// - /// The left style property. - /// The right style property. - /// Whether the two style properties are not equal. - [Obsolete("StyleProp equality is ambiguous as it is not clear whether priority is taken into account. Compare Values instead.")] - public static bool operator !=(StyleProp left, StyleProp right) { - return !left.Equals(right); - } - } } diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index 6f4b791..15afdb6 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -76,29 +76,6 @@ namespace MLEM.Ui { /// public float DrawAlpha = 1; /// - /// The blend state that this ui system and all of its elements draw with - /// - [Obsolete("Set this through SpriteBatchContext instead")] - public BlendState BlendState; - /// - /// The sampler state that this ui system and all of its elements draw with. - /// The default is , as that is the one that works best with pixel graphics. - /// - [Obsolete("Set this through SpriteBatchContext instead")] - public SamplerState SamplerState; - /// - /// The depth stencil state that this ui system and all of its elements draw with. - /// The default is , which is also the default for SpriteBatch.Begin. - /// - [Obsolete("Set this through SpriteBatchContext instead")] - public DepthStencilState DepthStencilState; - /// - /// The effect that this ui system and all of its elements draw with. - /// The default is null, which means that no custom effect will be used. - /// - [Obsolete("Set this through SpriteBatchContext instead")] - public Effect Effect; - /// /// The spriteb atch context that this ui system and all of its elements should draw with. /// The default is , as that is the one that works best with pixel graphics. /// @@ -279,27 +256,6 @@ namespace MLEM.Ui { this.Metrics.UpdateTime += this.stopwatch.Elapsed; } - /// - /// Draws any and other elements that draw onto rather than directly onto the screen. - /// For drawing in this manner to work correctly, this method has to be called before your is cleared, and before everything else in your game is drawn. - /// - /// The game's time - /// The sprite batch to use for drawing - [Obsolete("DrawEarly is deprecated. Calling it is not required anymore, and there is no replacement.")] - public void DrawEarly(GameTime time, SpriteBatch batch) { - this.Metrics.ResetDraws(); - this.stopwatch.Restart(); - - foreach (var root in this.rootElements) { - if (!root.Element.IsHidden) - root.Element.DrawEarly(time, batch, this.DrawAlpha * root.Element.DrawAlpha, this.BlendState, this.SamplerState, this.DepthStencilState, this.Effect, root.Transform); - } - - this.stopwatch.Stop(); - this.Metrics.DrawTime += this.stopwatch.Elapsed; - this.drewEarly = true; - } - /// /// Draws any s onto the screen. /// @@ -316,21 +272,8 @@ namespace MLEM.Ui { var context = this.SpriteBatchContext; context.TransformMatrix = root.Transform * context.TransformMatrix; -#pragma warning disable CS0618 - if (this.BlendState != null) - context.BlendState = this.BlendState; - if (this.SamplerState != null) - context.SamplerState = this.SamplerState; - if (this.DepthStencilState != null) - context.DepthStencilState = this.DepthStencilState; - if (this.Effect != null) - context.Effect = this.Effect; -#pragma warning restore CS0618 - batch.Begin(context); -#pragma warning disable CS0618 - root.Element.DrawTransformed(time, batch, this.DrawAlpha * root.Element.DrawAlpha, context.BlendState, context.SamplerState, context.DepthStencilState, context.Effect, context.TransformMatrix); -#pragma warning restore CS0618 + root.Element.DrawTransformed(time, batch, this.DrawAlpha * root.Element.DrawAlpha, context); batch.End(); } diff --git a/MLEM/Extensions/CharExtensions.cs b/MLEM/Extensions/CharExtensions.cs deleted file mode 100644 index 143c9f2..0000000 --- a/MLEM/Extensions/CharExtensions.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace MLEM.Extensions { - /// - /// A set of extensions for dealing with - /// - [Obsolete("ToCachedString is deprecated. Consider using a more robust, custom implementation for text caching, or CodePointSource.ToString for UTF-32 caching.")] - public static class CharExtensions { - - private static readonly Dictionary Cache = new Dictionary(); - - /// - /// Returns the string representation of this character which will be stored and retrieved from a dictionary cache. - /// This method reduces string allocations, making it trade in processor efficiency for memory efficiency. - /// - /// The character to turn into a string - /// A string representing the character - [Obsolete("ToCachedString is deprecated. Consider using a more robust, custom implementation for text caching, or CodePointSource.ToString for UTF-32 caching.")] - public static string ToCachedString(this char c) { - if (!CharExtensions.Cache.TryGetValue(c, out var ret)) { - ret = c.ToString(); - CharExtensions.Cache.Add(c, ret); - } - return ret; - } - - } -} diff --git a/MLEM/Font/GenericFont.cs b/MLEM/Font/GenericFont.cs index fe96299..4eee844 100644 --- a/MLEM/Font/GenericFont.cs +++ b/MLEM/Font/GenericFont.cs @@ -21,9 +21,6 @@ namespace MLEM.Font { /// Whereas a regular would have to explicitly support this character for width calculations, generic fonts implicitly support it in . /// public const char Emsp = '\u2003'; - /// - [Obsolete("Use the Emsp field instead.")] - public const char OneEmSpace = GenericFont.Emsp; /// /// This field holds the unicode representation of a non-breaking space. /// Whereas a regular would have to explicitly support this character for width calculations, generic fonts implicitly support it in . diff --git a/MLEM/Formatting/Codes/Code.cs b/MLEM/Formatting/Codes/Code.cs index 2969105..f2c8ec3 100644 --- a/MLEM/Formatting/Codes/Code.cs +++ b/MLEM/Formatting/Codes/Code.cs @@ -80,17 +80,6 @@ namespace MLEM.Formatting.Codes { /// The game's time public virtual void Update(GameTime time) {} - /// - /// Returns the string that this formatting code should be replaced with. - /// Usually, you'll just want an empty string here, but some formatting codes (like ) require their space to be filled by spaces. - /// - /// The font that is used - /// The replacement string for this formatting code - [Obsolete("This method is deprecated. Use GetSelfWidth to add additional width to this code and DrawSelf or DrawCharacter to draw additional items.")] - public virtual string GetReplacementString(GenericFont font) { - return string.Empty; - } - /// public virtual bool DrawCharacter(GameTime time, SpriteBatch batch, int codePoint, string character, Token token, int indexInToken, Vector2 stringPos, ref Vector2 charPosOffset, GenericFont font, ref Color color, ref Vector2 scale, ref float rotation, ref Vector2 origin, float depth, SpriteEffects effects, Vector2 stringSize, Vector2 charSize) { return false; diff --git a/MLEM/Formatting/TextFormatter.cs b/MLEM/Formatting/TextFormatter.cs index f17124d..1459273 100644 --- a/MLEM/Formatting/TextFormatter.cs +++ b/MLEM/Formatting/TextFormatter.cs @@ -169,14 +169,14 @@ namespace MLEM.Formatting { // if we've reached the end of the string if (next == null) { var sub = s.Substring(rawIndex, s.Length - rawIndex); - tokens.Add(new Token(applied.ToArray(), index, rawIndex, TextFormatter.StripFormatting(font, sub, applied), sub)); + tokens.Add(new Token(applied.ToArray(), index, rawIndex, TextFormatter.StripFormatting(sub, applied.Select(c => c.Regex)), sub)); break; } allCodes.Add(next); // create a new token for the content up to the next code var ret = s.Substring(rawIndex, next.Match.Index - rawIndex); - var strippedRet = TextFormatter.StripFormatting(font, ret, applied); + var strippedRet = TextFormatter.StripFormatting(ret, applied.Select(c => c.Regex)); tokens.Add(new Token(applied.ToArray(), index, rawIndex, strippedRet, ret)); // move to the start of the next code @@ -187,7 +187,7 @@ namespace MLEM.Formatting { applied.RemoveAll(c => c.EndsHere(next) || next.EndsOther(c)); applied.Add(next); } - return new TokenizedString(font, alignment, s, TextFormatter.StripFormatting(font, s, allCodes), tokens.ToArray(), allCodes.ToArray()); + return new TokenizedString(font, alignment, s, TextFormatter.StripFormatting(s, allCodes.Select(c => c.Regex)), tokens.ToArray(), allCodes.ToArray()); } /// @@ -224,9 +224,7 @@ namespace MLEM.Formatting { /// The string to strip formatting codes from. /// The stripped string. public string StripAllFormatting(string s) { - foreach (var regex in this.Codes.Keys) - s = regex.Replace(s, string.Empty); - return s; + return TextFormatter.StripFormatting(s, this.Codes.Keys); } private Code GetNextCode(string s, int index, int maxIndex = int.MaxValue) { @@ -238,14 +236,9 @@ namespace MLEM.Formatting { return constructor?.Invoke(this, match, regex); } - private static string StripFormatting(GenericFont font, string s, IEnumerable codes) { - foreach (var code in codes) { -#pragma warning disable CS0618 - // this can be combined with StripAllFormatting (which was added after GetReplacementString was deprecated) once GetReplacementString is removed - // (just make this method accept a set of regular expressions, and then call it with all code keys in StripAllFormatting, and the applied codes' regexes in Tokenize) - s = code.Regex.Replace(s, code.GetReplacementString(font)); -#pragma warning restore CS0618 - } + private static string StripFormatting(string s, IEnumerable codes) { + foreach (var code in codes) + s = code.Replace(s, string.Empty); return s; } diff --git a/MLEM/Formatting/TokenizedString.cs b/MLEM/Formatting/TokenizedString.cs index c6f07d9..9c40b82 100644 --- a/MLEM/Formatting/TokenizedString.cs +++ b/MLEM/Formatting/TokenizedString.cs @@ -137,12 +137,6 @@ namespace MLEM.Formatting { } } - /// - [Obsolete("Measure is deprecated. Use GetArea, which returns the string's total size measurement, instead.")] - public Vector2 Measure(GenericFont font) { - return this.GetArea().Size; - } - /// /// Measures the area that this entire tokenized string and all of its take up and returns it as a . /// diff --git a/MLEM/Input/InputHandler.cs b/MLEM/Input/InputHandler.cs index c17ce25..f513135 100644 --- a/MLEM/Input/InputHandler.cs +++ b/MLEM/Input/InputHandler.cs @@ -84,12 +84,12 @@ namespace MLEM.Input { public bool HandleGamepadRepeats = true; /// /// This field represents the deadzone that gamepad have when input is queried for them using this input handler. - /// A deadzone is the percentage (between 0 and 1) that an analog value has to exceed for it to be considered down () or pressed (). + /// A deadzone is the percentage (between 0 and 1) that an analog value has to exceed for it to be considered down () or pressed (). /// Querying of analog values is done using . /// public float GamepadButtonDeadzone; /// - /// Set this field to true to invert the press behavior of , , and . + /// Set this field to true to invert the press behavior of . /// Inverted behavior means that, instead of an input counting as pressed when it was up in the last frame and is now down, it will be counted as pressed when it was down in the last frame and is now up. /// public bool InvertPressBehavior; @@ -414,287 +414,6 @@ namespace MLEM.Input { } return false; } - - /// - [Obsolete("This method is deprecated. Use the GenericInput version IsDown instead.")] - public bool IsKeyDown(Keys key) { - return this.KeyboardState.IsKeyDown(key); - } - - /// - [Obsolete("This method is deprecated. Use the GenericInput version IsUp instead.")] - public bool IsKeyUp(Keys key) { - return this.KeyboardState.IsKeyUp(key); - } - - /// - [Obsolete("This method is deprecated. Use the GenericInput version WasDown instead.")] - public bool WasKeyDown(Keys key) { - return this.LastKeyboardState.IsKeyDown(key); - } - - /// - [Obsolete("This method is deprecated. Use the GenericInput version WasUp instead.")] - public bool WasKeyUp(Keys key) { - return this.LastKeyboardState.IsKeyUp(key); - } - - /// - /// Returns whether the given key is considered pressed. - /// A key is considered pressed if it was not down the last update call, but is down the current update call. If is true, this behavior is inverted. - /// If is true, this method will also return true to signify a key repeat. - /// - /// The key to query - /// If the key is pressed - [Obsolete("This method is deprecated. Use the GenericInput version IsPressed instead.")] - public bool IsKeyPressed(Keys key) { - // if the queried key is the held key and a repeat should be triggered, return true - if (this.HandleKeyboardRepeats && key == this.heldKey && this.triggerKeyRepeat) - return true; - return this.IsKeyPressedIgnoreRepeats(key); - } - - /// - /// Returns whether the given key is considered pressed. - /// A key is considered pressed if it was not down the last update call, but is down the current update call. If is true, this behavior is inverted. - /// This has the same behavior as , but ignores keyboard repeat events. - /// If is false, this method does the same as . - /// - /// The key to query - /// If the key is pressed - [Obsolete("This method is deprecated. Use the GenericInput version IsPressedIgnoreRepeats instead.")] - public bool IsKeyPressedIgnoreRepeats(Keys key) { - if (this.InvertPressBehavior) - return this.WasKeyDown(key) && this.IsKeyUp(key); - return this.WasKeyUp(key) && this.IsKeyDown(key); - } - - /// - /// Returns if the given key is considered pressed, and if the press has not been consumed yet using . - /// - /// The key to query. - /// If the key is pressed and the press is not consumed yet. - [Obsolete("This method is deprecated. Use the GenericInput version IsPressedAvailable instead.")] - public bool IsKeyPressedAvailable(Keys key) { - return this.IsKeyPressed(key) && !this.IsPressConsumed(key); - } - - /// - /// Returns whether the given key is considered pressed, and marks the press as consumed if it is. - /// A key is considered pressed if it was not down the last update call, but is down the current update call. - /// A key press is considered consumed if this method has already returned true previously since the last call. - /// If is true, this method will also return true to signify a key repeat. - /// - /// The key to query. - /// If the key is pressed and the press is not consumed yet. - [Obsolete("This method is deprecated. Use the GenericInput version TryConsumePressed instead.")] - public bool TryConsumeKeyPressed(Keys key) { - if (this.IsKeyPressedAvailable(key)) { - this.consumedPresses.Add((key, -1)); - return true; - } - return false; - } - - /// - /// Returns whether the given mouse button is currently down. - /// - /// The button to query - /// Whether or not the queried button is down - [Obsolete("This method is deprecated. Use the GenericInput version IsDown instead.")] - public bool IsMouseButtonDown(MouseButton button) { - return this.MouseState.GetState(button) == ButtonState.Pressed; - } - - /// - /// Returns whether the given mouse button is currently up. - /// - /// The button to query - /// Whether or not the queried button is up - [Obsolete("This method is deprecated. Use the GenericInput version IsUp instead.")] - public bool IsMouseButtonUp(MouseButton button) { - return this.MouseState.GetState(button) == ButtonState.Released; - } - - /// - /// Returns whether the given mouse button was down the last update call. - /// - /// The button to query - /// Whether or not the queried button was down - [Obsolete("This method is deprecated. Use the GenericInput version WasDown instead.")] - public bool WasMouseButtonDown(MouseButton button) { - return this.LastMouseState.GetState(button) == ButtonState.Pressed; - } - - /// - /// Returns whether the given mouse button was up the last update call. - /// - /// The button to query - /// Whether or not the queried button was up - [Obsolete("This method is deprecated. Use the GenericInput version WasUp instead.")] - public bool WasMouseButtonUp(MouseButton button) { - return this.LastMouseState.GetState(button) == ButtonState.Released; - } - - /// - /// Returns whether the given mouse button is considered pressed. - /// A mouse button is considered pressed if it was up the last update call, and is down the current update call. If is true, this behavior is inverted. - /// - /// The button to query - /// Whether the button is pressed - [Obsolete("This method is deprecated. Use the GenericInput version IsPressed instead.")] - public bool IsMouseButtonPressed(MouseButton button) { - if (this.InvertPressBehavior) - return this.WasMouseButtonDown(button) && this.IsMouseButtonUp(button); - return this.WasMouseButtonUp(button) && this.IsMouseButtonDown(button); - } - - /// - /// Returns if the given mouse button is considered pressed, and if the press has not been consumed yet using . - /// - /// The button to query. - /// If the button is pressed and the press is not consumed yet. - [Obsolete("This method is deprecated. Use the GenericInput version IsPressedAvailable instead.")] - public bool IsMouseButtonPressedAvailable(MouseButton button) { - return this.IsMouseButtonPressed(button) && !this.IsPressConsumed(button); - } - - /// - /// Returns whether the given mouse button is considered pressed, and marks the press as consumed if it is. - /// A mouse button is considered pressed if it was up the last update call, and is down the current update call. - /// A mouse button press is considered consumed if this method has already returned true previously since the last call. - /// - /// The button to query. - /// If the button is pressed and the press is not consumed yet. - [Obsolete("This method is deprecated. Use the GenericInput version TryConsumePressed instead.")] - public bool TryConsumeMouseButtonPressed(MouseButton button) { - if (this.IsMouseButtonPressedAvailable(button)) { - this.consumedPresses.Add((button, -1)); - return true; - } - return false; - } - - /// - [Obsolete("This method is deprecated. Use the GenericInput version IsDown instead.")] - public bool IsGamepadButtonDown(Buttons button, int index = -1) { - if (index < 0) { - for (var i = 0; i < this.ConnectedGamepads; i++) { - if (this.GetGamepadState(i).GetAnalogValue(button) > this.GamepadButtonDeadzone) - return true; - } - return false; - } - return this.GetGamepadState(index).GetAnalogValue(button) > this.GamepadButtonDeadzone; - } - - /// - [Obsolete("This method is deprecated. Use the GenericInput version IsUp instead.")] - public bool IsGamepadButtonUp(Buttons button, int index = -1) { - if (index < 0) { - for (var i = 0; i < this.ConnectedGamepads; i++) { - if (this.GetGamepadState(i).GetAnalogValue(button) <= this.GamepadButtonDeadzone) - return true; - } - return false; - } - return this.GetGamepadState(index).GetAnalogValue(button) <= this.GamepadButtonDeadzone; - } - - /// - [Obsolete("This method is deprecated. Use the GenericInput version WasDown instead.")] - public bool WasGamepadButtonDown(Buttons button, int index = -1) { - if (index < 0) { - for (var i = 0; i < this.ConnectedGamepads; i++) { - if (this.GetLastGamepadState(i).GetAnalogValue(button) > this.GamepadButtonDeadzone) - return true; - } - return false; - } - return this.GetLastGamepadState(index).GetAnalogValue(button) > this.GamepadButtonDeadzone; - } - - /// - [Obsolete("This method is deprecated. Use the GenericInput version WasUp instead.")] - public bool WasGamepadButtonUp(Buttons button, int index = -1) { - if (index < 0) { - for (var i = 0; i < this.ConnectedGamepads; i++) { - if (this.GetLastGamepadState(i).GetAnalogValue(button) <= this.GamepadButtonDeadzone) - return true; - } - return false; - } - return this.GetLastGamepadState(index).GetAnalogValue(button) <= this.GamepadButtonDeadzone; - } - - /// - /// Returns whether the given gamepad button on the given index is considered pressed. - /// A gamepad button is considered pressed if it was down the last update call, and is up the current update call. If is true, this behavior is inverted. - /// If is true, this method will also return true to signify a gamepad button repeat. - /// - /// The button to query - /// The zero-based index of the gamepad, or -1 for any gamepad - /// Whether the given button is pressed - [Obsolete("This method is deprecated. Use the GenericInput version IsPressed instead.")] - public bool IsGamepadButtonPressed(Buttons button, int index = -1) { - if (this.HandleGamepadRepeats) { - if (index < 0) { - for (var i = 0; i < this.ConnectedGamepads; i++) { - if (this.heldGamepadButtons[i] == button && this.triggerGamepadButtonRepeat[i]) - return true; - } - } else if (this.heldGamepadButtons[index] == button && this.triggerGamepadButtonRepeat[index]) { - return true; - } - } - return this.IsGamepadButtonPressedIgnoreRepeats(button, index); - } - - /// - /// Returns whether the given key is considered pressed. - /// A gamepad button is considered pressed if it was down the last update call, and is up the current update call. If is true, this behavior is inverted. - /// This has the same behavior as , but ignores gamepad repeat events. - /// If is false, this method does the same as . - /// - /// The button to query - /// The zero-based index of the gamepad, or -1 for any gamepad - /// Whether the given button is pressed - [Obsolete("This method is deprecated. Use the GenericInput version IsPressedIgnoreRepeats instead.")] - public bool IsGamepadButtonPressedIgnoreRepeats(Buttons button, int index = -1) { - if (this.InvertPressBehavior) - return this.WasGamepadButtonDown(button, index) && this.IsGamepadButtonUp(button, index); - return this.WasGamepadButtonUp(button, index) && this.IsGamepadButtonDown(button, index); - } - - /// - /// Returns if the given gamepad button is considered pressed, and if the press has not been consumed yet using . - /// - /// The button to query. - /// The zero-based index of the gamepad, or -1 for any gamepad. - /// Whether the given button is pressed and the press is not consumed yet. - [Obsolete("This method is deprecated. Use the GenericInput version IsPressedAvailable instead.")] - public bool IsGamepadButtonPressedAvailable(Buttons button, int index = -1) { - return this.IsGamepadButtonPressed(button) && !this.IsPressConsumed(button, index) && (index < 0 || !this.IsPressConsumed(button)); - } - - /// - /// Returns whether the given gamepad button on the given index is considered pressed, and marks the press as consumed if it is. - /// A gamepad button is considered pressed if it was down the last update call, and is up the current update call. - /// A gamepad button press is considered consumed if this method has already returned true previously since the last call. - /// If is true, this method will also return true to signify a gamepad button repeat. - /// - /// The button to query. - /// The zero-based index of the gamepad, or -1 for any gamepad. - /// Whether the given button is pressed and the press is not consumed yet. - [Obsolete("This method is deprecated. Use the GenericInput version TryConsumePressed instead.")] - public bool TryConsumeGamepadButtonPressed(Buttons button, int index = -1) { - if (this.IsGamepadButtonPressedAvailable(button, index)) { - this.consumedPresses.Add((button, index)); - return true; - } - return false; - } - /// /// Queries for a gesture of a given type that finished during the current update call. /// diff --git a/MLEM/Input/Keybind.cs b/MLEM/Input/Keybind.cs index d39a726..e51d6b7 100644 --- a/MLEM/Input/Keybind.cs +++ b/MLEM/Input/Keybind.cs @@ -245,42 +245,6 @@ namespace MLEM.Input { return false; } - /// - /// Returns the amount of time that this keybind has been held down for. - /// If this input isn't currently down, this method returns . - /// - /// The input handler to query the keys with - /// The index of the gamepad to query, or -1 to query all gamepads - /// The resulting down time, or if the input is not being held. - [Obsolete("This method is deprecated, as it does not query Modifiers or InverseModifiers. Use InputHandler.GetDownTime or custom handling instead.")] - public TimeSpan GetDownTime(InputHandler handler, int gamepadIndex = -1) { - return this.Combinations.Max(c => c.GetDownTime(handler, gamepadIndex)); - } - - /// - /// Returns the amount of time that this keybind has been up for since the last time it was down. - /// If this input isn't currently up, this method returns . - /// - /// The input handler to query the keys with - /// The index of the gamepad to query, or -1 to query all gamepads - /// The resulting up time, or if the input is being held. - [Obsolete("This method is deprecated, as it does not query Modifiers or InverseModifiers. Use InputHandler.GetUpTime or custom handling instead.")] - public TimeSpan GetUpTime(InputHandler handler, int gamepadIndex = -1) { - return this.Combinations.Min(c => c.GetUpTime(handler, gamepadIndex)); - } - - /// - /// Returns the amount of time that has passed since this keybind last counted as pressed. - /// If this input hasn't been pressed previously, or is currently pressed, this method returns . - /// - /// The input handler to query the keys with - /// The index of the gamepad to query, or -1 to query all gamepads - /// The resulting up time, or if the input has never been pressed, or is currently pressed. - [Obsolete("This method is deprecated, as it does not query Modifiers or InverseModifiers. Use InputHandler.GetTimeSincePress or custom handling instead.")] - public TimeSpan GetTimeSincePress(InputHandler handler, int gamepadIndex = -1) { - return this.Combinations.Min(c => c.GetTimeSincePress(handler, gamepadIndex)); - } - /// /// Returns an enumerable of all of the combinations that this keybind currently contains /// @@ -502,41 +466,6 @@ namespace MLEM.Input { return true; } - /// - /// Returns the amount of time that this combination has been held down for. - /// If this input isn't currently down, this method returns . - /// - /// The input handler to query the keys with - /// The index of the gamepad to query, or -1 to query all gamepads - /// The resulting down time, or if the input is not being held. - [Obsolete("This method is deprecated, as it does not query Modifiers or InverseModifiers. Use InputHandler.GetDownTime or custom handling instead.")] - public TimeSpan GetDownTime(InputHandler handler, int gamepadIndex = -1) { - return handler.GetDownTime(this.Key, gamepadIndex); - } - - /// - /// Returns the amount of time that this combination has been up for since the last time it was down. - /// If this input isn't currently up, this method returns . - /// - /// The input handler to query the keys with - /// The index of the gamepad to query, or -1 to query all gamepads - /// The resulting up time, or if the input is being held. - [Obsolete("This method is deprecated, as it does not query Modifiers or InverseModifiers. Use InputHandler.GetUpTime or custom handling instead.")] - public TimeSpan GetUpTime(InputHandler handler, int gamepadIndex = -1) { - return handler.GetUpTime(this.Key, gamepadIndex); - } - - /// - /// Returns the amount of time that has passed since this combination last counted as pressed. - /// If this input hasn't been pressed previously, or is currently pressed, this method returns . - /// - /// The input handler to query the keys with - /// The index of the gamepad to query, or -1 to query all gamepads - /// The resulting up time, or if the input has never been pressed, or is currently pressed. - [Obsolete("This method is deprecated, as it does not query Modifiers or InverseModifiers. Use InputHandler.GetTimeSincePress or custom handling instead.")] - public TimeSpan GetTimeSincePress(InputHandler handler, int gamepadIndex = -1) { - return handler.GetTimeSincePress(this.Key, gamepadIndex); - } /// /// Converts this combination into an easily human-readable string. diff --git a/MLEM/Misc/EnumHelper.cs b/MLEM/Misc/EnumHelper.cs deleted file mode 100644 index 2b10348..0000000 --- a/MLEM/Misc/EnumHelper.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework.Input; - -namespace MLEM.Misc { - /// - /// A helper class that allows easier usage of values. - /// - [Obsolete("EnumHelper has been moved into the DynamicEnums library: https://www.nuget.org/packages/DynamicEnums")] - public static class EnumHelper { - - /// - /// All values of the enum. - /// - [Obsolete("This field has been moved to InputHandler.AllButtons")] - public static readonly Buttons[] Buttons = EnumHelper.GetValues(); - /// - /// All values of the enum. - /// - [Obsolete("This field has been moved to InputHandler.AllKeys")] - public static readonly Keys[] Keys = EnumHelper.GetValues(); - - /// - /// Returns an array containing all of the values of the given enum type. - /// Note that this method is a version-independent equivalent of .NET 5's Enum.GetValues<TEnum>. - /// - /// The type whose enum to get - /// An enumerable of the values of the enum, in declaration order. - public static T[] GetValues() where T : struct, Enum { -#if NET6_0_OR_GREATER - return Enum.GetValues(); -#else - return (T[]) Enum.GetValues(typeof(T)); -#endif - } - - /// - /// Returns all of the defined values from the given enum type which are contained in . - /// Note that, if combined flags are defined in , and contains them, they will also be returned. - /// - /// The combined flags whose individual flags to return. - /// Whether the enum value 0 should also be returned, if contains one. - /// The type of enum. - /// All of the flags that make up . - public static IEnumerable GetFlags(T combinedFlag, bool includeZero = true) where T : struct, Enum { - foreach (var flag in EnumHelper.GetValues()) { - if (combinedFlag.HasFlag(flag) && (includeZero || Convert.ToInt64(flag) != 0)) - yield return flag; - } - } - - /// - /// Returns all of the defined unique flags from the given enum type which are contained in . - /// Any combined flags (flags that aren't powers of two) which are defined in will not be returned. - /// - /// The combined flags whose individual flags to return. - /// The type of enum. - /// All of the unique flags that make up . - public static IEnumerable GetUniqueFlags(T combinedFlag) where T : struct, Enum { - var uniqueFlag = 1; - foreach (var flag in EnumHelper.GetValues()) { - var flagValue = Convert.ToInt64(flag); - // GetValues is always ordered by binary value, so we can be sure that the next flag is bigger than the last - while (uniqueFlag < flagValue) - uniqueFlag <<= 1; - if (flagValue == uniqueFlag && combinedFlag.HasFlag(flag)) - yield return flag; - } - } - - } -} diff --git a/MLEM/Misc/GenericDataHolder.cs b/MLEM/Misc/GenericDataHolder.cs index fb425e4..8ca15ab 100644 --- a/MLEM/Misc/GenericDataHolder.cs +++ b/MLEM/Misc/GenericDataHolder.cs @@ -12,12 +12,6 @@ namespace MLEM.Misc { private static readonly string[] EmptyStrings = new string[0]; private Dictionary data; - /// - [Obsolete("This method will be removed in a future update in favor of the generic SetData.")] - public void SetData(string key, object data) { - this.SetData(key, data); - } - /// public void SetData(string key, T data) { if (EqualityComparer.Default.Equals(data, default)) { @@ -52,14 +46,6 @@ namespace MLEM.Misc { /// public interface IGenericDataHolder { - /// - /// Store a piece of generic data on this object. - /// - /// The key to store the data by - /// The data to store in the object - [Obsolete("This method will be removed in a future update in favor of the generic SetData.")] - void SetData(string key, object data); - /// /// Store a piece of generic data on this object. ///