diff --git a/CHANGELOG.md b/CHANGELOG.md index faa46f1..5d8dcf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,13 @@ Removals - Marked old Draw and DrawTransformed overloads as obsolete in favor of SpriteBatchContext ones - Marked Tooltip.Paragraph as obsolete in favor of new Paragraphs collection +### MLEM.Extended +Additions +- Added LayerPositionF + +Improvements +- Allow using a StaticSpriteBatch to render an IndividualTiledMapRenderer + ### MLEM.Data Additions - Added the ability to add padding to RuntimeTexturePacker texture regions diff --git a/MLEM.Extended/Tiled/LayerPosition.cs b/MLEM.Extended/Tiled/LayerPosition.cs index c47cfc0..333ddd9 100644 --- a/MLEM.Extended/Tiled/LayerPosition.cs +++ b/MLEM.Extended/Tiled/LayerPosition.cs @@ -4,7 +4,8 @@ using MonoGame.Extended.Tiled; namespace MLEM.Extended.Tiled { /// - /// A struct that represents a position on a with multiple layers. + /// A struct that represents a position on a with multiple layers, where the and coordinates are 32-bit integer numbers. + /// See for a floating point position. /// [DataContract] public struct LayerPosition : IEquatable { @@ -117,5 +118,14 @@ namespace MLEM.Extended.Tiled { return Add(left, -right); } + /// + /// Implicitly converts a to a . + /// + /// The position to convert. + /// The converted position. + public static implicit operator LayerPositionF(LayerPosition position) { + return new LayerPositionF(position.Layer, position.X, position.Y); + } + } } \ No newline at end of file diff --git a/MLEM.Extended/Tiled/LayerPositionF.cs b/MLEM.Extended/Tiled/LayerPositionF.cs new file mode 100644 index 0000000..a84477e --- /dev/null +++ b/MLEM.Extended/Tiled/LayerPositionF.cs @@ -0,0 +1,132 @@ +using System; +using System.Runtime.Serialization; +using MonoGame.Extended.Tiled; + +namespace MLEM.Extended.Tiled { + /// + /// A struct that represents a position on a with multiple layers, where the and coordinates are 32-bit floating point numbers. + /// See for an integer position. + /// + [DataContract] + public struct LayerPositionF : IEquatable { + + /// + /// The name of the layer that this position is on + /// + [DataMember] + public string Layer; + /// + /// The x coordinate of this position + /// + [DataMember] + public float X; + /// + /// The y coordinate of this position + /// + [DataMember] + public float Y; + + /// + /// Creates a new layer position with the given settings + /// + /// The layer name + /// The x coordinate + /// The y coordinate + public LayerPositionF(string layerName, float x, float y) { + this.Layer = layerName; + this.X = x; + this.Y = y; + } + + /// + public bool Equals(LayerPositionF other) { + return this.Layer == other.Layer && this.X == other.X && this.Y == other.Y; + } + + /// Indicates whether this instance and a specified object are equal. + /// The object to compare with the current instance. + /// true if obj and this instance are the same type and represent the same value; otherwise, false. + public override bool Equals(object obj) { + return obj is LayerPositionF other && this.Equals(other); + } + + /// Returns the hash code for this instance. + /// A 32-bit signed integer that is the hash code for this instance. + public override int GetHashCode() { + var hashCode = this.Layer.GetHashCode(); + hashCode = (hashCode * 397) ^ this.X.GetHashCode(); + hashCode = (hashCode * 397) ^ this.Y.GetHashCode(); + return hashCode; + } + + /// Returns the fully qualified type name of this instance. + /// The fully qualified type name. + public override string ToString() { + return $"{nameof(this.Layer)}: {this.Layer}, {nameof(this.X)}: {this.X}, {nameof(this.Y)}: {this.Y}"; + } + + /// + /// Adds the given layer positions together, returning a new layer position with the sum of their coordinates. + /// If the two layer positions' differ, an is thrown. + /// + /// The left position. + /// The right position. + /// The sum of the positions. + /// Thrown if the two positions' are not the same. + public static LayerPositionF Add(LayerPositionF left, LayerPositionF right) { + if (left.Layer != right.Layer) + throw new ArgumentException("Cannot add layer positions on different layers"); + return new LayerPositionF(left.Layer, left.X + right.X, left.Y + right.Y); + } + + /// + public static bool operator ==(LayerPositionF left, LayerPositionF right) { + return left.Equals(right); + } + + /// + public static bool operator !=(LayerPositionF left, LayerPositionF right) { + return !left.Equals(right); + } + + /// + /// Returns the negative of the given layer position. + /// + /// The position to negate. + /// The negative position. + public static LayerPositionF operator -(LayerPositionF position) { + return new LayerPositionF(position.Layer, -position.X, -position.Y); + } + + /// + /// Returns the sum of the two layer positions using . + /// + /// The left position. + /// The right position. + /// The sum of the positions. + public static LayerPositionF operator +(LayerPositionF left, LayerPositionF right) { + return Add(left, right); + } + + /// + /// Subtracts the second from the first position using . + /// + /// The left position. + /// The right position. + /// The difference of the positions. + public static LayerPositionF operator -(LayerPositionF left, LayerPositionF right) { + return Add(left, -right); + } + + /// + /// Implicitly converts a to a . + /// The coordinates are typecast to 32-bit integers in the process. + /// + /// The position to convert. + /// The converted position. + public static implicit operator LayerPosition(LayerPositionF position) { + return new LayerPosition(position.Layer, (int) position.X, (int) position.Y); + } + + } +} \ No newline at end of file