1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

code cleanup

This commit is contained in:
Ellpeck 2020-06-18 17:24:35 +02:00
parent 71dabe7360
commit deec553b22
43 changed files with 52 additions and 104 deletions

View file

@ -1,7 +1,5 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Android.App;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information

View file

@ -55,17 +55,19 @@ namespace Demos {
var x1 = x; var x1 = x;
var y1 = y; var y1 = y;
// the connectsTo function determines for any given tile if it should connect to, that is, auto-tile with the // the connectsTo function determines for any given tile if it should connect to, that is, auto-tile with the
// neighbor in the supplied offset direction. In this example, the layout determines where grass tiles are (X) // neighbor in the supplied offset direction. In this example, the layout determines where grass tiles are (X)
// and where there are none ( ). // and where there are none ( ).
AutoTiling.ConnectsTo connectsTo = (xOff, yOff) => { bool ConnectsTo(int xOff, int yOff) {
// don't auto-tile out of bounds // don't auto-tile out of bounds
if (x1 + xOff < 0 || y1 + yOff < 0 || x1 + xOff >= 5 || y1 + yOff >= 5) if (x1 + xOff < 0 || y1 + yOff < 0 || x1 + xOff >= 5 || y1 + yOff >= 5)
return false; return false;
// check if the neighboring tile is also grass (X) // check if the neighboring tile is also grass (X)
return this.layout[y1 + yOff][x1 + xOff] == 'X'; return this.layout[y1 + yOff][x1 + xOff] == 'X';
}; }
AutoTiling.DrawAutoTile(this.SpriteBatch, new Vector2(x, y) * tileSize, this.texture, region, connectsTo, Color.White);
AutoTiling.DrawAutoTile(this.SpriteBatch, new Vector2(x, y) * tileSize, this.texture, region, ConnectsTo, Color.White);
} }
} }
this.SpriteBatch.End(); this.SpriteBatch.End();

View file

@ -40,7 +40,7 @@ namespace Demos {
PanelTexture = new NinePatch(new TextureRegion(tex, 0, 8, 24, 24), 8), PanelTexture = new NinePatch(new TextureRegion(tex, 0, 8, 24, 24), 8),
ButtonTexture = new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4), ButtonTexture = new NinePatch(new TextureRegion(tex, 24, 8, 16, 16), 4),
ScrollBarBackground = new NinePatch(new TextureRegion(tex, 12, 0, 4, 8), 1, 1, 2, 2), ScrollBarBackground = new NinePatch(new TextureRegion(tex, 12, 0, 4, 8), 1, 1, 2, 2),
ScrollBarScrollerTexture = new NinePatch(new TextureRegion(tex, 8, 0, 4, 8), 1, 1, 2, 2), ScrollBarScrollerTexture = new NinePatch(new TextureRegion(tex, 8, 0, 4, 8), 1, 1, 2, 2)
}; };
this.UiSystem.AutoScaleReferenceSize = new Point(1280, 720); this.UiSystem.AutoScaleReferenceSize = new Point(1280, 720);
this.UiSystem.AutoScaleWithScreen = true; this.UiSystem.AutoScaleWithScreen = true;

View file

@ -8,7 +8,6 @@ using MLEM.Input;
using MLEM.Misc; using MLEM.Misc;
using MLEM.Pathfinding; using MLEM.Pathfinding;
using MLEM.Startup; using MLEM.Startup;
using MLEM.Textures;
namespace Demos { namespace Demos {
public class PathfindingDemo : Demo { public class PathfindingDemo : Demo {
@ -39,14 +38,15 @@ namespace Demos {
// If your game contains harder-to-move-on areas like, say, a muddy pit, you can return a higher cost value for those // If your game contains harder-to-move-on areas like, say, a muddy pit, you can return a higher cost value for those
// locations. If you want to scale your cost function differently, you can specify a different default cost in your // locations. If you want to scale your cost function differently, you can specify a different default cost in your
// pathfinder's constructor // pathfinder's constructor
AStar<Point>.GetCost cost = (pos, nextPos) => { float Cost(Point pos, Point nextPos) {
if (nextPos.X < 0 || nextPos.Y < 0 || nextPos.X >= 50 || nextPos.Y >= 50) if (nextPos.X < 0 || nextPos.Y < 0 || nextPos.X >= 50 || nextPos.Y >= 50)
return float.MaxValue; return float.MaxValue;
return this.world[nextPos.X, nextPos.Y] ? 1 : float.MaxValue; return this.world[nextPos.X, nextPos.Y] ? 1 : float.MaxValue;
}; }
// Actually initialize the pathfinder with the cost function, as well as specify if moving diagonally between tiles should be // Actually initialize the pathfinder with the cost function, as well as specify if moving diagonally between tiles should be
// allowed or not (in this case it's not) // allowed or not (in this case it's not)
this.pathfinder = new AStar2(cost, false); this.pathfinder = new AStar2(Cost, false);
// Now find a path from the top left to the bottom right corner and store it in a variable // Now find a path from the top left to the bottom right corner and store it in a variable
// If no path can be found after the maximum amount of tries (10000 by default), the pathfinder will abort and return no path (null) // If no path can be found after the maximum amount of tries (10000 by default), the pathfinder will abort and return no path (null)

View file

@ -4,12 +4,9 @@ using System.Linq;
using Coroutine; using Coroutine;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Animations;
using MLEM.Extensions; using MLEM.Extensions;
using MLEM.Font; using MLEM.Font;
using MLEM.Formatting;
using MLEM.Formatting.Codes; using MLEM.Formatting.Codes;
using MLEM.Input;
using MLEM.Misc; using MLEM.Misc;
using MLEM.Startup; using MLEM.Startup;
using MLEM.Textures; using MLEM.Textures;
@ -143,7 +140,7 @@ namespace Demos {
// Check the WobbleButton method for an explanation of how this button works // Check the WobbleButton method for an explanation of how this button works
var group = this.root.AddChild(new CustomDrawGroup(Anchor.AutoLeft, new Vector2(1, 0))); var group = this.root.AddChild(new CustomDrawGroup(Anchor.AutoLeft, new Vector2(1, 0)));
group.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.5F, 10), "Wobble Me", "This button wobbles around visually when clicked, but this doesn't affect its actual size and positioning") { group.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.5F, 10), "Wobble Me", "This button wobbles around visually when clicked, but this doesn't affect its actual size and positioning") {
OnPressed = element => CoroutineHandler.Start(this.WobbleButton(group)), OnPressed = element => CoroutineHandler.Start(WobbleButton(group)),
PositionOffset = new Vector2(0, 1) PositionOffset = new Vector2(0, 1)
}); });
this.root.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.5F, 10), "Transform Ui", "This button causes the entire ui to be transformed (both in positioning, rotation and scale)") { this.root.AddChild(new Button(Anchor.AutoCenter, new Vector2(0.5F, 10), "Transform Ui", "This button causes the entire ui to be transformed (both in positioning, rotation and scale)") {
@ -160,13 +157,13 @@ namespace Demos {
this.root.AddChild(new VerticalSpace(3)); this.root.AddChild(new VerticalSpace(3));
this.root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "Progress bars!")); this.root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "Progress bars!"));
var bar1 = this.root.AddChild(new ProgressBar(Anchor.AutoLeft, new Vector2(1, 8), Direction2.Right, 10) {PositionOffset = new Vector2(0, 1)}); var bar1 = this.root.AddChild(new ProgressBar(Anchor.AutoLeft, new Vector2(1, 8), Direction2.Right, 10) {PositionOffset = new Vector2(0, 1)});
CoroutineHandler.Start(this.WobbleProgressBar(bar1)); CoroutineHandler.Start(WobbleProgressBar(bar1));
var bar2 = this.root.AddChild(new ProgressBar(Anchor.AutoLeft, new Vector2(1, 8), Direction2.Left, 10) {PositionOffset = new Vector2(0, 1)}); var bar2 = this.root.AddChild(new ProgressBar(Anchor.AutoLeft, new Vector2(1, 8), Direction2.Left, 10) {PositionOffset = new Vector2(0, 1)});
CoroutineHandler.Start(this.WobbleProgressBar(bar2)); CoroutineHandler.Start(WobbleProgressBar(bar2));
var bar3 = this.root.AddChild(new ProgressBar(Anchor.AutoLeft, new Vector2(8, 30), Direction2.Down, 10) {PositionOffset = new Vector2(0, 1)}); var bar3 = this.root.AddChild(new ProgressBar(Anchor.AutoLeft, new Vector2(8, 30), Direction2.Down, 10) {PositionOffset = new Vector2(0, 1)});
CoroutineHandler.Start(this.WobbleProgressBar(bar3)); CoroutineHandler.Start(WobbleProgressBar(bar3));
var bar4 = this.root.AddChild(new ProgressBar(Anchor.AutoInline, new Vector2(8, 30), Direction2.Up, 10) {PositionOffset = new Vector2(1, 1)}); var bar4 = this.root.AddChild(new ProgressBar(Anchor.AutoInline, new Vector2(8, 30), Direction2.Up, 10) {PositionOffset = new Vector2(1, 1)});
CoroutineHandler.Start(this.WobbleProgressBar(bar4)); CoroutineHandler.Start(WobbleProgressBar(bar4));
this.root.AddChild(new VerticalSpace(3)); this.root.AddChild(new VerticalSpace(3));
var dropdown = this.root.AddChild(new Dropdown(Anchor.AutoLeft, new Vector2(1, 10), "Dropdown Menu")); var dropdown = this.root.AddChild(new Dropdown(Anchor.AutoLeft, new Vector2(1, 10), "Dropdown Menu"));
@ -203,7 +200,7 @@ namespace Demos {
// This method is used by the wobbling button (see above) // This method is used by the wobbling button (see above)
// Note that this particular example makes use of the Coroutine package, which is not required but makes demonstration easier // Note that this particular example makes use of the Coroutine package, which is not required but makes demonstration easier
private IEnumerator<Wait> WobbleButton(CustomDrawGroup group) { private static IEnumerator<Wait> WobbleButton(CustomDrawGroup group) {
var counter = 0F; var counter = 0F;
while (counter < 4 * Math.PI) { while (counter < 4 * Math.PI) {
// A custom draw group allows the implementation of any sort of custom rendering for all of its child components // A custom draw group allows the implementation of any sort of custom rendering for all of its child components
@ -219,7 +216,7 @@ namespace Demos {
group.Transform = Matrix.Identity; group.Transform = Matrix.Identity;
} }
private IEnumerator<Wait> WobbleProgressBar(ProgressBar bar) { private static IEnumerator<Wait> WobbleProgressBar(ProgressBar bar) {
var reducing = false; var reducing = false;
while (bar.Root != null) { while (bar.Root != null) {
if (reducing) { if (reducing) {

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace MLEM.Data.Json { namespace MLEM.Data.Json {

View file

@ -1,9 +1,7 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions; using MLEM.Extensions;
using MLEM.Textures;
using MonoGame.Extended; using MonoGame.Extended;
using MonoGame.Extended.BitmapFonts;
namespace MLEM.Extended.Extensions { namespace MLEM.Extended.Extensions {
/// <summary> /// <summary>

View file

@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Text; using System.Text;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extended.Extensions;
using MLEM.Font; using MLEM.Font;
using MonoGame.Extended.BitmapFonts; using MonoGame.Extended.BitmapFonts;

View file

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Extensions; using MLEM.Extensions;

View file

@ -2,7 +2,6 @@ using Coroutine;
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 Microsoft.Xna.Framework.Input;
using MLEM.Input; using MLEM.Input;
using MLEM.Ui; using MLEM.Ui;
using MLEM.Ui.Style; using MLEM.Ui.Style;

View file

@ -1,6 +1,5 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Textures; using MLEM.Textures;
using MLEM.Ui.Style; using MLEM.Ui.Style;

View file

@ -1,7 +1,5 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Input;
using MLEM.Misc; using MLEM.Misc;
using MLEM.Textures; using MLEM.Textures;
using MLEM.Ui.Style; using MLEM.Ui.Style;

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;

View file

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;

View file

@ -1,5 +1,4 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Input;
using MLEM.Textures; using MLEM.Textures;
namespace MLEM.Ui.Elements { namespace MLEM.Ui.Elements {
@ -91,7 +90,7 @@ namespace MLEM.Ui.Elements {
var upButton = new Button(Anchor.TopRight, Vector2.One, "+") { var upButton = new Button(Anchor.TopRight, Vector2.One, "+") {
OnPressed = element => { OnPressed = element => {
var text = field.Text.ToString(); var text = field.Text;
if (int.TryParse(text, out var val)) if (int.TryParse(text, out var val))
field.SetText(val + stepPerClick); field.SetText(val + stepPerClick);
} }
@ -101,7 +100,7 @@ namespace MLEM.Ui.Elements {
var downButton = new Button(Anchor.BottomRight, Vector2.One, "-") { var downButton = new Button(Anchor.BottomRight, Vector2.One, "-") {
OnPressed = element => { OnPressed = element => {
var text = field.Text.ToString(); var text = field.Text;
if (int.TryParse(text, out var val)) if (int.TryParse(text, out var val))
field.SetText(val - stepPerClick); field.SetText(val - stepPerClick);
} }

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;

View file

@ -1,17 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
using MLEM.Font; using MLEM.Font;
using MLEM.Formatting; using MLEM.Formatting;
using MLEM.Formatting.Codes; using MLEM.Formatting.Codes;
using MLEM.Input;
using MLEM.Misc; using MLEM.Misc;
using MLEM.Textures;
using MLEM.Ui.Style; using MLEM.Ui.Style;
namespace MLEM.Ui.Elements { namespace MLEM.Ui.Elements {

View file

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

View file

@ -1,6 +1,4 @@
using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using MLEM.Misc; using MLEM.Misc;
namespace MLEM.Ui.Elements { namespace MLEM.Ui.Elements {

View file

@ -1,6 +1,5 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Animations; using MLEM.Animations;
using MLEM.Textures;
namespace MLEM.Ui.Elements { namespace MLEM.Ui.Elements {
/// <summary> /// <summary>

View file

@ -1,7 +1,5 @@
using System; using System;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Extensions;
using MLEM.Font;
using MLEM.Ui.Style; using MLEM.Ui.Style;
namespace MLEM.Ui.Elements { namespace MLEM.Ui.Elements {

View file

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

View file

@ -1,10 +1,8 @@
using System.Collections.Generic;
using System.Text; using System.Text;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions; using MLEM.Extensions;
using MLEM.Font; using MLEM.Font;
using MLEM.Textures;
namespace MLEM.Ui.Style { namespace MLEM.Ui.Style {
/// <summary> /// <summary>

View file

@ -1,10 +1,8 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch; using Microsoft.Xna.Framework.Input.Touch;
using MLEM.Extensions;
using MLEM.Input; using MLEM.Input;
using MLEM.Misc; using MLEM.Misc;
using MLEM.Ui.Elements; using MLEM.Ui.Elements;

View file

@ -5,9 +5,7 @@ using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MLEM.Extensions; using MLEM.Extensions;
using MLEM.Font;
using MLEM.Formatting; using MLEM.Formatting;
using MLEM.Formatting.Codes; using MLEM.Formatting.Codes;
using MLEM.Input; using MLEM.Input;

View file

@ -10,7 +10,7 @@ namespace MLEM.Animations {
/// </summary> /// </summary>
public class SpriteAnimation : GenericDataHolder { public class SpriteAnimation : GenericDataHolder {
private AnimationFrame[] frames; private readonly AnimationFrame[] frames;
/// <summary> /// <summary>
/// Returns the <see cref="AnimationFrame"/> at the given index. /// Returns the <see cref="AnimationFrame"/> at the given index.
/// Index ordering is based on the order that animation frames were added in. /// Index ordering is based on the order that animation frames were added in.

View file

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
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;

View file

@ -1,4 +1,3 @@
using System;
using System.IO; using System.IO;
using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Audio;

View file

@ -1,5 +1,4 @@
using System; using System;
using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
@ -79,7 +78,7 @@ namespace MLEM.Extensions {
/// Represents a context in which a <see cref="RenderTarget2D"/> is applied. /// Represents a context in which a <see cref="RenderTarget2D"/> is applied.
/// This class should be used with <see cref="GraphicsExtensions.WithRenderTarget"/>. /// This class should be used with <see cref="GraphicsExtensions.WithRenderTarget"/>.
/// </summary> /// </summary>
public struct TargetContext : IDisposable { public readonly struct TargetContext : IDisposable {
private readonly GraphicsDevice device; private readonly GraphicsDevice device;
private readonly RenderTargetBinding[] lastTargets; private readonly RenderTargetBinding[] lastTargets;

View file

@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text; using System.Text;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;

View file

@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.Text; using System.Text;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Extensions;
namespace MLEM.Font { namespace MLEM.Font {
/// <inheritdoc/> /// <inheritdoc/>

View file

@ -1,4 +1,3 @@
using System;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;

View file

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;

View file

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;

View file

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;

View file

@ -10,7 +10,7 @@ namespace MLEM.Input {
/// Note that this type is serializable using <see cref="DataContractAttribute"/>. /// Note that this type is serializable using <see cref="DataContractAttribute"/>.
/// </summary> /// </summary>
[DataContract] [DataContract]
public struct GenericInput { public readonly struct GenericInput {
/// <summary> /// <summary>
/// The <see cref="InputType"/> of this generic input's current <see cref="value"/>. /// The <see cref="InputType"/> of this generic input's current <see cref="value"/>.

View file

@ -5,7 +5,6 @@ using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch; using Microsoft.Xna.Framework.Input.Touch;
using MLEM.Extensions;
using MLEM.Misc; using MLEM.Misc;
namespace MLEM.Input { namespace MLEM.Input {
@ -433,13 +432,16 @@ namespace MLEM.Input {
/// <returns>Whether the given control is down</returns> /// <returns>Whether the given control is down</returns>
/// <exception cref="ArgumentException">If the passed control isn't of a supported type</exception> /// <exception cref="ArgumentException">If the passed control isn't of a supported type</exception>
public bool IsDown(GenericInput control, int index = -1) { public bool IsDown(GenericInput control, int index = -1) {
if (control.Type == GenericInput.InputType.Keyboard) switch (control.Type) {
return this.IsKeyDown(control); case GenericInput.InputType.Keyboard:
if (control.Type == GenericInput.InputType.Gamepad) return this.IsKeyDown(control);
return this.IsGamepadButtonDown(control, index); case GenericInput.InputType.Gamepad:
if (control.Type == GenericInput.InputType.Mouse) return this.IsGamepadButtonDown(control, index);
return this.IsMouseButtonDown(control); case GenericInput.InputType.Mouse:
throw new ArgumentException(nameof(control)); return this.IsMouseButtonDown(control);
default:
throw new ArgumentException(nameof(control));
}
} }
/// <summary> /// <summary>
@ -451,13 +453,16 @@ namespace MLEM.Input {
/// <returns>Whether the given control is down</returns> /// <returns>Whether the given control is down</returns>
/// <exception cref="ArgumentException">If the passed control isn't of a supported type</exception> /// <exception cref="ArgumentException">If the passed control isn't of a supported type</exception>
public bool IsUp(GenericInput control, int index = -1) { public bool IsUp(GenericInput control, int index = -1) {
if (control.Type == GenericInput.InputType.Keyboard) switch (control.Type) {
return this.IsKeyUp(control); case GenericInput.InputType.Keyboard:
if (control.Type == GenericInput.InputType.Gamepad) return this.IsKeyUp(control);
return this.IsGamepadButtonUp(control, index); case GenericInput.InputType.Gamepad:
if (control.Type == GenericInput.InputType.Mouse) return this.IsGamepadButtonUp(control, index);
return this.IsMouseButtonUp(control); case GenericInput.InputType.Mouse:
throw new ArgumentException(nameof(control)); return this.IsMouseButtonUp(control);
default:
throw new ArgumentException(nameof(control));
}
} }
/// <summary> /// <summary>
@ -469,13 +474,16 @@ namespace MLEM.Input {
/// <returns>Whether the given control is down</returns> /// <returns>Whether the given control is down</returns>
/// <exception cref="ArgumentException">If the passed control isn't of a supported type</exception> /// <exception cref="ArgumentException">If the passed control isn't of a supported type</exception>
public bool IsPressed(GenericInput control, int index = -1) { public bool IsPressed(GenericInput control, int index = -1) {
if (control.Type == GenericInput.InputType.Keyboard) switch (control.Type) {
return this.IsKeyPressed(control); case GenericInput.InputType.Keyboard:
if (control.Type == GenericInput.InputType.Gamepad) return this.IsKeyPressed(control);
return this.IsGamepadButtonPressed(control, index); case GenericInput.InputType.Gamepad:
if (control.Type == GenericInput.InputType.Mouse) return this.IsGamepadButtonPressed(control, index);
return this.IsMouseButtonPressed(control); case GenericInput.InputType.Mouse:
throw new ArgumentException(nameof(control)); return this.IsMouseButtonPressed(control);
default:
throw new ArgumentException(nameof(control));
}
} }
/// <inheritdoc cref="IsDown"/> /// <inheritdoc cref="IsDown"/>

View file

@ -1,8 +1,6 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Microsoft.Xna.Framework.Input;
namespace MLEM.Input { namespace MLEM.Input {
/// <summary> /// <summary>

View file

@ -1,5 +1,4 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
namespace MLEM.Pathfinding { namespace MLEM.Pathfinding {

View file

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;

View file

@ -1,6 +1,5 @@
using System; using System;
using System.IO; using System.IO;
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; using Microsoft.Xna.Framework.Input;
@ -11,7 +10,6 @@ using MLEM.Extended.Extensions;
using MLEM.Extended.Font; using MLEM.Extended.Font;
using MLEM.Extended.Tiled; using MLEM.Extended.Tiled;
using MLEM.Extensions; using MLEM.Extensions;
using MLEM.Font;
using MLEM.Formatting; using MLEM.Formatting;
using MLEM.Formatting.Codes; using MLEM.Formatting.Codes;
using MLEM.Input; using MLEM.Input;
@ -21,10 +19,8 @@ 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;
using MonoGame.Extended;
using MonoGame.Extended.BitmapFonts; using MonoGame.Extended.BitmapFonts;
using MonoGame.Extended.Tiled; using MonoGame.Extended.Tiled;
using Newtonsoft.Json.Linq;
using RectangleF = MonoGame.Extended.RectangleF; using RectangleF = MonoGame.Extended.RectangleF;
namespace Sandbox { namespace Sandbox {