mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 14:08:34 +01:00
Marked EnumHelper and DynamicEnum as obsolete due to their reimplementation in the DynamicEnums library
This commit is contained in:
parent
791c66b098
commit
f58e3c94d5
12 changed files with 28 additions and 99 deletions
|
@ -31,6 +31,9 @@ Fixes
|
|||
- Fixed some TokenizedString tokens starting with a line break not being split correctly
|
||||
- Fixed InputHandler maintaining old input states when input types are toggled off
|
||||
|
||||
Removals
|
||||
- Marked EnumHelper as obsolete due to its reimplementation in [DynamicEnums](https://www.nuget.org/packages/DynamicEnums)
|
||||
|
||||
### MLEM.Ui
|
||||
Additions
|
||||
- Added some extension methods for querying Anchor types
|
||||
|
@ -70,6 +73,9 @@ Improvements
|
|||
Fixes
|
||||
- Fixed data texture atlases not allowing most characters in their region names
|
||||
|
||||
Removals
|
||||
- Marked DynamicEnum as obsolete due to its reimplementation in [DynamicEnums](https://www.nuget.org/packages/DynamicEnums)
|
||||
|
||||
## MLEM.Extended
|
||||
Improvements
|
||||
- Multi-target net452, making MLEM compatible with MonoGame for consoles
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace MLEM.Data {
|
|||
/// public static MyEnum operator ~(MyEnum value) => Neg(value);
|
||||
/// </code>
|
||||
/// </remarks>
|
||||
[JsonConverter(typeof(DynamicEnumConverter))]
|
||||
[Obsolete("DynamicEnum has been moved into the DynamicEnums library: https://www.nuget.org/packages/DynamicEnums"), JsonConverter(typeof(DynamicEnumConverter))]
|
||||
public abstract class DynamicEnum {
|
||||
|
||||
private static readonly Dictionary<Type, Storage> Storages = new Dictionary<Type, Storage>();
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace MLEM.Data.Json {
|
|||
/// <summary>
|
||||
/// Converts a <see cref="DynamicEnum"/> to and from JSON
|
||||
/// </summary>
|
||||
[Obsolete("DynamicEnum has been moved into the DynamicEnums library: https://www.nuget.org/packages/DynamicEnums"), JsonConverter(typeof(DynamicEnumConverter))]
|
||||
public class DynamicEnumConverter : JsonConverter<DynamicEnum> {
|
||||
|
||||
/// <summary>Writes the JSON representation of the object.</summary>
|
||||
|
|
|
@ -4,14 +4,12 @@ using System.IO;
|
|||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MLEM.Formatting;
|
||||
using MLEM.Misc;
|
||||
using MLEM.Textures;
|
||||
using MLEM.Ui.Elements;
|
||||
using MLEM.Ui.Style;
|
||||
|
||||
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
|
||||
using System.Net.Http;
|
||||
|
||||
#else
|
||||
using System.Net;
|
||||
#endif
|
||||
|
@ -26,7 +24,7 @@ namespace MLEM.Ui.Parsers {
|
|||
/// <summary>
|
||||
/// An array containing all of the <see cref="ElementType"/> enum values.
|
||||
/// </summary>
|
||||
public static readonly ElementType[] ElementTypes = EnumHelper.GetValues<ElementType>();
|
||||
public static readonly ElementType[] ElementTypes = (ElementType[]) Enum.GetValues(typeof(ElementType));
|
||||
|
||||
/// <summary>
|
||||
/// The base path for images, which is prepended to the image link.
|
||||
|
|
|
@ -6,7 +6,6 @@ using Microsoft.Xna.Framework;
|
|||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Microsoft.Xna.Framework.Input.Touch;
|
||||
using MLEM.Misc;
|
||||
|
||||
namespace MLEM.Input {
|
||||
/// <summary>
|
||||
|
@ -15,6 +14,15 @@ namespace MLEM.Input {
|
|||
/// </summary>
|
||||
public class InputHandler : GameComponent {
|
||||
|
||||
/// <summary>
|
||||
/// All values of the <see cref="Buttons"/> enum.
|
||||
/// </summary>
|
||||
public static readonly Buttons[] AllButtons = (Buttons[]) Enum.GetValues(typeof(Buttons));
|
||||
/// <summary>
|
||||
/// All values of the <see cref="Keys"/> enum.
|
||||
/// </summary>
|
||||
public static readonly Keys[] AllKeys = (Keys[]) Enum.GetValues(typeof(Keys));
|
||||
|
||||
#if FNA
|
||||
private const int MaximumGamePadCount = 4;
|
||||
#else
|
||||
|
@ -257,7 +265,7 @@ namespace MLEM.Input {
|
|||
if (GamePad.GetCapabilities((PlayerIndex) i).IsConnected) {
|
||||
if (active) {
|
||||
this.gamepads[i] = GamePad.GetState((PlayerIndex) i);
|
||||
foreach (var button in EnumHelper.Buttons) {
|
||||
foreach (var button in InputHandler.AllButtons) {
|
||||
if (this.IsGamepadButtonDown(button, i))
|
||||
this.AccumulateDown(button, i);
|
||||
}
|
||||
|
@ -270,7 +278,7 @@ namespace MLEM.Input {
|
|||
for (var i = 0; i < this.ConnectedGamepads; i++) {
|
||||
this.triggerGamepadButtonRepeat[i] = false;
|
||||
if (this.HandleGamepadRepeats) {
|
||||
this.heldGamepadButtons[i] = EnumHelper.Buttons
|
||||
this.heldGamepadButtons[i] = InputHandler.AllButtons
|
||||
.Where(b => this.IsGamepadButtonDown(b, i))
|
||||
.OrderBy(b => this.GetDownTime(b, i))
|
||||
.Cast<Buttons?>().FirstOrDefault();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using MLEM.Misc;
|
||||
|
||||
namespace MLEM.Input {
|
||||
/// <summary>
|
||||
|
@ -12,7 +12,7 @@ namespace MLEM.Input {
|
|||
/// <summary>
|
||||
/// All enum values of <see cref="ModifierKey"/>
|
||||
/// </summary>
|
||||
public static readonly ModifierKey[] ModifierKeys = EnumHelper.GetValues<ModifierKey>();
|
||||
public static readonly ModifierKey[] ModifierKeys = (ModifierKey[]) Enum.GetValues(typeof(ModifierKey));
|
||||
private static readonly Dictionary<ModifierKey, Keys[]> KeysLookup = new Dictionary<ModifierKey, Keys[]> {
|
||||
{ModifierKey.Shift, new[] {Keys.LeftShift, Keys.RightShift}},
|
||||
{ModifierKey.Control, new[] {Keys.LeftControl, Keys.RightControl}},
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using MLEM.Misc;
|
||||
|
||||
namespace MLEM.Input {
|
||||
/// <summary>
|
||||
|
@ -11,7 +10,7 @@ namespace MLEM.Input {
|
|||
/// <summary>
|
||||
/// All enum values of <see cref="MouseButton"/>
|
||||
/// </summary>
|
||||
public static readonly MouseButton[] MouseButtons = EnumHelper.GetValues<MouseButton>();
|
||||
public static readonly MouseButton[] MouseButtons = (MouseButton[]) Enum.GetValues(typeof(MouseButton));
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="ButtonState"/> of the given mouse button.
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace MLEM.Misc {
|
|||
/// <summary>
|
||||
/// All <see cref="Direction2"/> enum values
|
||||
/// </summary>
|
||||
public static readonly Direction2[] All = EnumHelper.GetValues<Direction2>();
|
||||
public static readonly Direction2[] All = (Direction2[]) Enum.GetValues(typeof(Direction2));
|
||||
/// <summary>
|
||||
/// The <see cref="Direction2.Up"/> through <see cref="Direction2.Left"/> directions
|
||||
/// </summary>
|
||||
|
|
|
@ -6,15 +6,18 @@ namespace MLEM.Misc {
|
|||
/// <summary>
|
||||
/// A helper class that allows easier usage of <see cref="Enum"/> values.
|
||||
/// </summary>
|
||||
[Obsolete("EnumHelper has been moved into the DynamicEnums library: https://www.nuget.org/packages/DynamicEnums")]
|
||||
public static class EnumHelper {
|
||||
|
||||
/// <summary>
|
||||
/// All values of the <see cref="Buttons"/> enum.
|
||||
/// </summary>
|
||||
[Obsolete("This field has been moved to InputHandler.AllButtons")]
|
||||
public static readonly Buttons[] Buttons = EnumHelper.GetValues<Buttons>();
|
||||
/// <summary>
|
||||
/// All values of the <see cref="Keys"/> enum.
|
||||
/// </summary>
|
||||
[Obsolete("This field has been moved to InputHandler.AllKeys")]
|
||||
public static readonly Keys[] Keys = EnumHelper.GetValues<Keys>();
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -347,7 +347,7 @@ public class GameImpl : MlemGame {
|
|||
widthPanel.AddChild(new Paragraph(Anchor.AutoCenter, 100000, "Test String " + Math.Pow(10, i), true) {
|
||||
OnUpdated = (e, _) => {
|
||||
if (MlemGame.Input.IsPressed(Keys.A)) {
|
||||
e.Anchor = (Anchor) (((int) e.Anchor + 1) % EnumHelper.GetValues<Anchor>().Length);
|
||||
e.Anchor = (Anchor) (((int) e.Anchor + 1) % 14);
|
||||
Console.WriteLine(e.Anchor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using MLEM.Data;
|
||||
using MLEM.Data.Json;
|
||||
using MLEM.Misc;
|
||||
using Newtonsoft.Json;
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using MLEM.Data;
|
||||
using MLEM.Misc;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests;
|
||||
|
||||
public class EnumTests {
|
||||
|
||||
[Test]
|
||||
public void TestRegularEnums() {
|
||||
Assert.AreEqual(
|
||||
new[] {TestEnum.One, TestEnum.Two, TestEnum.Eight, TestEnum.Sixteen, TestEnum.EightSixteen},
|
||||
EnumHelper.GetFlags(TestEnum.One | TestEnum.Sixteen | TestEnum.Eight | TestEnum.Two));
|
||||
|
||||
Assert.AreEqual(
|
||||
new[] {TestEnum.One, TestEnum.Two, TestEnum.Eight, TestEnum.Sixteen},
|
||||
EnumHelper.GetUniqueFlags(TestEnum.One | TestEnum.Sixteen | TestEnum.Eight | TestEnum.Two));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDynamicEnums() {
|
||||
var flags = new TestDynamicEnum[100];
|
||||
for (var i = 0; i < flags.Length; i++)
|
||||
flags[i] = DynamicEnum.AddFlag<TestDynamicEnum>("Flag" + i);
|
||||
var combined = DynamicEnum.Add<TestDynamicEnum>("Combined", DynamicEnum.GetValue(DynamicEnum.Or(flags[7], flags[13])));
|
||||
|
||||
Assert.AreEqual(DynamicEnum.GetValue(flags[7]), BigInteger.One << 7);
|
||||
Assert.AreEqual(DynamicEnum.GetEnumValue<TestDynamicEnum>(BigInteger.One << 75), flags[75]);
|
||||
|
||||
Assert.AreEqual(DynamicEnum.GetValue(DynamicEnum.Or(flags[2], flags[17])), BigInteger.One << 2 | BigInteger.One << 17);
|
||||
Assert.AreEqual(DynamicEnum.GetValue(DynamicEnum.And(flags[2], flags[3])), BigInteger.Zero);
|
||||
Assert.AreEqual(DynamicEnum.And(DynamicEnum.Or(flags[24], flags[52]), DynamicEnum.Or(flags[52], flags[75])), flags[52]);
|
||||
Assert.AreEqual(DynamicEnum.Xor(DynamicEnum.Or(flags[85], flags[73]), flags[73]), flags[85]);
|
||||
Assert.AreEqual(DynamicEnum.Xor(DynamicEnum.Or(flags[85], DynamicEnum.Or(flags[73], flags[12])), flags[73]), DynamicEnum.Or(flags[85], flags[12]));
|
||||
Assert.AreEqual(DynamicEnum.GetValue(DynamicEnum.Neg(flags[74])), ~(BigInteger.One << 74));
|
||||
|
||||
Assert.AreEqual(DynamicEnum.Or(flags[24], flags[52]).HasFlag(flags[24]), true);
|
||||
Assert.AreEqual(DynamicEnum.Or(flags[24], flags[52]).HasAnyFlag(flags[24]), true);
|
||||
Assert.AreEqual(DynamicEnum.Or(flags[24], flags[52]).HasFlag(DynamicEnum.Or(flags[24], flags[26])), false);
|
||||
Assert.AreEqual(DynamicEnum.Or(flags[24], flags[52]).HasAnyFlag(DynamicEnum.Or(flags[24], flags[26])), true);
|
||||
|
||||
Assert.AreEqual(DynamicEnum.Parse<TestDynamicEnum>("Flag24"), flags[24]);
|
||||
Assert.AreEqual(DynamicEnum.Parse<TestDynamicEnum>("Flag24 | Flag43"), DynamicEnum.Or(flags[24], flags[43]));
|
||||
Assert.AreEqual(flags[24].ToString(), "Flag24");
|
||||
Assert.AreEqual(DynamicEnum.Or(flags[24], flags[43]).ToString(), "Flag24 | Flag43");
|
||||
|
||||
Assert.True(DynamicEnum.IsDefined(flags[27]));
|
||||
Assert.True(DynamicEnum.IsDefined(combined));
|
||||
Assert.False(DynamicEnum.IsDefined(DynamicEnum.Or(flags[17], flags[49])));
|
||||
Assert.False(DynamicEnum.IsDefined(DynamicEnum.Or(combined, flags[49])));
|
||||
|
||||
Assert.AreEqual(
|
||||
new[] {flags[0], flags[7], flags[13], combined},
|
||||
DynamicEnum.GetFlags(DynamicEnum.Or(DynamicEnum.Or(flags[0], flags[13]), flags[7])));
|
||||
|
||||
Assert.AreEqual(
|
||||
new[] {flags[0], flags[7], flags[13]},
|
||||
DynamicEnum.GetUniqueFlags(DynamicEnum.Or(DynamicEnum.Or(flags[0], flags[13]), flags[7])));
|
||||
}
|
||||
|
||||
[Flags]
|
||||
private enum TestEnum {
|
||||
|
||||
One = 1,
|
||||
Two = 2,
|
||||
Eight = 8,
|
||||
Sixteen = 16,
|
||||
EightSixteen = TestEnum.Eight | TestEnum.Sixteen,
|
||||
ThirtyTwo = 32,
|
||||
OneTwentyEight = 128,
|
||||
OneTwentyEightTwoOne = TestEnum.OneTwentyEight | TestEnum.Two | TestEnum.One
|
||||
|
||||
}
|
||||
|
||||
private class TestDynamicEnum : DynamicEnum {
|
||||
|
||||
public TestDynamicEnum(string name, BigInteger value) : base(name, value) {}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue