diff --git a/CHANGELOG.md b/CHANGELOG.md
index d23f682..e4eeb56 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ Jump to version:
### MLEM
Additions
- Added TokenizedString.Realign
+- Added EnumHelper.GetFlags
- **Added the ability to find paths to one of multiple goals using AStar**
Improvements
@@ -59,6 +60,7 @@ Fixes
Additions
- Added data, from, and copy instructions to DataTextureAtlas
- Added the ability to add additional regions to a RuntimeTexturePacker after packing
+- Added DynamicEnum.GetFlags
Improvements
- Allow data texture atlas pivots and offsets to be negative
diff --git a/MLEM.Data/DynamicEnum.cs b/MLEM.Data/DynamicEnum.cs
index 09f9717..e22107b 100644
--- a/MLEM.Data/DynamicEnum.cs
+++ b/MLEM.Data/DynamicEnum.cs
@@ -174,6 +174,21 @@ namespace MLEM.Data {
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 the bitwise OR (|) combination of the two dynamic enum values
///
diff --git a/MLEM/Misc/EnumHelper.cs b/MLEM/Misc/EnumHelper.cs
index 684aa19..34a561b 100644
--- a/MLEM/Misc/EnumHelper.cs
+++ b/MLEM/Misc/EnumHelper.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using Microsoft.Xna.Framework.Input;
namespace MLEM.Misc {
@@ -30,5 +31,20 @@ namespace MLEM.Misc {
#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;
+ }
+ }
+
}
}