1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-04-28 23:29:06 +02:00

cleaned up preprocessor instructions

This commit is contained in:
Ell 2022-12-13 13:11:36 +01:00
parent e229432d0f
commit 14d0b24aa9
40 changed files with 119 additions and 117 deletions

View file

@ -87,8 +87,9 @@ resharper_indent_nested_for_stmt = true
resharper_indent_nested_lock_stmt = true resharper_indent_nested_lock_stmt = true
resharper_indent_nested_usings_stmt = true resharper_indent_nested_usings_stmt = true
resharper_indent_nested_while_stmt = true resharper_indent_nested_while_stmt = true
resharper_indent_preprocessor_if = usual_indent resharper_indent_preprocessor_if = no_indent
resharper_indent_preprocessor_other = usual_indent resharper_indent_preprocessor_other = no_indent
resharper_indent_preprocessor_region = no_indent
resharper_keep_existing_declaration_parens_arrangement = false resharper_keep_existing_declaration_parens_arrangement = false
resharper_keep_existing_embedded_arrangement = false resharper_keep_existing_embedded_arrangement = false
resharper_keep_existing_expr_member_arrangement = false resharper_keep_existing_expr_member_arrangement = false

View file

@ -10,11 +10,11 @@ namespace Demos.DesktopGL;
public static class Program { public static class Program {
public static void Main() { public static void Main() {
#if FNA #if FNA
MlemPlatform.Current = new MlemPlatform.DesktopFna(a => TextInputEXT.TextInput += a); MlemPlatform.Current = new MlemPlatform.DesktopFna(a => TextInputEXT.TextInput += a);
#else #else
MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c); MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
#endif #endif
using var game = new GameImpl(); using var game = new GameImpl();
game.Run(); game.Run();
} }

View file

@ -23,9 +23,9 @@ namespace MLEM.Data.Content {
private readonly List<IDisposable> disposableAssets = new List<IDisposable>(); private readonly List<IDisposable> disposableAssets = new List<IDisposable>();
private readonly List<RawContentReader> readers; private readonly List<RawContentReader> readers;
#if FNA #if FNA
private Dictionary<string, object> LoadedAssets { get; } = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); private Dictionary<string, object> LoadedAssets { get; } = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
#endif #endif
/// <summary> /// <summary>
/// Creates a new content manager with an optionally specified root directory. /// Creates a new content manager with an optionally specified root directory.
@ -33,9 +33,9 @@ namespace MLEM.Data.Content {
/// </summary> /// </summary>
/// <param name="serviceProvider">The service provider of your game</param> /// <param name="serviceProvider">The service provider of your game</param>
/// <param name="rootDirectory">The root directory. Defaults to "Content"</param> /// <param name="rootDirectory">The root directory. Defaults to "Content"</param>
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Automatically gathered RawContentReader types might be removed, use other constructor to add readers manually")] [RequiresUnreferencedCode("Automatically gathered RawContentReader types might be removed, use other constructor to add readers manually")]
#endif #endif
public RawContentManager(IServiceProvider serviceProvider, string rootDirectory = "Content") : public RawContentManager(IServiceProvider serviceProvider, string rootDirectory = "Content") :
this(serviceProvider, RawContentManager.CollectContentReaders(), rootDirectory) {} this(serviceProvider, RawContentManager.CollectContentReaders(), rootDirectory) {}
@ -73,9 +73,9 @@ namespace MLEM.Data.Content {
/// <param name="currentAsset">The current asset instance.</param> /// <param name="currentAsset">The current asset instance.</param>
/// <typeparam name="T">The asset's type.</typeparam> /// <typeparam name="T">The asset's type.</typeparam>
protected protected
#if !FNA #if !FNA
override override
#endif #endif
void ReloadAsset<T>(string originalAssetName, T currentAsset) { void ReloadAsset<T>(string originalAssetName, T currentAsset) {
this.Read(originalAssetName, currentAsset); this.Read(originalAssetName, currentAsset);
} }
@ -121,9 +121,9 @@ namespace MLEM.Data.Content {
/// </summary> /// </summary>
public void Initialize() {} public void Initialize() {}
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
[RequiresUnreferencedCode("Automatically gathered RawContentReader types might be removed, use other constructor to add readers manually")] [RequiresUnreferencedCode("Automatically gathered RawContentReader types might be removed, use other constructor to add readers manually")]
#endif #endif
private static List<RawContentReader> CollectContentReaders() { private static List<RawContentReader> CollectContentReaders() {
var ret = new List<RawContentReader>(); var ret = new List<RawContentReader>();
var assemblyExceptions = new List<Exception>(); var assemblyExceptions = new List<Exception>();

View file

@ -9,12 +9,12 @@ namespace MLEM.Data.Content {
/// <inheritdoc /> /// <inheritdoc />
protected override Texture2D Read(RawContentManager manager, string assetPath, Stream stream, Texture2D existing) { protected override Texture2D Read(RawContentManager manager, string assetPath, Stream stream, Texture2D existing) {
#if !FNA #if !FNA
if (existing != null) { if (existing != null) {
existing.Reload(stream); existing.Reload(stream);
return existing; return existing;
} }
#endif #endif
// premultiply the texture's color to be in line with the pipeline's texture reader // premultiply the texture's color to be in line with the pipeline's texture reader
using (var texture = Texture2D.FromStream(manager.GraphicsDevice, stream)) { using (var texture = Texture2D.FromStream(manager.GraphicsDevice, stream)) {

View file

@ -12,10 +12,10 @@ namespace MLEM.Data.Content {
} }
/// <inheritdoc /> /// <inheritdoc />
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026", [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026",
Justification = "RawContentManager does not support XmlReader in a trimmed or AOT context, so this method is not expected to be called.")] Justification = "RawContentManager does not support XmlReader in a trimmed or AOT context, so this method is not expected to be called.")]
#endif #endif
public override object Read(RawContentManager manager, string assetPath, Stream stream, Type t, object existing) { public override object Read(RawContentManager manager, string assetPath, Stream stream, Type t, object existing) {
return new XmlSerializer(t).Deserialize(stream); return new XmlSerializer(t).Deserialize(stream);
} }

View file

@ -12,9 +12,9 @@ namespace MLEM.Data {
/// A set of extensions for dealing with copying objects. /// A set of extensions for dealing with copying objects.
/// </summary> /// </summary>
[Obsolete("CopyExtensions has major flaws and insufficient speed compared to other libraries specifically designed for copying objects.")] [Obsolete("CopyExtensions has major flaws and insufficient speed compared to other libraries specifically designed for copying objects.")]
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
[UnconditionalSuppressMessage("Aot", "IL3050"), UnconditionalSuppressMessage("Aot", "IL2070"), UnconditionalSuppressMessage("Aot", "IL2090")] [UnconditionalSuppressMessage("Aot", "IL3050"), UnconditionalSuppressMessage("Aot", "IL2070"), UnconditionalSuppressMessage("Aot", "IL2090")]
#endif #endif
public static class CopyExtensions { public static class CopyExtensions {
private const BindingFlags DefaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; private const BindingFlags DefaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

View file

@ -26,9 +26,9 @@ namespace MLEM.Data {
/// </code> /// </code>
/// </remarks> /// </remarks>
[Obsolete("DynamicEnum has been moved into the DynamicEnums library: https://www.nuget.org/packages/DynamicEnums"), JsonConverter(typeof(DynamicEnumConverter))] [Obsolete("DynamicEnum has been moved into the DynamicEnums library: https://www.nuget.org/packages/DynamicEnums"), JsonConverter(typeof(DynamicEnumConverter))]
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Aot", "IL2067")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Aot", "IL2067")]
#endif #endif
public abstract class DynamicEnum { public abstract class DynamicEnum {
private static readonly Dictionary<Type, Storage> Storages = new Dictionary<Type, Storage>(); private static readonly Dictionary<Type, Storage> Storages = new Dictionary<Type, Storage>();

View file

@ -13,9 +13,9 @@ namespace MLEM.Data.Json {
/// </summary> /// </summary>
public static readonly JsonConverter[] Converters = { public static readonly JsonConverter[] Converters = {
new Direction2Converter(), new Direction2Converter(),
#pragma warning disable CS0618 #pragma warning disable CS0618
new DynamicEnumConverter(), new DynamicEnumConverter(),
#pragma warning restore CS0618 #pragma warning restore CS0618
new PointConverter(), new PointConverter(),
new RectangleConverter(), new RectangleConverter(),
new RectangleFConverter(), new RectangleFConverter(),

View file

@ -9,9 +9,9 @@ namespace MLEM.Data.Json {
/// This class uses <see cref="JsonTypeSafeWrapper"/> for each object stored to ensure that objects with a custom <see cref="JsonConverter"/> get deserialized as an instance of their original type if <see cref="JsonSerializer.TypeNameHandling"/> is not set to <see cref="TypeNameHandling.None"/>. /// This class uses <see cref="JsonTypeSafeWrapper"/> for each object stored to ensure that objects with a custom <see cref="JsonConverter"/> get deserialized as an instance of their original type if <see cref="JsonSerializer.TypeNameHandling"/> is not set to <see cref="TypeNameHandling.None"/>.
/// Note that, using <see cref="SetData"/>, adding <see cref="JsonTypeSafeWrapper{T}"/> instances directly is also possible. /// Note that, using <see cref="SetData"/>, adding <see cref="JsonTypeSafeWrapper{T}"/> instances directly is also possible.
/// </summary> /// </summary>
#if NET7_0_OR_GREATER #if NET7_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for instantiation of JsonTypeSafeWrapper instances might not be available at runtime.")] [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for instantiation of JsonTypeSafeWrapper instances might not be available at runtime.")]
#endif #endif
public class JsonTypeSafeGenericDataHolder : IGenericDataHolder { public class JsonTypeSafeGenericDataHolder : IGenericDataHolder {
private static readonly string[] EmptyStrings = new string[0]; private static readonly string[] EmptyStrings = new string[0];

View file

@ -34,9 +34,9 @@ namespace MLEM.Data.Json {
/// </summary> /// </summary>
/// <param name="value">The value to wrap</param> /// <param name="value">The value to wrap</param>
/// <returns>A <see cref="JsonTypeSafeWrapper{T}"/> with a type matching the type of <paramref name="value"/></returns> /// <returns>A <see cref="JsonTypeSafeWrapper{T}"/> with a type matching the type of <paramref name="value"/></returns>
#if NET7_0_OR_GREATER #if NET7_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for this instantiation might not be available at runtime if the value's type is a subtype of T.")] [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The native code for this instantiation might not be available at runtime if the value's type is a subtype of T.")]
#endif #endif
public static JsonTypeSafeWrapper Of<T>(T value) { public static JsonTypeSafeWrapper Of<T>(T value) {
if (value.GetType() == typeof(T)) { if (value.GetType() == typeof(T)) {
return new JsonTypeSafeWrapper<T>(value); return new JsonTypeSafeWrapper<T>(value);

View file

@ -34,9 +34,9 @@ namespace MLEM.Data.Json {
/// <param name="type">The type that the dictionary is declared in</param> /// <param name="type">The type that the dictionary is declared in</param>
/// <param name="memberName">The name of the dictionary itself</param> /// <param name="memberName">The name of the dictionary itself</param>
public StaticJsonConverter( public StaticJsonConverter(
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)]
#endif #endif
Type type, string memberName) : this(StaticJsonConverter<T>.GetEntries(type, memberName)) {} Type type, string memberName) : this(StaticJsonConverter<T>.GetEntries(type, memberName)) {}
/// <summary>Writes the JSON representation of the object.</summary> /// <summary>Writes the JSON representation of the object.</summary>
@ -65,9 +65,9 @@ namespace MLEM.Data.Json {
} }
private static Dictionary<string, T> GetEntries( private static Dictionary<string, T> GetEntries(
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)]
#endif #endif
Type type, string memberName) { Type type, string memberName) {
const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; const BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
var value = type.GetProperty(memberName, flags)?.GetValue(null) ?? type.GetField(memberName, flags)?.GetValue(null); var value = type.GetProperty(memberName, flags)?.GetValue(null) ?? type.GetField(memberName, flags)?.GetValue(null);

View file

@ -11,9 +11,9 @@ namespace MLEM.Data {
/// Before serializing and deserializing an object, each of the object's fields has to have a handler. New handlers can be added using <see cref="AddHandler{T}(System.Action{Lidgren.Network.NetBuffer,T},System.Func{Lidgren.Network.NetBuffer,T})"/> or <see cref="AddHandler{T}(Newtonsoft.Json.JsonSerializer)"/>. /// Before serializing and deserializing an object, each of the object's fields has to have a handler. New handlers can be added using <see cref="AddHandler{T}(System.Action{Lidgren.Network.NetBuffer,T},System.Func{Lidgren.Network.NetBuffer,T})"/> or <see cref="AddHandler{T}(Newtonsoft.Json.JsonSerializer)"/>.
/// </summary> /// </summary>
[Obsolete("Lidgren.Network support is deprecated. Consider using LiteNetLib or a custom implementation instead.")] [Obsolete("Lidgren.Network support is deprecated. Consider using LiteNetLib or a custom implementation instead.")]
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Aot", "IL2070")] [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Aot", "IL2070")]
#endif #endif
public class NetBufferSerializer { public class NetBufferSerializer {
private readonly Dictionary<Type, Action<NetBuffer, object>> writeFunctions = new Dictionary<Type, Action<NetBuffer, object>>(); private readonly Dictionary<Type, Action<NetBuffer, object>> writeFunctions = new Dictionary<Type, Action<NetBuffer, object>>();

View file

@ -69,9 +69,9 @@ namespace MLEM.Startup {
this.GraphicsDeviceManager = new GraphicsDeviceManager(this) { this.GraphicsDeviceManager = new GraphicsDeviceManager(this) {
PreferredBackBufferWidth = windowWidth, PreferredBackBufferWidth = windowWidth,
PreferredBackBufferHeight = windowHeight, PreferredBackBufferHeight = windowHeight,
#if !FNA #if !FNA
HardwareModeSwitch = false HardwareModeSwitch = false
#endif #endif
}; };
this.Window.AllowUserResizing = true; this.Window.AllowUserResizing = true;
this.Content.RootDirectory = "Content"; this.Content.RootDirectory = "Content";
@ -116,9 +116,9 @@ namespace MLEM.Startup {
this.PreDraw?.Invoke(this, gameTime); this.PreDraw?.Invoke(this, gameTime);
CoroutineHandler.RaiseEvent(CoroutineEvents.PreDraw); CoroutineHandler.RaiseEvent(CoroutineEvents.PreDraw);
#pragma warning disable CS0618 #pragma warning disable CS0618
this.UiSystem.DrawEarly(gameTime, this.SpriteBatch); this.UiSystem.DrawEarly(gameTime, this.SpriteBatch);
#pragma warning restore CS0618 #pragma warning restore CS0618
this.DoDraw(gameTime); this.DoDraw(gameTime);
this.UiSystem.Draw(gameTime, this.SpriteBatch); this.UiSystem.Draw(gameTime, this.SpriteBatch);

View file

@ -206,10 +206,10 @@ namespace MLEM.Ui.Elements {
/// The call that this element should make to <see cref="SpriteBatch"/> to begin drawing. /// The call that this element should make to <see cref="SpriteBatch"/> to begin drawing.
/// Note that, when this is non-null, a new <c>SpriteBatch.Begin</c> call is used for this element. /// Note that, when this is non-null, a new <c>SpriteBatch.Begin</c> call is used for this element.
/// </summary> /// </summary>
#pragma warning disable CS0618 #pragma warning disable CS0618
[Obsolete("BeginImpl is deprecated. You can create a custom element class and override Draw instead.")] [Obsolete("BeginImpl is deprecated. You can create a custom element class and override Draw instead.")]
public BeginDelegate BeginImpl; public BeginDelegate BeginImpl;
#pragma warning restore CS0618 #pragma warning restore CS0618
/// <summary> /// <summary>
/// Set this field to false to disallow the element from being selected. /// Set this field to false to disallow the element from being selected.
/// An unselectable element is skipped by automatic navigation and its <see cref="OnSelected"/> callback will never be called. /// An unselectable element is skipped by automatic navigation and its <see cref="OnSelected"/> callback will never be called.
@ -983,7 +983,7 @@ namespace MLEM.Ui.Elements {
/// <param name="alpha">The alpha to draw this element and its children with</param> /// <param name="alpha">The alpha to draw this element and its children with</param>
/// <param name="context">The sprite batch context to use for drawing</param> /// <param name="context">The sprite batch context to use for drawing</param>
public void DrawTransformed(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) { public void DrawTransformed(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) {
#pragma warning disable CS0618 #pragma warning disable CS0618
var customDraw = this.BeginImpl != null || this.Transform != Matrix.Identity; var customDraw = this.BeginImpl != null || this.Transform != Matrix.Identity;
var transformed = context; var transformed = context;
transformed.TransformMatrix = this.Transform * transformed.TransformMatrix; transformed.TransformMatrix = this.Transform * transformed.TransformMatrix;
@ -994,12 +994,12 @@ namespace MLEM.Ui.Elements {
// begin our own draw call // begin our own draw call
batch.Begin(transformed); batch.Begin(transformed);
} }
#pragma warning restore CS0618 #pragma warning restore CS0618
// draw content in custom begin call // draw content in custom begin call
#pragma warning disable CS0618 #pragma warning disable CS0618
this.Draw(time, batch, alpha, transformed.BlendState, transformed.SamplerState, transformed.DepthStencilState, transformed.Effect, transformed.TransformMatrix); this.Draw(time, batch, alpha, transformed.BlendState, transformed.SamplerState, transformed.DepthStencilState, transformed.Effect, transformed.TransformMatrix);
#pragma warning restore CS0618 #pragma warning restore CS0618
if (this.System != null) if (this.System != null)
this.System.Metrics.Draws++; this.System.Metrics.Draws++;
@ -1043,9 +1043,9 @@ namespace MLEM.Ui.Elements {
foreach (var child in this.GetRelevantChildren()) { foreach (var child in this.GetRelevantChildren()) {
if (!child.IsHidden) { if (!child.IsHidden) {
#pragma warning disable CS0618 #pragma warning disable CS0618
child.DrawTransformed(time, batch, alpha * child.DrawAlpha, context.BlendState, context.SamplerState, context.DepthStencilState, context.Effect, context.TransformMatrix); child.DrawTransformed(time, batch, alpha * child.DrawAlpha, context.BlendState, context.SamplerState, context.DepthStencilState, context.Effect, context.TransformMatrix);
#pragma warning restore CS0618 #pragma warning restore CS0618
} }
} }
} }

View file

@ -112,11 +112,11 @@ namespace MLEM.Ui.Elements {
set => this.textInput.Multiline = value; set => this.textInput.Multiline = value;
} }
#if FNA #if FNA
/// <inheritdoc /> /// <inheritdoc />
// we need to make sure that the enter press doesn't get consumed by our press function so that it still works in TextInput // we need to make sure that the enter press doesn't get consumed by our press function so that it still works in TextInput
public override bool CanBePressed => base.CanBePressed && !this.IsSelected; public override bool CanBePressed => base.CanBePressed && !this.IsSelected;
#endif #endif
/// <summary> /// <summary>
/// The text that displays in this text field if <see cref="Text"/> is empty /// The text that displays in this text field if <see cref="Text"/> is empty
@ -146,9 +146,9 @@ namespace MLEM.Ui.Elements {
/// <param name="multiline">Whether the text field should support multi-line editing</param> /// <param name="multiline">Whether the text field should support multi-line editing</param>
public TextField(Anchor anchor, Vector2 size, Rule rule = null, GenericFont font = null, string text = null, bool multiline = false) : base(anchor, size) { public TextField(Anchor anchor, Vector2 size, Rule rule = null, GenericFont font = null, string text = null, bool multiline = false) : base(anchor, size) {
this.textInput = new TextInput(null, Vector2.Zero, 1 this.textInput = new TextInput(null, Vector2.Zero, 1
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER #if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
, null, ClipboardService.SetText, ClipboardService.GetText , null, ClipboardService.SetText, ClipboardService.GetText
#endif #endif
) { ) {
OnTextChange = (i, s) => this.OnTextChange?.Invoke(this, s), OnTextChange = (i, s) => this.OnTextChange?.Invoke(this, s),
InputRule = (i, s) => this.InputRule.Invoke(this, s) InputRule = (i, s) => this.InputRule.Invoke(this, s)

View file

@ -100,9 +100,9 @@ namespace MLEM.Ui.Elements {
public Tooltip(string text = null, Element elementToHover = null) : public Tooltip(string text = null, Element elementToHover = null) :
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) { base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
if (text != null) { if (text != null) {
#pragma warning disable CS0618 #pragma warning disable CS0618
this.Paragraph = this.AddParagraph(text); this.Paragraph = this.AddParagraph(text);
#pragma warning restore CS0618 #pragma warning restore CS0618
} }
this.Init(elementToHover); this.Init(elementToHover);
} }
@ -114,9 +114,9 @@ namespace MLEM.Ui.Elements {
/// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param> /// <param name="elementToHover">The element that should automatically cause the tooltip to appear and disappear when hovered and not hovered, respectively</param>
public Tooltip(Paragraph.TextCallback textCallback, Element elementToHover = null) : public Tooltip(Paragraph.TextCallback textCallback, Element elementToHover = null) :
base(Anchor.TopLeft, Vector2.One, Vector2.Zero) { base(Anchor.TopLeft, Vector2.One, Vector2.Zero) {
#pragma warning disable CS0618 #pragma warning disable CS0618
this.Paragraph = this.AddParagraph(textCallback); this.Paragraph = this.AddParagraph(textCallback);
#pragma warning restore CS0618 #pragma warning restore CS0618
this.Init(elementToHover); this.Init(elementToHover);
} }
@ -298,11 +298,11 @@ namespace MLEM.Ui.Elements {
foreach (var paragraph in this.Paragraphs) foreach (var paragraph in this.Paragraphs)
this.UpdateParagraphStyle(paragraph); this.UpdateParagraphStyle(paragraph);
#pragma warning disable CS0618 #pragma warning disable CS0618
// still set style here in case someone changed the paragraph field manually // still set style here in case someone changed the paragraph field manually
if (this.Paragraph != null) if (this.Paragraph != null)
this.UpdateParagraphStyle(this.Paragraph); this.UpdateParagraphStyle(this.Paragraph);
#pragma warning restore CS0618 #pragma warning restore CS0618
} }
private void UpdateParagraphStyle(Paragraph paragraph) { private void UpdateParagraphStyle(Paragraph paragraph) {

View file

@ -10,6 +10,7 @@ using MLEM.Ui.Style;
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER #if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
using System.Net.Http; using System.Net.Http;
#else #else
using System.Net; using System.Net;
#endif #endif
@ -25,11 +26,11 @@ namespace MLEM.Ui.Parsers {
/// An array containing all of the <see cref="ElementType"/> enum values. /// An array containing all of the <see cref="ElementType"/> enum values.
/// </summary> /// </summary>
public static readonly ElementType[] ElementTypes = public static readonly ElementType[] ElementTypes =
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
Enum.GetValues<ElementType>(); Enum.GetValues<ElementType>();
#else #else
(ElementType[]) Enum.GetValues(typeof(ElementType)); (ElementType[]) Enum.GetValues(typeof(ElementType));
#endif #endif
/// <summary> /// <summary>
/// The base path for images, which is prepended to the image link. /// The base path for images, which is prepended to the image link.
@ -164,13 +165,13 @@ namespace MLEM.Ui.Parsers {
Texture2D tex; Texture2D tex;
if (path.StartsWith("http")) { if (path.StartsWith("http")) {
byte[] src; byte[] src;
#if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER #if NETSTANDARD2_0_OR_GREATER || NET6_0_OR_GREATER
using (var client = new HttpClient()) using (var client = new HttpClient())
src = await client.GetByteArrayAsync(path); src = await client.GetByteArrayAsync(path);
#else #else
using (var client = new WebClient()) using (var client = new WebClient())
src = await client.DownloadDataTaskAsync(path); src = await client.DownloadDataTaskAsync(path);
#endif #endif
using (var memory = new MemoryStream(src)) using (var memory = new MemoryStream(src))
tex = Texture2D.FromStream(this.GraphicsDevice, memory); tex = Texture2D.FromStream(this.GraphicsDevice, memory);
} else { } else {

View file

@ -84,7 +84,7 @@ namespace MLEM.Ui.Style {
/// <param name="obj">The object to compare with the current instance.</param> /// <param name="obj">The object to compare with the current instance.</param>
/// <returns>true if <paramref name="obj">obj</paramref> and this instance are the same type and represent the same value; otherwise, false.</returns> /// <returns>true if <paramref name="obj">obj</paramref> and this instance are the same type and represent the same value; otherwise, false.</returns>
[Obsolete("StyleProp equality is ambiguous as it is not clear whether priority is taken into account. Compare Values instead.")] [Obsolete("StyleProp equality is ambiguous as it is not clear whether priority is taken into account. Compare Values instead.")]
#pragma warning disable CS0809 #pragma warning disable CS0809
public override bool Equals(object obj) { public override bool Equals(object obj) {
return obj is StyleProp<T> other && this.Equals(other); return obj is StyleProp<T> other && this.Equals(other);
} }
@ -95,7 +95,7 @@ namespace MLEM.Ui.Style {
public override int GetHashCode() { public override int GetHashCode() {
return EqualityComparer<T>.Default.GetHashCode(this.Value); return EqualityComparer<T>.Default.GetHashCode(this.Value);
} }
#pragma warning restore CS0809 #pragma warning restore CS0809
/// <summary>Returns the fully qualified type name of this instance.</summary> /// <summary>Returns the fully qualified type name of this instance.</summary>
/// <returns>The fully qualified type name.</returns> /// <returns>The fully qualified type name.</returns>

View file

@ -309,7 +309,7 @@ namespace MLEM.Ui {
var context = this.SpriteBatchContext; var context = this.SpriteBatchContext;
context.TransformMatrix = root.Transform * context.TransformMatrix; context.TransformMatrix = root.Transform * context.TransformMatrix;
#pragma warning disable CS0618 #pragma warning disable CS0618
if (this.BlendState != null) if (this.BlendState != null)
context.BlendState = this.BlendState; context.BlendState = this.BlendState;
if (this.SamplerState != null) if (this.SamplerState != null)
@ -318,12 +318,12 @@ namespace MLEM.Ui {
context.DepthStencilState = this.DepthStencilState; context.DepthStencilState = this.DepthStencilState;
if (this.Effect != null) if (this.Effect != null)
context.Effect = this.Effect; context.Effect = this.Effect;
#pragma warning restore CS0618 #pragma warning restore CS0618
batch.Begin(context); batch.Begin(context);
#pragma warning disable CS0618 #pragma warning disable CS0618
root.Element.DrawTransformed(time, batch, this.DrawAlpha * root.Element.DrawAlpha, context.BlendState, context.SamplerState, context.DepthStencilState, context.Effect, context.TransformMatrix); root.Element.DrawTransformed(time, batch, this.DrawAlpha * root.Element.DrawAlpha, context.BlendState, context.SamplerState, context.DepthStencilState, context.Effect, context.TransformMatrix);
#pragma warning restore CS0618 #pragma warning restore CS0618
batch.End(); batch.End();
} }

View file

@ -51,7 +51,7 @@ namespace MLEM.Extensions {
return combos; return combos;
} }
#if NET452 #if NET452
/// <summary>Appends a value to the end of the sequence.</summary> /// <summary>Appends a value to the end of the sequence.</summary>
/// <param name="source">A sequence of values.</param> /// <param name="source">A sequence of values.</param>
/// <param name="element">The value to append to <paramref name="source"/>.</param> /// <param name="element">The value to append to <paramref name="source"/>.</param>
@ -73,7 +73,7 @@ namespace MLEM.Extensions {
foreach (var src in source) foreach (var src in source)
yield return src; yield return src;
} }
#endif #endif
} }
} }

View file

@ -90,12 +90,12 @@ namespace MLEM.Extensions {
/// <param name="target">The target to apply</param> /// <param name="target">The target to apply</param>
public TargetContext(GraphicsDevice device, RenderTarget2D target) { public TargetContext(GraphicsDevice device, RenderTarget2D target) {
this.device = device; this.device = device;
#if FNA #if FNA
// RenderTargetCount doesn't exist in FNA but we still want the optimization in MG // RenderTargetCount doesn't exist in FNA but we still want the optimization in MG
this.lastTargets = device.GetRenderTargets(); this.lastTargets = device.GetRenderTargets();
#else #else
this.lastTargets = device.RenderTargetCount <= 0 ? null : device.GetRenderTargets(); this.lastTargets = device.RenderTargetCount <= 0 ? null : device.GetRenderTargets();
#endif #endif
device.SetRenderTarget(target); device.SetRenderTarget(target);
} }

View file

@ -288,7 +288,7 @@ namespace MLEM.Extensions {
return false; return false;
} }
#if FNA #if FNA
/// <summary> /// <summary>
/// Gets a <see cref="Point"/> representation for this object. /// Gets a <see cref="Point"/> representation for this object.
/// </summary> /// </summary>
@ -339,7 +339,7 @@ namespace MLEM.Extensions {
y = vector.Y; y = vector.Y;
z = vector.Z; z = vector.Z;
} }
#endif #endif
} }
} }

View file

@ -360,7 +360,7 @@ namespace MLEM.Font {
var total = new StringBuilder(); var total = new StringBuilder();
var extraWidth = 0F; var extraWidth = 0F;
var endReached = false; var endReached = false;
foreach (var part in (fromBack ? text.Reverse() : text)) { foreach (var part in fromBack ? text.Reverse() : text) {
var curr = new StringBuilder(); var curr = new StringBuilder();
// if we reached the end previously, all the other parts should just be empty // if we reached the end previously, all the other parts should just be empty
if (!endReached) { if (!endReached) {

View file

@ -44,10 +44,10 @@ namespace MLEM.Font {
} }
private static SpriteFont SetDefaults(SpriteFont font) { private static SpriteFont SetDefaults(SpriteFont font) {
#if FNA #if FNA
// none of the copying is available with FNA // none of the copying is available with FNA
return font; return font;
#else #else
// we copy the font here to set the default character to a space // we copy the font here to set the default character to a space
return new SpriteFont( return new SpriteFont(
font.Texture, font.Texture,
@ -58,7 +58,7 @@ namespace MLEM.Font {
font.Spacing, font.Spacing,
font.Glyphs.Select(g => new Vector3(g.LeftSideBearing, g.Width, g.RightSideBearing)).ToList(), font.Glyphs.Select(g => new Vector3(g.LeftSideBearing, g.Width, g.RightSideBearing)).ToList(),
' '); ' ');
#endif #endif
} }
} }

View file

@ -143,9 +143,9 @@ namespace MLEM.Formatting {
private static string StripFormatting(GenericFont font, string s, IEnumerable<Code> codes) { private static string StripFormatting(GenericFont font, string s, IEnumerable<Code> codes) {
foreach (var code in codes) { foreach (var code in codes) {
#pragma warning disable CS0618 #pragma warning disable CS0618
s = code.Regex.Replace(s, code.GetReplacementString(font)); s = code.Regex.Replace(s, code.GetReplacementString(font));
#pragma warning restore CS0618 #pragma warning restore CS0618
} }
return s; return s;
} }

View file

@ -461,11 +461,11 @@ namespace MLEM.Graphics {
} }
private void DrawPrimitives(int vertices) { private void DrawPrimitives(int vertices) {
#if FNA #if FNA
this.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices, 0, vertices / 4 * 2); this.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices, 0, vertices / 4 * 2);
#else #else
this.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices / 4 * 2); this.graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices / 4 * 2);
#endif #endif
} }
private void AddItemToSet(Item item) { private void AddItemToSet(Item item) {
@ -560,7 +560,7 @@ namespace MLEM.Graphics {
} }
#if FNA #if FNA
private class SpriteEffect : Effect { private class SpriteEffect : Effect {
private EffectParameter matrixParam; private EffectParameter matrixParam;
@ -611,7 +611,7 @@ namespace MLEM.Graphics {
} }
} }
#endif #endif
} }
} }

View file

@ -18,26 +18,26 @@ namespace MLEM.Input {
/// All values of the <see cref="Buttons"/> enum. /// All values of the <see cref="Buttons"/> enum.
/// </summary> /// </summary>
public static readonly Buttons[] AllButtons = public static readonly Buttons[] AllButtons =
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
Enum.GetValues<Buttons>(); Enum.GetValues<Buttons>();
#else #else
(Buttons[]) Enum.GetValues(typeof(Buttons)); (Buttons[]) Enum.GetValues(typeof(Buttons));
#endif #endif
/// <summary> /// <summary>
/// All values of the <see cref="Keys"/> enum. /// All values of the <see cref="Keys"/> enum.
/// </summary> /// </summary>
public static readonly Keys[] AllKeys = public static readonly Keys[] AllKeys =
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
Enum.GetValues<Keys>(); Enum.GetValues<Keys>();
#else #else
(Keys[]) Enum.GetValues(typeof(Keys)); (Keys[]) Enum.GetValues(typeof(Keys));
#endif #endif
#if FNA #if FNA
private const int MaximumGamePadCount = 4; private const int MaximumGamePadCount = 4;
#else #else
private static readonly int MaximumGamePadCount = GamePad.MaximumGamePadCount; private static readonly int MaximumGamePadCount = GamePad.MaximumGamePadCount;
#endif #endif
private static readonly TouchLocation[] EmptyTouchLocations = new TouchLocation[0]; private static readonly TouchLocation[] EmptyTouchLocations = new TouchLocation[0];
private static readonly GenericInput[] EmptyGenericInputs = new GenericInput[0]; private static readonly GenericInput[] EmptyGenericInputs = new GenericInput[0];
@ -258,11 +258,11 @@ namespace MLEM.Input {
} }
} else { } else {
// mouse position and scroll wheel value should be preserved when the mouse is out of bounds // mouse position and scroll wheel value should be preserved when the mouse is out of bounds
#if FNA #if FNA
this.MouseState = new MouseState(state.X, state.Y, state.ScrollWheelValue, 0, 0, 0, 0, 0); this.MouseState = new MouseState(state.X, state.Y, state.ScrollWheelValue, 0, 0, 0, 0, 0);
#else #else
this.MouseState = new MouseState(state.X, state.Y, state.ScrollWheelValue, 0, 0, 0, 0, 0, state.HorizontalScrollWheelValue); this.MouseState = new MouseState(state.X, state.Y, state.ScrollWheelValue, 0, 0, 0, 0, 0, state.HorizontalScrollWheelValue);
#endif #endif
} }
} else { } else {
this.MouseState = default; this.MouseState = default;

View file

@ -246,7 +246,7 @@ namespace MLEM.Input {
/// <returns>Whether text was successfully input.</returns> /// <returns>Whether text was successfully input.</returns>
public bool OnTextInput(Keys key, char character) { public bool OnTextInput(Keys key, char character) {
// FNA's text input event doesn't supply keys, so we handle this in Update // FNA's text input event doesn't supply keys, so we handle this in Update
#if !FNA #if !FNA
if (key == Keys.Back) { if (key == Keys.Back) {
if (this.CaretPos > 0) { if (this.CaretPos > 0) {
this.CaretPos--; this.CaretPos--;
@ -261,9 +261,9 @@ namespace MLEM.Input {
return this.InsertText(character); return this.InsertText(character);
} }
return false; return false;
#else #else
return this.InsertText(character); return this.InsertText(character);
#endif #endif
} }
/// <summary> /// <summary>
@ -274,8 +274,8 @@ namespace MLEM.Input {
public void Update(GameTime time, InputHandler input) { public void Update(GameTime time, InputHandler input) {
this.UpdateTextDataIfDirty(); this.UpdateTextDataIfDirty();
#if FNA
// FNA's text input event doesn't supply keys, so we handle this here // FNA's text input event doesn't supply keys, so we handle this here
#if FNA
if (this.CaretPos > 0 && input.TryConsumePressed(Keys.Back)) { if (this.CaretPos > 0 && input.TryConsumePressed(Keys.Back)) {
this.CaretPos--; this.CaretPos--;
this.RemoveText(this.CaretPos, 1); this.RemoveText(this.CaretPos, 1);
@ -284,7 +284,7 @@ namespace MLEM.Input {
} else if (this.Multiline && input.TryConsumePressed(Keys.Enter)) { } else if (this.Multiline && input.TryConsumePressed(Keys.Enter)) {
this.InsertText('\n'); this.InsertText('\n');
} else } else
#endif #endif
if (this.CaretPos > 0 && input.TryConsumePressed(Keys.Left)) { if (this.CaretPos > 0 && input.TryConsumePressed(Keys.Left)) {
this.CaretPos--; this.CaretPos--;
} else if (this.CaretPos < this.text.Length && input.TryConsumePressed(Keys.Right)) { } else if (this.CaretPos < this.text.Length && input.TryConsumePressed(Keys.Right)) {

View file

@ -27,11 +27,11 @@ namespace MLEM.Misc {
/// <typeparam name="T">The type whose enum to get</typeparam> /// <typeparam name="T">The type whose enum to get</typeparam>
/// <returns>An enumerable of the values of the enum, in declaration order.</returns> /// <returns>An enumerable of the values of the enum, in declaration order.</returns>
public static T[] GetValues<T>() where T : struct, Enum { public static T[] GetValues<T>() where T : struct, Enum {
#if NET6_0_OR_GREATER #if NET6_0_OR_GREATER
return Enum.GetValues<T>(); return Enum.GetValues<T>();
#else #else
return (T[]) Enum.GetValues(typeof(T)); return (T[]) Enum.GetValues(typeof(T));
#endif #endif
} }
/// <summary> /// <summary>

View file

@ -399,7 +399,7 @@ public class GameImpl : MlemGame {
Console.WriteLine("Down: " + string.Join(", ", Input.InputsDown));*/ Console.WriteLine("Down: " + string.Join(", ", Input.InputsDown));*/
if (MlemGame.Input.InputsPressed.Length > 0) if (MlemGame.Input.InputsPressed.Length > 0)
Console.WriteLine("Pressed: " + string.Join(", ", MlemGame.Input.InputsPressed)); Console.WriteLine("Pressed: " + string.Join(", ", MlemGame.Input.InputsPressed));
MlemGame.Input.HandleKeyboardRepeats = false;/* MlemGame.Input.HandleKeyboardRepeats = false; /*
Console.WriteLine("Down time: " + MlemGame.Input.GetDownTime(Keys.A)); Console.WriteLine("Down time: " + MlemGame.Input.GetDownTime(Keys.A));
Console.WriteLine("Time since press: " + MlemGame.Input.GetTimeSincePress(Keys.A));*/ Console.WriteLine("Time since press: " + MlemGame.Input.GetTimeSincePress(Keys.A));*/
Console.WriteLine("Up time: " + MlemGame.Input.GetUpTime(Keys.A)); Console.WriteLine("Up time: " + MlemGame.Input.GetUpTime(Keys.A));

View file

@ -2,7 +2,7 @@
using MLEM.Cameras; using MLEM.Cameras;
using NUnit.Framework; using NUnit.Framework;
namespace Tests; namespace Tests;
public class CameraTests { public class CameraTests {

View file

@ -1,7 +1,7 @@
using MLEM.Extensions; using MLEM.Extensions;
using NUnit.Framework; using NUnit.Framework;
namespace Tests; namespace Tests;
public class CollectionTests { public class CollectionTests {

View file

@ -5,7 +5,7 @@ using MLEM.Data;
using MLEM.Textures; using MLEM.Textures;
using NUnit.Framework; using NUnit.Framework;
namespace Tests; namespace Tests;
public class TestDataTextureAtlas { public class TestDataTextureAtlas {

View file

@ -2,7 +2,7 @@ using Microsoft.Xna.Framework;
using MLEM.Misc; using MLEM.Misc;
using NUnit.Framework; using NUnit.Framework;
namespace Tests; namespace Tests;
public class DirectionTests { public class DirectionTests {

View file

@ -2,7 +2,7 @@
using MLEM.Input; using MLEM.Input;
using NUnit.Framework; using NUnit.Framework;
namespace Tests; namespace Tests;
public class KeybindTests { public class KeybindTests {

View file

@ -73,7 +73,7 @@ public class NumberTests {
Assert.AreEqual(penetration, 0); Assert.AreEqual(penetration, 0);
} }
#if !FNA #if !FNA
[Test] [Test]
public void TestRangePercentage() { public void TestRangePercentage() {
Assert.AreEqual(0.5F, new Range<int>(1, 7).GetPercentage(4)); Assert.AreEqual(0.5F, new Range<int>(1, 7).GetPercentage(4));
@ -95,6 +95,6 @@ public class NumberTests {
Assert.AreEqual(11, new Range<float>(8, 10).FromPercentage(1.5F)); Assert.AreEqual(11, new Range<float>(8, 10).FromPercentage(1.5F));
Assert.AreEqual(7, new Range<float>(8, 10).FromPercentage(-0.5F)); Assert.AreEqual(7, new Range<float>(8, 10).FromPercentage(-0.5F));
} }
#endif #endif
} }

View file

@ -4,7 +4,7 @@ using Microsoft.Xna.Framework;
using MLEM.Pathfinding; using MLEM.Pathfinding;
using NUnit.Framework; using NUnit.Framework;
namespace Tests; namespace Tests;
public class PathfindingTests { public class PathfindingTests {

View file

@ -3,7 +3,7 @@ using MLEM.Data.Content;
using MLEM.Font; using MLEM.Font;
using MLEM.Startup; using MLEM.Startup;
namespace Tests; namespace Tests;
public class TestGame : MlemGame { public class TestGame : MlemGame {

View file

@ -4,7 +4,7 @@ using MLEM.Data;
using MLEM.Textures; using MLEM.Textures;
using NUnit.Framework; using NUnit.Framework;
namespace Tests; namespace Tests;
public class TexturePackerTests { public class TexturePackerTests {

View file

@ -8,7 +8,7 @@ using MLEM.Ui.Elements;
using MLEM.Ui.Style; using MLEM.Ui.Style;
using NUnit.Framework; using NUnit.Framework;
namespace Tests; namespace Tests;
public class UiTests { public class UiTests {