1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-18 15:18:45 +02:00

cleaned up code

This commit is contained in:
Ell 2022-08-20 11:39:28 +02:00
parent 6a271af017
commit 0a696941dc
30 changed files with 128 additions and 89 deletions

View file

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ApplicationIcon>Icon.ico</ApplicationIcon> <ApplicationIcon>Icon.ico</ApplicationIcon>
<AssemblyName>MLEM Desktop Demos</AssemblyName> <AssemblyName>MLEM Desktop Demos</AssemblyName>
<RootNamespace>Demos.DesktopGL</RootNamespace> <RootNamespace>Demos.DesktopGL</RootNamespace>

View file

@ -1,31 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<ApplicationIcon>Icon.ico</ApplicationIcon> <ApplicationIcon>Icon.ico</ApplicationIcon>
<AssemblyName>MLEM Desktop Demos</AssemblyName> <AssemblyName>MLEM Desktop Demos</AssemblyName>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.263" /> <PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.263" />
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.263" /> <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.263" />
<ProjectReference Include="..\Demos\Demos.csproj" /> <ProjectReference Include="..\Demos\Demos.csproj" />
<ProjectReference Include="..\MLEM.Startup\MLEM.Startup.csproj" /> <ProjectReference Include="..\MLEM.Startup\MLEM.Startup.csproj" />
<ProjectReference Include="..\MLEM.Ui\MLEM.Ui.csproj" /> <ProjectReference Include="..\MLEM.Ui\MLEM.Ui.csproj" />
<ProjectReference Include="..\MLEM\MLEM.csproj" /> <ProjectReference Include="..\MLEM\MLEM.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<MonoGameContentReference Include="..\Demos\Content\Content.mgcb" /> <MonoGameContentReference Include="..\Demos\Content\Content.mgcb" />
<EmbeddedResource Include="Icon.ico" /> <EmbeddedResource Include="Icon.ico" />
<EmbeddedResource Include="Icon.bmp" /> <EmbeddedResource Include="Icon.bmp" />
</ItemGroup> </ItemGroup>
<Target Name="RestoreDotnetTools" BeforeTargets="Restore"> <Target Name="RestoreDotnetTools" BeforeTargets="Restore">
<Message Text="Restoring dotnet tools" Importance="High" /> <Message Text="Restoring dotnet tools" Importance="High" />
<Exec Command="dotnet tool restore" /> <Exec Command="dotnet tool restore" />

View file

@ -1,20 +1,20 @@
using System; using MLEM.Misc;
using Microsoft.Xna.Framework; #if FNA
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using MLEM.Misc; #endif
namespace Demos.DesktopGL { namespace Demos.DesktopGL;
public static class Program {
public static void Main() { public static class Program {
#if FNA
MlemPlatform.Current = new MlemPlatform.DesktopFna(a => TextInputEXT.TextInput += a);
#else
MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
#endif
using var game = new GameImpl();
game.Run();
}
public static void Main() {
#if FNA
MlemPlatform.Current = new MlemPlatform.DesktopFna(a => TextInputEXT.TextInput += a);
#else
MlemPlatform.Current = new MlemPlatform.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
#endif
using var game = new GameImpl();
game.Run();
} }
} }

View file

@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\MLEM.Startup\MLEM.Startup.csproj" /> <ProjectReference Include="..\MLEM.Startup\MLEM.Startup.csproj" />
<ProjectReference Include="..\MLEM.Ui\MLEM.Ui.csproj" /> <ProjectReference Include="..\MLEM.Ui\MLEM.Ui.csproj" />
<ProjectReference Include="..\MLEM\MLEM.csproj" /> <ProjectReference Include="..\MLEM\MLEM.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.263"> <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>

View file

@ -43,7 +43,7 @@ namespace Demos {
this.GraphicsDevice.Clear(Color.CornflowerBlue); this.GraphicsDevice.Clear(Color.CornflowerBlue);
base.DoDraw(time); 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; var view = this.GraphicsDevice.Viewport;
// graph the easing function // graph the easing function

View file

@ -9,9 +9,6 @@ using MLEM.Textures;
using MLEM.Ui; using MLEM.Ui;
using MLEM.Ui.Elements; using MLEM.Ui.Elements;
using MLEM.Ui.Style; using MLEM.Ui.Style;
#if !FNA
using MonoGame.Framework.Utilities;
#endif
namespace Demos { namespace Demos {
public class GameImpl : MlemGame { public class GameImpl : MlemGame {

View file

@ -50,7 +50,7 @@ namespace Demos {
public override void DoDraw(GameTime time) { public override void DoDraw(GameTime time) {
this.GraphicsDevice.Clear(Color.DarkSlateGray); 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 // 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 // since the text is already center-aligned, we only need to align it on the y axis here

2
FNA

@ -1 +1 @@
Subproject commit 31ff5cd8b6d62b0c10b627c67cc66db1d4def4e7 Subproject commit dfa9ce8cfd46846ad1df81283e84cfe5cee4faca

View file

@ -13,22 +13,21 @@ namespace MLEM.Data.Content {
if (existing != null) { if (existing != null) {
existing.Reload(stream); existing.Reload(stream);
return existing; return existing;
} else }
#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)) {
var ret = new Texture2D(manager.GraphicsDevice, texture.Width, texture.Height); var ret = new Texture2D(manager.GraphicsDevice, texture.Width, texture.Height);
using (var textureData = texture.GetTextureData()) { using (var textureData = texture.GetTextureData()) {
using (var retData = ret.GetTextureData()) { using (var retData = ret.GetTextureData()) {
for (var x = 0; x < ret.Width; x++) { for (var x = 0; x < ret.Width; x++) {
for (var y = 0; y < ret.Height; y++) for (var y = 0; y < ret.Height; y++)
retData[x, y] = Color.FromNonPremultiplied(textureData[x, y].ToVector4()); retData[x, y] = Color.FromNonPremultiplied(textureData[x, y].ToVector4());
}
} }
} }
return ret;
} }
return ret;
} }
} }

View file

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@ -6,8 +5,10 @@ using System.Text.RegularExpressions;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Textures; using MLEM.Textures;
#if FNA
using MLEM.Extensions;
#endif
namespace MLEM.Data { namespace MLEM.Data {
/// <summary> /// <summary>

View file

@ -267,7 +267,7 @@ namespace MLEM.Data {
srcColor = Color.Transparent; srcColor = Color.Transparent;
} else { } else {
// otherwise, we just use the closest pixel that is actually in bounds, causing the border pixels to be doubled up // 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]; srcColor = data[request.Texture.Position + src];
} }
destination[location + new Point(x, y)] = srcColor; destination[location + new Point(x, y)] = srcColor;

View file

@ -10,9 +10,9 @@ using MLEM.Extensions;
using MLEM.Graphics; using MLEM.Graphics;
using MLEM.Input; using MLEM.Input;
using MLEM.Misc; using MLEM.Misc;
using MLEM.Sound;
using MLEM.Textures; using MLEM.Textures;
using MLEM.Ui.Style; using MLEM.Ui.Style;
using SoundEffectInfo = MLEM.Sound.SoundEffectInfo;
namespace MLEM.Ui.Elements { namespace MLEM.Ui.Elements {
/// <summary> /// <summary>

View file

@ -1,11 +1,13 @@
using System; using System;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Graphics; using MLEM.Graphics;
using MLEM.Misc; using MLEM.Misc;
using MLEM.Textures; using MLEM.Textures;
using MLEM.Ui.Style; using MLEM.Ui.Style;
#if FNA
using MLEM.Extensions;
#endif
namespace MLEM.Ui.Elements { namespace MLEM.Ui.Elements {
/// <summary> /// <summary>

View file

@ -3,12 +3,14 @@ using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch; using Microsoft.Xna.Framework.Input.Touch;
using MLEM.Extensions;
using MLEM.Graphics; using MLEM.Graphics;
using MLEM.Input; using MLEM.Input;
using MLEM.Misc; using MLEM.Misc;
using MLEM.Textures; using MLEM.Textures;
using MLEM.Ui.Style; using MLEM.Ui.Style;
#if FNA
using MLEM.Extensions;
#endif
namespace MLEM.Ui.Elements { namespace MLEM.Ui.Elements {
/// <summary> /// <summary>

View file

@ -1,4 +1,3 @@
using System;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Font; using MLEM.Font;

View file

@ -1,9 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Extensions;
using MLEM.Input; using MLEM.Input;
using MLEM.Ui.Style; using MLEM.Ui.Style;
#if FNA
using MLEM.Extensions;
#endif
namespace MLEM.Ui.Elements { namespace MLEM.Ui.Elements {
/// <summary> /// <summary>

View file

@ -5,9 +5,9 @@ using MLEM.Font;
using MLEM.Formatting; using MLEM.Formatting;
using MLEM.Formatting.Codes; using MLEM.Formatting.Codes;
using MLEM.Misc; using MLEM.Misc;
using MLEM.Sound;
using MLEM.Textures; using MLEM.Textures;
using MLEM.Ui.Elements; using MLEM.Ui.Elements;
using SoundEffectInfo = MLEM.Sound.SoundEffectInfo;
namespace MLEM.Ui.Style { namespace MLEM.Ui.Style {
/// <summary> /// <summary>

View file

@ -1,5 +1,4 @@
using System; using System;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Ui.Elements; using MLEM.Ui.Elements;
namespace MLEM.Ui { namespace MLEM.Ui {

View file

@ -561,7 +561,7 @@ namespace MLEM.Ui {
/// This property returns <see langword="true"/> if <see cref="CanSelectContent"/> is <see langword="true"/> and the <see cref="Element"/> is not hidden, or if it has been set to <see langword="true"/> manually. /// This property returns <see langword="true"/> if <see cref="CanSelectContent"/> is <see langword="true"/> and the <see cref="Element"/> is not hidden, or if it has been set to <see langword="true"/> manually.
/// </summary> /// </summary>
public bool CanBeActive { public bool CanBeActive {
get => this.canBeActive || (!this.Element.IsHidden && this.CanSelectContent); get => this.canBeActive || !this.Element.IsHidden && this.CanSelectContent;
set => this.canBeActive = value; set => this.canBeActive = value;
} }

View file

@ -304,6 +304,41 @@ namespace MLEM.Extensions {
public static Vector2 ToVector2(this Point point) { public static Vector2 ToVector2(this Point point) {
return new Vector2(point.X, point.Y); return new Vector2(point.X, point.Y);
} }
/// <summary>
/// Deconstruction method for <see cref="Point"/>.
/// </summary>
/// <param name="point">The point to deconstruct.</param>
/// <param name="x"></param>
/// <param name="y"></param>
public static void Deconstruct(this Point point, out int x, out int y) {
x = point.X;
y = point.Y;
}
/// <summary>
/// Deconstruction method for <see cref="Vector2"/>.
/// </summary>
/// <param name="vector">The vector to deconstruct.</param>
/// <param name="x"></param>
/// <param name="y"></param>
public static void Deconstruct(this Vector2 vector, out float x, out float y) {
x = vector.X;
y = vector.Y;
}
/// <summary>
/// Deconstruction method for <see cref="Vector3"/>.
/// </summary>
/// <param name="vector">The vector to deconstruct.</param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
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 #endif
} }

View file

@ -1,8 +1,11 @@
using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions; using MLEM.Extensions;
#if !FNA
using System.Linq;
#endif
namespace MLEM.Font { namespace MLEM.Font {
/// <inheritdoc/> /// <inheritdoc/>
public class GenericSpriteFont : GenericFont { public class GenericSpriteFont : GenericFont {

View file

@ -88,7 +88,7 @@ namespace MLEM.Graphics {
var orig = origin ?? Vector2.Zero; var orig = origin ?? Vector2.Zero;
var sc = scale ?? Vector2.One; var sc = scale ?? Vector2.One;
var od = layerDepth + overlayDepthOffset; 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) if (backgroundTexture != null)
batch.Draw(backgroundTexture, pos, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth); batch.Draw(backgroundTexture, pos, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth);
if (r1 != Rectangle.Empty) if (r1 != Rectangle.Empty)
@ -106,7 +106,7 @@ namespace MLEM.Graphics {
var orig = origin ?? Vector2.Zero; var orig = origin ?? Vector2.Zero;
var sc = scale ?? Vector2.One; var sc = scale ?? Vector2.One;
var od = layerDepth + overlayDepthOffset; 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) { if (backgroundTexture != null) {
var background = batch.Add(backgroundTexture, pos, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth); var background = batch.Add(backgroundTexture, pos, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth);
items?.Add(background); 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)); 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 up = connectsTo(0, -1);
var down = connectsTo(0, 1); var down = connectsTo(0, 1);
var left = connectsTo(-1, 0); var left = connectsTo(-1, 0);

View file

@ -1,10 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
#if FNA
using MLEM.Extensions; using MLEM.Extensions;
using System.IO;
#endif
namespace MLEM.Graphics { namespace MLEM.Graphics {
/// <summary> /// <summary>

View file

@ -73,7 +73,7 @@ namespace MLEM.Input {
/// </summary> /// </summary>
public bool InvertPressBehavior; public bool InvertPressBehavior;
/// <summary> /// <summary>
/// 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 <see cref="GestureSample"/> objects can only be retrieved once and are then removed from the <see cref="TouchPanelState"/>'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 <see cref="GestureSample"/> objects can only be retrieved once and are then removed from the <see cref="TouchPanel"/>'s queue.
/// If this value is set to true, but you still want to be able to use <see cref="Gestures"/>, <see cref="GetGesture"/>, and <see cref="GetViewportGesture"/>, you can make this input handler aware of a gesture for the duration of the update frame that you added it on by using <see cref="AddExternalGesture"/>. /// If this value is set to true, but you still want to be able to use <see cref="Gestures"/>, <see cref="GetGesture"/>, and <see cref="GetViewportGesture"/>, you can make this input handler aware of a gesture for the duration of the update frame that you added it on by using <see cref="AddExternalGesture"/>.
/// For more info, see https://mlem.ellpeck.de/articles/input.html#external-gesture-handling. /// For more info, see https://mlem.ellpeck.de/articles/input.html#external-gesture-handling.
/// </summary> /// </summary>

View file

@ -31,7 +31,7 @@ public class GameImpl : MlemGame {
public GameImpl() { public GameImpl() {
this.IsMouseVisible = true; this.IsMouseVisible = true;
this.Window.ClientSizeChanged += (o, args) => { this.Window.ClientSizeChanged += (_, _) => {
Console.WriteLine("Size changed"); Console.WriteLine("Size changed");
}; };
} }
@ -121,7 +121,7 @@ public class GameImpl : MlemGame {
var res = this.Content.LoadJson<Test>("Test"); var res = this.Content.LoadJson<Test>("Test");
Console.WriteLine("The res is " + res); 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.OnDraw += (game, time) => {
this.SpriteBatch.Begin(); this.SpriteBatch.Begin();
this.SpriteBatch.Draw(this.SpriteBatch.GetBlankTexture(), new Rectangle(640 - 4, 360 - 4, 8, 8), Color.Green); 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 sc = 4;
var formatter = new TextFormatter(); var formatter = new TextFormatter();
formatter.AddImage("Test", new TextureRegion(tex, 0, 8, 24, 24)); formatter.AddImage("Test", new TextureRegion(tex, 0, 8, 24, 24));
formatter.Macros.Add(new Regex("<testmacro>"), (f, m, r) => "<test1>"); formatter.Macros.Add(new Regex("<testmacro>"), (_, _, _) => "<test1>");
formatter.Macros.Add(new Regex("<test1>"), (f, m, r) => "<test2> blue"); formatter.Macros.Add(new Regex("<test1>"), (_, _, _) => "<test2> blue");
formatter.Macros.Add(new Regex("<test2>"), (f, m, r) => "<c Blue>"); formatter.Macros.Add(new Regex("<test2>"), (_, _, _) => "<c Blue>");
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 <testmacro> text</c>."; 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 <testmacro> text</c>.";
//var strg = "Lorem Ipsum <i Test> is simply dummy text of the <i Test> printing and typesetting <i Test> industry. Lorem Ipsum has been the industry's standard dummy text <i Test> ever since the <i Test> 1500s, when <i Test><i Test><i Test><i Test><i Test><i Test><i Test> 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 <i Test> is simply dummy text of the <i Test> printing and typesetting <i Test> industry. Lorem Ipsum has been the industry's standard dummy text <i Test> ever since the <i Test> 1500s, when <i Test><i Test><i Test><i Test><i Test><i Test><i Test> 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."; //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 = formatter.Tokenize(font, strg);
this.tokenized.Split(font, 400, sc); 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 round = this.SpriteBatch.GenerateCircleTexture(Color.Green, 128);
var region = new TextureRegion(round) {Pivot = new Vector2(0.5F)}; var region = new TextureRegion(round) {Pivot = new Vector2(0.5F)};
@ -159,7 +159,7 @@ public class GameImpl : MlemGame {
foreach (var r in atlas.Regions) foreach (var r in atlas.Regions)
Console.WriteLine(r.Name + ": " + r.U + " " + r.V + " " + r.Width + " " + r.Height + " " + r.PivotPixels); 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.Begin(samplerState: SamplerState.PointClamp);
//this.SpriteBatch.Draw(square, new Rectangle(10, 10, 400, 400), Color.White); //this.SpriteBatch.Draw(square, new Rectangle(10, 10, 400, 400), Color.White);
//this.SpriteBatch.Draw(round, 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.DrawGrid(new Vector2(30, 30), new Vector2(40, 60), new Point(10, 5), Color.Yellow, 3);
this.SpriteBatch.End(); this.SpriteBatch.End();
}; };
this.OnUpdate += (g, time) => { this.OnUpdate += (_, time) => {
if (this.InputHandler.IsPressed(Keys.W)) { if (this.InputHandler.IsPressed(Keys.W)) {
this.tokenized = formatter.Tokenize(font, strg); this.tokenized = formatter.Tokenize(font, strg);
this.tokenized.Split(font, this.InputHandler.IsModifierKeyDown(ModifierKey.Shift) ? 400 : 500, sc); this.tokenized.Split(font, this.InputHandler.IsModifierKeyDown(ModifierKey.Shift) ? 400 : 500, sc);
@ -259,7 +259,7 @@ public class GameImpl : MlemGame {
var rotation = 0F; var rotation = 0F;
var effects = SpriteEffects.None; 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."; 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)) { if (MlemGame.Input.IsKeyPressed(Keys.I)) {
index++; index++;
@ -335,15 +335,16 @@ public class GameImpl : MlemGame {
};*/ };*/
var widthPanel = new Panel(Anchor.Center, Vector2.One, Vector2.Zero, true) {SetWidthBasedOnChildren = true}; 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) { widthPanel.AddChild(new Paragraph(Anchor.AutoCenter, 100000, "Test String " + Math.Pow(10, i), true) {
OnUpdated = (e, time) => { OnUpdated = (e, _) => {
if (Input.IsPressed(Keys.A)) { if (MlemGame.Input.IsPressed(Keys.A)) {
e.Anchor = (Anchor) (((int) e.Anchor + 1) % EnumHelper.GetValues<Anchor>().Length); e.Anchor = (Anchor) (((int) e.Anchor + 1) % EnumHelper.GetValues<Anchor>().Length);
Console.WriteLine(e.Anchor); Console.WriteLine(e.Anchor);
} }
} }
}); });
}
this.UiSystem.Add("WidthTest", widthPanel); this.UiSystem.Add("WidthTest", widthPanel);
} }

View file

@ -1,7 +1,6 @@
using Microsoft.Xna.Framework; using MLEM.Misc;
using MLEM.Misc;
namespace Sandbox; namespace Sandbox;
internal static class Program { internal static class Program {
@ -11,4 +10,4 @@ internal static class Program {
game.Run(); game.Run();
} }
} }

View file

@ -12,11 +12,11 @@ using Vector2 = Microsoft.Xna.Framework.Vector2;
namespace Tests { namespace Tests {
public class DataTests { public class DataTests {
private readonly TestObject testObject = new(Vector2.One, "test") { private readonly TestObject testObject = new() {
Vec = new Vector2(10, 20), Vec = new Vector2(10, 20),
Point = new Point(20, 30), Point = new Point(20, 30),
Dir = Direction2.Left, Dir = Direction2.Left,
OtherTest = new TestObject(Vector2.One, "other") { OtherTest = new TestObject {
Vec = new Vector2(70, 30), Vec = new Vector2(70, 30),
Dir = Direction2.Right Dir = Direction2.Right
} }
@ -95,8 +95,6 @@ namespace Tests {
public Direction2 Dir { get; set; } public Direction2 Dir { get; set; }
public TestObject OtherTest; public TestObject OtherTest;
public TestObject(Vector2 test, string test2) {}
protected bool Equals(TestObject other) { 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; return this.Vec.Equals(other.Vec) && this.Point.Equals(other.Point) && object.Equals(this.OtherTest, other.OtherTest) && this.Dir == other.Dir;
} }

View file

@ -102,16 +102,16 @@ namespace Tests {
[Test] [Test]
public void TestMacros() { public void TestMacros() {
this.formatter.Macros.Add(new Regex("<testmacro>"), (f, m, r) => "<test1>"); this.formatter.Macros.Add(new Regex("<testmacro>"), (_, _, _) => "<test1>");
this.formatter.Macros.Add(new Regex("<test1>"), (f, m, r) => "<test2>blue"); this.formatter.Macros.Add(new Regex("<test1>"), (_, _, _) => "<test2>blue");
this.formatter.Macros.Add(new Regex("<test2>"), (f, m, r) => "<c Blue>"); this.formatter.Macros.Add(new Regex("<test2>"), (_, _, _) => "<c Blue>");
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 <testmacro> text</c>."; 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 <testmacro> text</c>.";
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 <c Blue>blue text</c>."; 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 <c Blue>blue text</c>.";
Assert.AreEqual(this.formatter.ResolveMacros(strg), goal); Assert.AreEqual(this.formatter.ResolveMacros(strg), goal);
// test recursive macros // test recursive macros
this.formatter.Macros.Add(new Regex("<rec1>"), (f, m, r) => "<rec2>"); this.formatter.Macros.Add(new Regex("<rec1>"), (_, _, _) => "<rec2>");
this.formatter.Macros.Add(new Regex("<rec2>"), (f, m, r) => "<rec1>"); this.formatter.Macros.Add(new Regex("<rec2>"), (_, _, _) => "<rec1>");
Assert.Throws<ArithmeticException>(() => this.formatter.ResolveMacros("Test <rec1> string")); Assert.Throws<ArithmeticException>(() => this.formatter.ResolveMacros("Test <rec1> string"));
} }

View file

@ -66,7 +66,7 @@ namespace Tests {
'X' => float.PositiveInfinity, 'X' => float.PositiveInfinity,
_ => (float) char.GetNumericValue(c) _ => (float) char.GetNumericValue(c)
}).ToArray()).ToArray(); }).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); return pathFinder.FindPath(start, end);
} }

View file

@ -122,12 +122,12 @@ namespace Tests {
for (var i = 1; i <= 100; i++) { for (var i = 1; i <= 100; i++) {
var totalUpdates = 0; var totalUpdates = 0;
var main = new Group(Anchor.TopLeft, new Vector2(50)) { var main = new Group(Anchor.TopLeft, new Vector2(50)) {
OnAreaUpdated = e => totalUpdates++ OnAreaUpdated = _ => totalUpdates++
}; };
var group = main; var group = main;
for (var g = 0; g < i; g++) { for (var g = 0; g < i; g++) {
group = group.AddChild(new Group(Anchor.TopLeft, Vector2.One) { group = group.AddChild(new Group(Anchor.TopLeft, Vector2.One) {
OnAreaUpdated = e => totalUpdates++ OnAreaUpdated = _ => totalUpdates++
}); });
} }
stopwatch.Restart(); stopwatch.Restart();