From 0a696941dcbf6c45427b36a6e8c660d38c605321 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 20 Aug 2022 11:39:28 +0200 Subject: [PATCH] cleaned up code --- Demos.DesktopGL/Demos.DesktopGL.FNA.csproj | 2 +- Demos.DesktopGL/Demos.DesktopGL.csproj | 12 ++++---- Demos.DesktopGL/Program.cs | 28 ++++++++--------- Demos/Demos.csproj | 10 +++---- Demos/EasingsDemo.cs | 2 +- Demos/GameImpl.cs | 3 -- Demos/TextFormattingDemo.cs | 2 +- FNA | 2 +- MLEM.Data/Content/Texture2DReader.cs | 23 +++++++------- MLEM.Data/DataTextureAtlas.cs | 5 ++-- MLEM.Data/RuntimeTexturePacker.cs | 2 +- MLEM.Ui/Elements/Element.cs | 2 +- MLEM.Ui/Elements/Image.cs | 4 ++- MLEM.Ui/Elements/ScrollBar.cs | 4 ++- MLEM.Ui/Elements/TextField.cs | 1 - MLEM.Ui/Elements/Tooltip.cs | 4 ++- MLEM.Ui/Style/UiStyle.cs | 2 +- MLEM.Ui/UiMetrics.cs | 1 - MLEM.Ui/UiSystem.cs | 2 +- MLEM/Extensions/NumberExtensions.cs | 35 ++++++++++++++++++++++ MLEM/Font/GenericSpriteFont.cs | 5 +++- MLEM/Graphics/AutoTiling.cs | 6 ++-- MLEM/Graphics/StaticSpriteBatch.cs | 4 ++- MLEM/Input/InputHandler.cs | 2 +- Sandbox/GameImpl.cs | 25 ++++++++-------- Sandbox/Program.cs | 7 ++--- Tests/DataTests.cs | 6 ++-- Tests/FontTests.cs | 10 +++---- Tests/PathfindingTests.cs | 2 +- Tests/UiTests.cs | 4 +-- 30 files changed, 128 insertions(+), 89 deletions(-) diff --git a/Demos.DesktopGL/Demos.DesktopGL.FNA.csproj b/Demos.DesktopGL/Demos.DesktopGL.FNA.csproj index 58a5df6..7933bf0 100644 --- a/Demos.DesktopGL/Demos.DesktopGL.FNA.csproj +++ b/Demos.DesktopGL/Demos.DesktopGL.FNA.csproj @@ -2,7 +2,7 @@ Exe - net5.0 + net6.0 Icon.ico MLEM Desktop Demos Demos.DesktopGL diff --git a/Demos.DesktopGL/Demos.DesktopGL.csproj b/Demos.DesktopGL/Demos.DesktopGL.csproj index f902a15..f2fd359 100644 --- a/Demos.DesktopGL/Demos.DesktopGL.csproj +++ b/Demos.DesktopGL/Demos.DesktopGL.csproj @@ -1,31 +1,31 @@  - + Exe net6.0 Icon.ico MLEM Desktop Demos - + - + - + - + - + diff --git a/Demos.DesktopGL/Program.cs b/Demos.DesktopGL/Program.cs index 0ec70d1..9a1363a 100644 --- a/Demos.DesktopGL/Program.cs +++ b/Demos.DesktopGL/Program.cs @@ -1,20 +1,20 @@ -using System; -using Microsoft.Xna.Framework; +using MLEM.Misc; +#if FNA using Microsoft.Xna.Framework.Input; -using MLEM.Misc; +#endif -namespace Demos.DesktopGL { - public static class Program { +namespace Demos.DesktopGL; - public static void Main() { - #if FNA - MlemPlatform.Current = new MlemPlatform.DesktopFna(a => TextInputEXT.TextInput += a); - #else - MlemPlatform.Current = new MlemPlatform.DesktopGl((w, c) => w.TextInput += c); - #endif - using var game = new GameImpl(); - game.Run(); - } +public static class Program { + public static void Main() { + #if FNA + MlemPlatform.Current = new MlemPlatform.DesktopFna(a => TextInputEXT.TextInput += a); + #else + MlemPlatform.Current = new MlemPlatform.DesktopGl((w, c) => w.TextInput += c); + #endif + using var game = new GameImpl(); + game.Run(); } + } diff --git a/Demos/Demos.csproj b/Demos/Demos.csproj index 93be6d2..e0742c1 100644 --- a/Demos/Demos.csproj +++ b/Demos/Demos.csproj @@ -1,17 +1,17 @@  - + - net6.0 + netstandard2.0 - + - + - + all diff --git a/Demos/EasingsDemo.cs b/Demos/EasingsDemo.cs index 14d5832..f77d6df 100644 --- a/Demos/EasingsDemo.cs +++ b/Demos/EasingsDemo.cs @@ -43,7 +43,7 @@ namespace Demos { this.GraphicsDevice.Clear(Color.CornflowerBlue); base.DoDraw(time); - this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null); + this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise); var view = this.GraphicsDevice.Viewport; // graph the easing function diff --git a/Demos/GameImpl.cs b/Demos/GameImpl.cs index 6eb6930..5badbb6 100644 --- a/Demos/GameImpl.cs +++ b/Demos/GameImpl.cs @@ -9,9 +9,6 @@ using MLEM.Textures; using MLEM.Ui; using MLEM.Ui.Elements; using MLEM.Ui.Style; -#if !FNA -using MonoGame.Framework.Utilities; -#endif namespace Demos { public class GameImpl : MlemGame { diff --git a/Demos/TextFormattingDemo.cs b/Demos/TextFormattingDemo.cs index 152d4ab..2473ff0 100644 --- a/Demos/TextFormattingDemo.cs +++ b/Demos/TextFormattingDemo.cs @@ -50,7 +50,7 @@ namespace Demos { public override void DoDraw(GameTime time) { this.GraphicsDevice.Clear(Color.DarkSlateGray); - this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null); + this.SpriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullCounterClockwise); // we draw the tokenized text in the center of the screen // since the text is already center-aligned, we only need to align it on the y axis here diff --git a/FNA b/FNA index 31ff5cd..dfa9ce8 160000 --- a/FNA +++ b/FNA @@ -1 +1 @@ -Subproject commit 31ff5cd8b6d62b0c10b627c67cc66db1d4def4e7 +Subproject commit dfa9ce8cfd46846ad1df81283e84cfe5cee4faca diff --git a/MLEM.Data/Content/Texture2DReader.cs b/MLEM.Data/Content/Texture2DReader.cs index 70b8c34..7e38746 100644 --- a/MLEM.Data/Content/Texture2DReader.cs +++ b/MLEM.Data/Content/Texture2DReader.cs @@ -13,22 +13,21 @@ namespace MLEM.Data.Content { if (existing != null) { existing.Reload(stream); return existing; - } else + } #endif - { - // premultiply the texture's color to be in line with the pipeline's texture reader - using (var texture = Texture2D.FromStream(manager.GraphicsDevice, stream)) { - var ret = new Texture2D(manager.GraphicsDevice, texture.Width, texture.Height); - using (var textureData = texture.GetTextureData()) { - using (var retData = ret.GetTextureData()) { - for (var x = 0; x < ret.Width; x++) { - for (var y = 0; y < ret.Height; y++) - retData[x, y] = Color.FromNonPremultiplied(textureData[x, y].ToVector4()); - } + + // premultiply the texture's color to be in line with the pipeline's texture reader + using (var texture = Texture2D.FromStream(manager.GraphicsDevice, stream)) { + var ret = new Texture2D(manager.GraphicsDevice, texture.Width, texture.Height); + using (var textureData = texture.GetTextureData()) { + using (var retData = ret.GetTextureData()) { + for (var x = 0; x < ret.Width; x++) { + for (var y = 0; y < ret.Height; y++) + retData[x, y] = Color.FromNonPremultiplied(textureData[x, y].ToVector4()); } } - return ret; } + return ret; } } diff --git a/MLEM.Data/DataTextureAtlas.cs b/MLEM.Data/DataTextureAtlas.cs index 5e1b9d2..400a200 100644 --- a/MLEM.Data/DataTextureAtlas.cs +++ b/MLEM.Data/DataTextureAtlas.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -6,8 +5,10 @@ using System.Text.RegularExpressions; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; -using MLEM.Extensions; using MLEM.Textures; +#if FNA +using MLEM.Extensions; +#endif namespace MLEM.Data { /// diff --git a/MLEM.Data/RuntimeTexturePacker.cs b/MLEM.Data/RuntimeTexturePacker.cs index 9c55c3c..7f47435 100644 --- a/MLEM.Data/RuntimeTexturePacker.cs +++ b/MLEM.Data/RuntimeTexturePacker.cs @@ -267,7 +267,7 @@ namespace MLEM.Data { srcColor = Color.Transparent; } else { // otherwise, we just use the closest pixel that is actually in bounds, causing the border pixels to be doubled up - var src = new Point((int) MathHelper.Clamp(x, 0, request.Texture.Width - 1), (int) MathHelper.Clamp(y, 0, request.Texture.Height - 1)); + var src = new Point((int) MathHelper.Clamp(x, 0F, request.Texture.Width - 1), (int) MathHelper.Clamp(y, 0F, request.Texture.Height - 1)); srcColor = data[request.Texture.Position + src]; } destination[location + new Point(x, y)] = srcColor; diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index d51e2fb..ccf3748 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -10,9 +10,9 @@ using MLEM.Extensions; using MLEM.Graphics; using MLEM.Input; using MLEM.Misc; +using MLEM.Sound; using MLEM.Textures; using MLEM.Ui.Style; -using SoundEffectInfo = MLEM.Sound.SoundEffectInfo; namespace MLEM.Ui.Elements { /// diff --git a/MLEM.Ui/Elements/Image.cs b/MLEM.Ui/Elements/Image.cs index 79ad69e..976eb7e 100644 --- a/MLEM.Ui/Elements/Image.cs +++ b/MLEM.Ui/Elements/Image.cs @@ -1,11 +1,13 @@ using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using MLEM.Extensions; using MLEM.Graphics; using MLEM.Misc; using MLEM.Textures; using MLEM.Ui.Style; +#if FNA +using MLEM.Extensions; +#endif namespace MLEM.Ui.Elements { /// diff --git a/MLEM.Ui/Elements/ScrollBar.cs b/MLEM.Ui/Elements/ScrollBar.cs index e421def..541c282 100644 --- a/MLEM.Ui/Elements/ScrollBar.cs +++ b/MLEM.Ui/Elements/ScrollBar.cs @@ -3,12 +3,14 @@ using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input.Touch; -using MLEM.Extensions; using MLEM.Graphics; using MLEM.Input; using MLEM.Misc; using MLEM.Textures; using MLEM.Ui.Style; +#if FNA +using MLEM.Extensions; +#endif namespace MLEM.Ui.Elements { /// diff --git a/MLEM.Ui/Elements/TextField.cs b/MLEM.Ui/Elements/TextField.cs index 6e67716..9eafbd8 100644 --- a/MLEM.Ui/Elements/TextField.cs +++ b/MLEM.Ui/Elements/TextField.cs @@ -1,4 +1,3 @@ -using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using MLEM.Font; diff --git a/MLEM.Ui/Elements/Tooltip.cs b/MLEM.Ui/Elements/Tooltip.cs index 18b1f6e..704d8a5 100644 --- a/MLEM.Ui/Elements/Tooltip.cs +++ b/MLEM.Ui/Elements/Tooltip.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using Microsoft.Xna.Framework; -using MLEM.Extensions; using MLEM.Input; using MLEM.Ui.Style; +#if FNA +using MLEM.Extensions; +#endif namespace MLEM.Ui.Elements { /// diff --git a/MLEM.Ui/Style/UiStyle.cs b/MLEM.Ui/Style/UiStyle.cs index 66655a0..85bdb73 100644 --- a/MLEM.Ui/Style/UiStyle.cs +++ b/MLEM.Ui/Style/UiStyle.cs @@ -5,9 +5,9 @@ using MLEM.Font; using MLEM.Formatting; using MLEM.Formatting.Codes; using MLEM.Misc; +using MLEM.Sound; using MLEM.Textures; using MLEM.Ui.Elements; -using SoundEffectInfo = MLEM.Sound.SoundEffectInfo; namespace MLEM.Ui.Style { /// diff --git a/MLEM.Ui/UiMetrics.cs b/MLEM.Ui/UiMetrics.cs index 81901e0..994cfc1 100644 --- a/MLEM.Ui/UiMetrics.cs +++ b/MLEM.Ui/UiMetrics.cs @@ -1,5 +1,4 @@ using System; -using Microsoft.Xna.Framework.Graphics; using MLEM.Ui.Elements; namespace MLEM.Ui { diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index 9176fbb..2f4fd32 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -561,7 +561,7 @@ namespace MLEM.Ui { /// This property returns if is and the is not hidden, or if it has been set to manually. /// public bool CanBeActive { - get => this.canBeActive || (!this.Element.IsHidden && this.CanSelectContent); + get => this.canBeActive || !this.Element.IsHidden && this.CanSelectContent; set => this.canBeActive = value; } diff --git a/MLEM/Extensions/NumberExtensions.cs b/MLEM/Extensions/NumberExtensions.cs index 3900c06..ca13bcd 100644 --- a/MLEM/Extensions/NumberExtensions.cs +++ b/MLEM/Extensions/NumberExtensions.cs @@ -304,6 +304,41 @@ namespace MLEM.Extensions { public static Vector2 ToVector2(this Point point) { return new Vector2(point.X, point.Y); } + + /// + /// Deconstruction method for . + /// + /// The point to deconstruct. + /// + /// + public static void Deconstruct(this Point point, out int x, out int y) { + x = point.X; + y = point.Y; + } + + /// + /// Deconstruction method for . + /// + /// The vector to deconstruct. + /// + /// + public static void Deconstruct(this Vector2 vector, out float x, out float y) { + x = vector.X; + y = vector.Y; + } + + /// + /// Deconstruction method for . + /// + /// The vector to deconstruct. + /// + /// + /// + public static void Deconstruct(this Vector3 vector, out float x, out float y, out float z) { + x = vector.X; + y = vector.Y; + z = vector.Z; + } #endif } diff --git a/MLEM/Font/GenericSpriteFont.cs b/MLEM/Font/GenericSpriteFont.cs index 3250149..abfa44d 100644 --- a/MLEM/Font/GenericSpriteFont.cs +++ b/MLEM/Font/GenericSpriteFont.cs @@ -1,8 +1,11 @@ -using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using MLEM.Extensions; +#if !FNA +using System.Linq; +#endif + namespace MLEM.Font { /// public class GenericSpriteFont : GenericFont { diff --git a/MLEM/Graphics/AutoTiling.cs b/MLEM/Graphics/AutoTiling.cs index f5efc7f..56f63f1 100644 --- a/MLEM/Graphics/AutoTiling.cs +++ b/MLEM/Graphics/AutoTiling.cs @@ -88,7 +88,7 @@ namespace MLEM.Graphics { var orig = origin ?? Vector2.Zero; var sc = scale ?? Vector2.One; var od = layerDepth + overlayDepthOffset; - var (r1, r2, r3, r4) = AutoTiling.CalculateExtendedAutoTile(pos, overlayTexture.Area, connectsTo, sc); + var (r1, r2, r3, r4) = AutoTiling.CalculateExtendedAutoTile(overlayTexture.Area, connectsTo); if (backgroundTexture != null) batch.Draw(backgroundTexture, pos, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth); if (r1 != Rectangle.Empty) @@ -106,7 +106,7 @@ namespace MLEM.Graphics { var orig = origin ?? Vector2.Zero; var sc = scale ?? Vector2.One; var od = layerDepth + overlayDepthOffset; - var (r1, r2, r3, r4) = AutoTiling.CalculateExtendedAutoTile(pos, overlayTexture.Area, connectsTo, sc); + var (r1, r2, r3, r4) = AutoTiling.CalculateExtendedAutoTile(overlayTexture.Area, connectsTo); if (backgroundTexture != null) { var background = batch.Add(backgroundTexture, pos, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth); items?.Add(background); @@ -147,7 +147,7 @@ namespace MLEM.Graphics { new Vector2(pos.X + w2 * scale.X, pos.Y + h2 * scale.Y), new Rectangle(textureRegion.X + w2 + xDr * w, textureRegion.Y + h2, w2, h2)); } - private static (Rectangle, Rectangle, Rectangle, Rectangle) CalculateExtendedAutoTile(Vector2 pos, Rectangle textureRegion, ConnectsTo connectsTo, Vector2 scale) { + private static (Rectangle, Rectangle, Rectangle, Rectangle) CalculateExtendedAutoTile(Rectangle textureRegion, ConnectsTo connectsTo) { var up = connectsTo(0, -1); var down = connectsTo(0, 1); var left = connectsTo(-1, 0); diff --git a/MLEM/Graphics/StaticSpriteBatch.cs b/MLEM/Graphics/StaticSpriteBatch.cs index 3bdc033..e9cf4cf 100644 --- a/MLEM/Graphics/StaticSpriteBatch.cs +++ b/MLEM/Graphics/StaticSpriteBatch.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +#if FNA using MLEM.Extensions; +using System.IO; +#endif namespace MLEM.Graphics { /// diff --git a/MLEM/Input/InputHandler.cs b/MLEM/Input/InputHandler.cs index a3ef273..9856a7f 100644 --- a/MLEM/Input/InputHandler.cs +++ b/MLEM/Input/InputHandler.cs @@ -73,7 +73,7 @@ namespace MLEM.Input { /// public bool InvertPressBehavior; /// - /// If your project already handles the processing of MonoGame's gestures elsewhere, you can set this field to true to ensure that this input handler's gesture handling does not override your own, since objects can only be retrieved once and are then removed from the 's queue. + /// If your project already handles the processing of MonoGame's gestures elsewhere, you can set this field to true to ensure that this input handler's gesture handling does not override your own, since objects can only be retrieved once and are then removed from the 's queue. /// If this value is set to true, but you still want to be able to use , , and , you can make this input handler aware of a gesture for the duration of the update frame that you added it on by using . /// For more info, see https://mlem.ellpeck.de/articles/input.html#external-gesture-handling. /// diff --git a/Sandbox/GameImpl.cs b/Sandbox/GameImpl.cs index 9680d65..5d9e714 100644 --- a/Sandbox/GameImpl.cs +++ b/Sandbox/GameImpl.cs @@ -31,7 +31,7 @@ public class GameImpl : MlemGame { public GameImpl() { this.IsMouseVisible = true; - this.Window.ClientSizeChanged += (o, args) => { + this.Window.ClientSizeChanged += (_, _) => { Console.WriteLine("Size changed"); }; } @@ -121,7 +121,7 @@ public class GameImpl : MlemGame { var res = this.Content.LoadJson("Test"); Console.WriteLine("The res is " + res); - var gradient = this.SpriteBatch.GenerateGradientTexture(Color.Green, Color.Red, Color.Blue, Color.Yellow); + //var gradient = this.SpriteBatch.GenerateGradientTexture(Color.Green, Color.Red, Color.Blue, Color.Yellow); /*this.OnDraw += (game, time) => { this.SpriteBatch.Begin(); this.SpriteBatch.Draw(this.SpriteBatch.GetBlankTexture(), new Rectangle(640 - 4, 360 - 4, 8, 8), Color.Green); @@ -139,9 +139,9 @@ public class GameImpl : MlemGame { var sc = 4; var formatter = new TextFormatter(); formatter.AddImage("Test", new TextureRegion(tex, 0, 8, 24, 24)); - formatter.Macros.Add(new Regex(""), (f, m, r) => ""); - formatter.Macros.Add(new Regex(""), (f, m, r) => " blue"); - formatter.Macros.Add(new Regex(""), (f, m, r) => ""); + formatter.Macros.Add(new Regex(""), (_, _, _) => ""); + formatter.Macros.Add(new Regex(""), (_, _, _) => " blue"); + formatter.Macros.Add(new Regex(""), (_, _, _) => ""); var strg = "This text uses a bunch of non-breaking~spaces to see if macros work. Additionally, it uses a macro that resolves into a bunch of other macros and then, at the end, into text."; //var strg = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."; //var strg = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."; @@ -149,7 +149,7 @@ public class GameImpl : MlemGame { this.tokenized = formatter.Tokenize(font, strg); this.tokenized.Split(font, 400, sc); - var square = this.SpriteBatch.GenerateSquareTexture(Color.Yellow); + //var square = this.SpriteBatch.GenerateSquareTexture(Color.Yellow); var round = this.SpriteBatch.GenerateCircleTexture(Color.Green, 128); var region = new TextureRegion(round) {Pivot = new Vector2(0.5F)}; @@ -159,7 +159,7 @@ public class GameImpl : MlemGame { foreach (var r in atlas.Regions) Console.WriteLine(r.Name + ": " + r.U + " " + r.V + " " + r.Width + " " + r.Height + " " + r.PivotPixels); - this.OnDraw += (g, time) => { + this.OnDraw += (_, _) => { this.SpriteBatch.Begin(samplerState: SamplerState.PointClamp); //this.SpriteBatch.Draw(square, new Rectangle(10, 10, 400, 400), Color.White); //this.SpriteBatch.Draw(round, new Rectangle(10, 10, 400, 400), Color.White); @@ -173,7 +173,7 @@ public class GameImpl : MlemGame { //this.SpriteBatch.DrawGrid(new Vector2(30, 30), new Vector2(40, 60), new Point(10, 5), Color.Yellow, 3); this.SpriteBatch.End(); }; - this.OnUpdate += (g, time) => { + this.OnUpdate += (_, time) => { if (this.InputHandler.IsPressed(Keys.W)) { this.tokenized = formatter.Tokenize(font, strg); this.tokenized.Split(font, this.InputHandler.IsModifierKeyDown(ModifierKey.Shift) ? 400 : 500, sc); @@ -259,7 +259,7 @@ public class GameImpl : MlemGame { var rotation = 0F; var effects = SpriteEffects.None; - this.OnDraw += (g, time) => { + this.OnDraw += (_, _) => { const string testString = "This is a\ntest string\n\twith long lines.\nLet's write some more stuff. Let's\r\nsplit lines weirdly."; if (MlemGame.Input.IsKeyPressed(Keys.I)) { index++; @@ -335,15 +335,16 @@ public class GameImpl : MlemGame { };*/ var widthPanel = new Panel(Anchor.Center, Vector2.One, Vector2.Zero, true) {SetWidthBasedOnChildren = true}; - for (var i = 0; i < 5; i++) + for (var i = 0; i < 5; i++) { widthPanel.AddChild(new Paragraph(Anchor.AutoCenter, 100000, "Test String " + Math.Pow(10, i), true) { - OnUpdated = (e, time) => { - if (Input.IsPressed(Keys.A)) { + OnUpdated = (e, _) => { + if (MlemGame.Input.IsPressed(Keys.A)) { e.Anchor = (Anchor) (((int) e.Anchor + 1) % EnumHelper.GetValues().Length); Console.WriteLine(e.Anchor); } } }); + } this.UiSystem.Add("WidthTest", widthPanel); } diff --git a/Sandbox/Program.cs b/Sandbox/Program.cs index 5751e11..17411a3 100644 --- a/Sandbox/Program.cs +++ b/Sandbox/Program.cs @@ -1,7 +1,6 @@ -using Microsoft.Xna.Framework; -using MLEM.Misc; +using MLEM.Misc; -namespace Sandbox; +namespace Sandbox; internal static class Program { @@ -11,4 +10,4 @@ internal static class Program { game.Run(); } -} \ No newline at end of file +} diff --git a/Tests/DataTests.cs b/Tests/DataTests.cs index e8361c2..9e83ee5 100644 --- a/Tests/DataTests.cs +++ b/Tests/DataTests.cs @@ -12,11 +12,11 @@ using Vector2 = Microsoft.Xna.Framework.Vector2; namespace Tests { public class DataTests { - private readonly TestObject testObject = new(Vector2.One, "test") { + private readonly TestObject testObject = new() { Vec = new Vector2(10, 20), Point = new Point(20, 30), Dir = Direction2.Left, - OtherTest = new TestObject(Vector2.One, "other") { + OtherTest = new TestObject { Vec = new Vector2(70, 30), Dir = Direction2.Right } @@ -95,8 +95,6 @@ namespace Tests { public Direction2 Dir { get; set; } public TestObject OtherTest; - public TestObject(Vector2 test, string test2) {} - protected bool Equals(TestObject other) { return this.Vec.Equals(other.Vec) && this.Point.Equals(other.Point) && object.Equals(this.OtherTest, other.OtherTest) && this.Dir == other.Dir; } diff --git a/Tests/FontTests.cs b/Tests/FontTests.cs index 92340d4..e233294 100644 --- a/Tests/FontTests.cs +++ b/Tests/FontTests.cs @@ -102,16 +102,16 @@ namespace Tests { [Test] public void TestMacros() { - this.formatter.Macros.Add(new Regex(""), (f, m, r) => ""); - this.formatter.Macros.Add(new Regex(""), (f, m, r) => "blue"); - this.formatter.Macros.Add(new Regex(""), (f, m, r) => ""); + this.formatter.Macros.Add(new Regex(""), (_, _, _) => ""); + this.formatter.Macros.Add(new Regex(""), (_, _, _) => "blue"); + this.formatter.Macros.Add(new Regex(""), (_, _, _) => ""); const string strg = "This text uses a bunch of non-breaking~spaces to see if macros work. Additionally, it uses a macro that resolves into a bunch of other macros and then, at the end, into text."; const string goal = "This text uses a bunch of non-breaking\u00A0spaces to see if macros work. Additionally, it uses a macro that resolves into a bunch of other macros and then, at the end, into blue text."; Assert.AreEqual(this.formatter.ResolveMacros(strg), goal); // test recursive macros - this.formatter.Macros.Add(new Regex(""), (f, m, r) => ""); - this.formatter.Macros.Add(new Regex(""), (f, m, r) => ""); + this.formatter.Macros.Add(new Regex(""), (_, _, _) => ""); + this.formatter.Macros.Add(new Regex(""), (_, _, _) => ""); Assert.Throws(() => this.formatter.ResolveMacros("Test string")); } diff --git a/Tests/PathfindingTests.cs b/Tests/PathfindingTests.cs index 053d09f..6724eea 100644 --- a/Tests/PathfindingTests.cs +++ b/Tests/PathfindingTests.cs @@ -66,7 +66,7 @@ namespace Tests { 'X' => float.PositiveInfinity, _ => (float) char.GetNumericValue(c) }).ToArray()).ToArray(); - var pathFinder = new AStar2((p1, p2) => costs[p2.Y][p2.X], allowDiagonals); + var pathFinder = new AStar2((_, p2) => costs[p2.Y][p2.X], allowDiagonals); return pathFinder.FindPath(start, end); } diff --git a/Tests/UiTests.cs b/Tests/UiTests.cs index 1c1458e..e412697 100644 --- a/Tests/UiTests.cs +++ b/Tests/UiTests.cs @@ -122,12 +122,12 @@ namespace Tests { for (var i = 1; i <= 100; i++) { var totalUpdates = 0; var main = new Group(Anchor.TopLeft, new Vector2(50)) { - OnAreaUpdated = e => totalUpdates++ + OnAreaUpdated = _ => totalUpdates++ }; var group = main; for (var g = 0; g < i; g++) { group = group.AddChild(new Group(Anchor.TopLeft, Vector2.One) { - OnAreaUpdated = e => totalUpdates++ + OnAreaUpdated = _ => totalUpdates++ }); } stopwatch.Restart();