1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-28 15:28:34 +01:00

Compare commits

..

No commits in common. "b4f45ba6b5fdd67d8bf865f97d1716f79a7ec501" and "fa60b5e8b1fed4dc7d0f23632e3df5bd339d6a6a" have entirely different histories.

2 changed files with 21 additions and 35 deletions

View file

@ -20,10 +20,8 @@ Additions
- **Added the ability for formatted (tokenized) strings to be drawn with custom rotation, origin and flipping**
- Added a RectangleF.FromCorners overload that accepts points
- Added indexers and Count to SpriteAnimation and SpriteAnimationGroup
- Added a Keybind constructor that accepts a set of combinations
Improvements
- **Made the Keybind.Combinations collection a public property**
- Allow NumberExtensions.GetPoints to include bottom and right coordinates
- Allow AutoTiling overlayTextures to return null texture regions

View file

@ -20,12 +20,8 @@ namespace MLEM.Input {
private static readonly Combination[] EmptyCombinations = new Combination[0];
private static readonly GenericInput[] EmptyInputs = new GenericInput[0];
/// <summary>
/// The combinations that make up this keybind.
/// This collection can be modified using <see cref="Add(MLEM.Input.GenericInput,MLEM.Input.GenericInput[])"/>, <see cref="Remove"/>, <see cref="Clear"/>, <see cref="CopyFrom"/>, etc.
/// </summary>
[DataMember]
public Combination[] Combinations { get; private set; } = Keybind.EmptyCombinations;
private Combination[] combinations = Keybind.EmptyCombinations;
/// <summary>
/// Creates a new keybind and adds the given key and modifiers using <see cref="Add(MLEM.Input.GenericInput,MLEM.Input.GenericInput[])"/>
@ -41,14 +37,6 @@ namespace MLEM.Input {
this.Add(key, modifier);
}
/// <summary>
/// Creates a new keybind with the given <paramref name="combinations"/>.
/// </summary>
/// <param name="combinations">The combinations to initialize this keybind with.</param>
public Keybind(params Combination[] combinations) {
this.Combinations = combinations.ToArray();
}
/// <summary>
/// Creates a new keybind with no default combinations
/// </summary>
@ -70,7 +58,7 @@ namespace MLEM.Input {
/// <param name="combination">The combination to add.</param>
/// <returns>This keybind, for chaining</returns>
public Keybind Add(Combination combination) {
this.Combinations = this.Combinations.Append(combination).ToArray();
this.combinations = this.combinations.Append(combination).ToArray();
return this;
}
@ -99,7 +87,7 @@ namespace MLEM.Input {
/// <param name="combination">The combination to insert.</param>
/// <returns>This keybind, for chaining.</returns>
public Keybind Insert(int index, Combination combination) {
this.Combinations = this.Combinations.Take(index).Append(combination).Concat(this.Combinations.Skip(index)).ToArray();
this.combinations = this.combinations.Take(index).Append(combination).Concat(this.combinations.Skip(index)).ToArray();
return this;
}
@ -115,7 +103,7 @@ namespace MLEM.Input {
/// </summary>
/// <returns>This keybind, for chaining</returns>
public Keybind Clear() {
this.Combinations = Keybind.EmptyCombinations;
this.combinations = Keybind.EmptyCombinations;
return this;
}
@ -125,7 +113,7 @@ namespace MLEM.Input {
/// <param name="predicate">The predicate to match against</param>
/// <returns>This keybind, for chaining</returns>
public Keybind Remove(Func<Combination, int, bool> predicate) {
this.Combinations = this.Combinations.Where((c, i) => !predicate(c, i)).ToArray();
this.combinations = this.combinations.Where((c, i) => !predicate(c, i)).ToArray();
return this;
}
@ -136,7 +124,7 @@ namespace MLEM.Input {
/// <param name="other">The keybind to copy from</param>
/// <returns>This keybind, for chaining</returns>
public Keybind CopyFrom(Keybind other) {
this.Combinations = this.Combinations.Concat(other.Combinations).ToArray();
this.combinations = this.combinations.Concat(other.combinations).ToArray();
return this;
}
@ -148,7 +136,7 @@ namespace MLEM.Input {
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
/// <returns>Whether this keybind is considered to be down</returns>
public bool IsDown(InputHandler handler, int gamepadIndex = -1) {
foreach (var combination in this.Combinations) {
foreach (var combination in this.combinations) {
if (combination.IsDown(handler, gamepadIndex))
return true;
}
@ -163,7 +151,7 @@ namespace MLEM.Input {
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
/// <returns>Whether this keybind was considered to be down</returns>
public bool WasDown(InputHandler handler, int gamepadIndex = -1) {
foreach (var combination in this.Combinations) {
foreach (var combination in this.combinations) {
if (combination.WasDown(handler, gamepadIndex))
return true;
}
@ -178,7 +166,7 @@ namespace MLEM.Input {
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
/// <returns>Whether this keybind is considered to be pressed</returns>
public bool IsPressed(InputHandler handler, int gamepadIndex = -1) {
foreach (var combination in this.Combinations) {
foreach (var combination in this.combinations) {
if (combination.IsPressed(handler, gamepadIndex))
return true;
}
@ -193,7 +181,7 @@ namespace MLEM.Input {
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
/// <returns>Whether this keybind is considered to be pressed</returns>
public bool IsPressedAvailable(InputHandler handler, int gamepadIndex = -1) {
foreach (var combination in this.Combinations) {
foreach (var combination in this.combinations) {
if (combination.IsPressedAvailable(handler, gamepadIndex))
return true;
}
@ -208,7 +196,7 @@ namespace MLEM.Input {
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
/// <returns>Whether this keybind is considered to be pressed</returns>
public bool TryConsumePressed(InputHandler handler, int gamepadIndex = -1) {
foreach (var combination in this.Combinations) {
foreach (var combination in this.combinations) {
if (combination.TryConsumePressed(handler, gamepadIndex))
return true;
}
@ -223,7 +211,7 @@ namespace MLEM.Input {
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
/// <returns>Whether any of this keyboard's modifier keys are down</returns>
public bool IsModifierDown(InputHandler handler, int gamepadIndex = -1) {
foreach (var combination in this.Combinations) {
foreach (var combination in this.combinations) {
if (combination.IsModifierDown(handler, gamepadIndex))
return true;
}
@ -238,7 +226,7 @@ namespace MLEM.Input {
/// <param name="gamepadIndex">The index of the gamepad to query, or -1 to query all gamepads</param>
/// <returns>Whether any of this keyboard's modifier keys were down</returns>
public bool WasModifierDown(InputHandler handler, int gamepadIndex = -1) {
foreach (var combination in this.Combinations) {
foreach (var combination in this.combinations) {
if (combination.WasModifierDown(handler, gamepadIndex))
return true;
}
@ -254,7 +242,7 @@ namespace MLEM.Input {
/// <returns>The resulting down time, or <see cref="TimeSpan.Zero"/> if the input is not being held.</returns>
[Obsolete("This method is deprecated, as it does not query Modifiers or InverseModifiers. Use InputHandler.GetDownTime or custom handling instead.")]
public TimeSpan GetDownTime(InputHandler handler, int gamepadIndex = -1) {
return this.Combinations.Max(c => c.GetDownTime(handler, gamepadIndex));
return this.combinations.Max(c => c.GetDownTime(handler, gamepadIndex));
}
/// <summary>
@ -266,7 +254,7 @@ namespace MLEM.Input {
/// <returns>The resulting up time, or <see cref="TimeSpan.Zero"/> if the input is being held.</returns>
[Obsolete("This method is deprecated, as it does not query Modifiers or InverseModifiers. Use InputHandler.GetUpTime or custom handling instead.")]
public TimeSpan GetUpTime(InputHandler handler, int gamepadIndex = -1) {
return this.Combinations.Min(c => c.GetUpTime(handler, gamepadIndex));
return this.combinations.Min(c => c.GetUpTime(handler, gamepadIndex));
}
/// <summary>
@ -278,7 +266,7 @@ namespace MLEM.Input {
/// <returns>The resulting up time, or <see cref="TimeSpan.Zero"/> if the input has never been pressed, or is currently pressed.</returns>
[Obsolete("This method is deprecated, as it does not query Modifiers or InverseModifiers. Use InputHandler.GetTimeSincePress or custom handling instead.")]
public TimeSpan GetTimeSincePress(InputHandler handler, int gamepadIndex = -1) {
return this.Combinations.Min(c => c.GetTimeSincePress(handler, gamepadIndex));
return this.combinations.Min(c => c.GetTimeSincePress(handler, gamepadIndex));
}
/// <summary>
@ -286,7 +274,7 @@ namespace MLEM.Input {
/// </summary>
/// <returns>This keybind's combinations</returns>
public IEnumerable<Combination> GetCombinations() {
foreach (var combination in this.Combinations)
foreach (var combination in this.combinations)
yield return combination;
}
@ -297,8 +285,8 @@ namespace MLEM.Input {
/// <param name="combination">The combination, or default if this method returns false.</param>
/// <returns>Whether the combination could be successfully retrieved or the index was out of bounds of this keybind's combination collection.</returns>
public bool TryGetCombination(int index, out Combination combination) {
if (index >= 0 && index < this.Combinations.Length) {
combination = this.Combinations[index];
if (index >= 0 && index < this.combinations.Length) {
combination = this.combinations[index];
return true;
} else {
combination = default;
@ -315,7 +303,7 @@ namespace MLEM.Input {
/// <param name="inputName">The function to use for determining the display name of generic inputs, see <see cref="Combination.ToString(string,System.Func{MLEM.Input.GenericInput,string})"/></param>
/// <returns>A human-readable string representing this keybind</returns>
public string ToString(string joiner, string combinationJoiner = " + ", Func<GenericInput, string> inputName = null) {
return string.Join(joiner, this.Combinations.Select(c => c.ToString(combinationJoiner, inputName)));
return string.Join(joiner, this.combinations.Select(c => c.ToString(combinationJoiner, inputName)));
}
/// <summary>Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.</summary>
@ -324,7 +312,7 @@ namespace MLEM.Input {
///
/// <list type="table"><listheader><term> Value</term><description> Meaning</description></listheader><item><term> Less than zero</term><description> This instance precedes <paramref name="other" /> in the sort order.</description></item><item><term> Zero</term><description> This instance occurs in the same position in the sort order as <paramref name="other" />.</description></item><item><term> Greater than zero</term><description> This instance follows <paramref name="other" /> in the sort order.</description></item></list></returns>
public int CompareTo(Keybind other) {
return this.Combinations.Sum(c => other.Combinations.Sum(c.CompareTo));
return this.combinations.Sum(c => other.combinations.Sum(c.CompareTo));
}
/// <summary>Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.</summary>