1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-10 11:28:44 +02:00

Improved EnumHelper.GetValues signature to return an array

This commit is contained in:
Ell 2022-07-29 19:52:01 +02:00
parent 7a0464e8d6
commit 8044cb59cb
7 changed files with 15 additions and 23 deletions

View file

@ -10,6 +10,10 @@ Jump to version:
- [5.0.0](#500)
## 6.1.0
### MLEM
Improvements
- Improved EnumHelper.GetValues signature to return an array
### MLEM.Ui
Additions
- Added some extension methods for querying Anchor types

View file

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using Microsoft.Xna.Framework;
@ -28,7 +27,7 @@ namespace MLEM.Ui.Parsers {
/// </remarks>
public class UiMarkdownParser {
private static readonly ElementType[] ElementTypes = EnumHelper.GetValues<ElementType>().ToArray();
private static readonly ElementType[] ElementTypes = EnumHelper.GetValues<ElementType>();
/// <summary>
/// The base path for markdown images, which is prepended to the image link.

View file

@ -12,7 +12,7 @@ namespace MLEM.Input {
/// <summary>
/// All enum values of <see cref="ModifierKey"/>
/// </summary>
public static readonly ModifierKey[] ModifierKeys = EnumHelper.GetValues<ModifierKey>().ToArray();
public static readonly ModifierKey[] ModifierKeys = EnumHelper.GetValues<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}},

View file

@ -1,5 +1,4 @@
using System;
using System.Linq;
using Microsoft.Xna.Framework.Input;
using MLEM.Misc;
@ -12,7 +11,7 @@ namespace MLEM.Input {
/// <summary>
/// All enum values of <see cref="MouseButton"/>
/// </summary>
public static readonly MouseButton[] MouseButtons = EnumHelper.GetValues<MouseButton>().ToArray();
public static readonly MouseButton[] MouseButtons = EnumHelper.GetValues<MouseButton>();
/// <summary>
/// Returns the <see cref="ButtonState"/> of the given mouse button.

View file

@ -71,7 +71,7 @@ namespace MLEM.Misc {
/// <summary>
/// All <see cref="Direction2"/> enum values
/// </summary>
public static readonly Direction2[] All = EnumHelper.GetValues<Direction2>().ToArray();
public static readonly Direction2[] All = EnumHelper.GetValues<Direction2>();
/// <summary>
/// The <see cref="Direction2.Up"/> through <see cref="Direction2.Left"/> directions
/// </summary>

View file

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework.Input;
namespace MLEM.Misc {
@ -12,19 +10,20 @@ namespace MLEM.Misc {
/// <summary>
/// All values of the <see cref="Buttons"/> enum.
/// </summary>
public static readonly Buttons[] Buttons = EnumHelper.GetValues<Buttons>().ToArray();
public static readonly Buttons[] Buttons = EnumHelper.GetValues<Buttons>();
/// <summary>
/// All values of the <see cref="Keys"/> enum.
/// </summary>
public static readonly Keys[] Keys = EnumHelper.GetValues<Keys>().ToArray();
public static readonly Keys[] Keys = EnumHelper.GetValues<Keys>();
/// <summary>
/// Returns all of the values of the given enum type.
/// 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 <c>Enum.GetValues&lt;TEnum&gt;</c>.
/// </summary>
/// <typeparam name="T">The type whose enum to get</typeparam>
/// <returns>An enumerable of the values of the enum, in declaration order.</returns>
public static IEnumerable<T> GetValues<T>() {
return Enum.GetValues(typeof(T)).Cast<T>();
public static T[] GetValues<T>() {
return (T[]) Enum.GetValues(typeof(T));
}
}

View file

@ -1,17 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using FontStashSharp;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MLEM.Cameras;
using MLEM.Data;
using MLEM.Data.Content;
using MLEM.Extended.Font;
using MLEM.Extended.Tiled;
using MLEM.Extensions;
using MLEM.Font;
using MLEM.Formatting;
@ -23,9 +17,6 @@ using MLEM.Textures;
using MLEM.Ui;
using MLEM.Ui.Elements;
using MLEM.Ui.Style;
using MonoGame.Extended;
using MonoGame.Extended.Tiled;
using MonoGame.Extended.ViewportAdapters;
namespace Sandbox;
@ -348,7 +339,7 @@ public class GameImpl : MlemGame {
widthPanel.AddChild(new Paragraph(Anchor.AutoCenter, 100000, "Test String " + Math.Pow(10, i), true) {
OnUpdated = (e, time) => {
if (Input.IsPressed(Keys.A)) {
e.Anchor = (Anchor) (((int) e.Anchor + 1) % EnumHelper.GetValues<Anchor>().Count());
e.Anchor = (Anchor) (((int) e.Anchor + 1) % EnumHelper.GetValues<Anchor>().Length);
Console.WriteLine(e.Anchor);
}
}