2019-12-07 13:00:50 +01:00
|
|
|
using System.Runtime.Serialization;
|
2020-05-22 20:32:38 +02:00
|
|
|
using MonoGame.Extended.Tiled;
|
2019-12-07 13:00:50 +01:00
|
|
|
|
|
|
|
namespace MLEM.Extended.Tiled {
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// A struct that represents a position on a <see cref="TiledMap"/> with multiple layers.
|
|
|
|
/// </summary>
|
2019-12-07 13:00:50 +01:00
|
|
|
[DataContract]
|
|
|
|
public struct LayerPosition {
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The name of the layer that this position is on
|
|
|
|
/// </summary>
|
2019-12-07 13:00:50 +01:00
|
|
|
[DataMember]
|
|
|
|
public string Layer;
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The x coordinate of this position
|
|
|
|
/// </summary>
|
2019-12-07 13:00:50 +01:00
|
|
|
[DataMember]
|
|
|
|
public int X;
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// The y coordinate of this position
|
|
|
|
/// </summary>
|
2019-12-07 13:00:50 +01:00
|
|
|
[DataMember]
|
|
|
|
public int Y;
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new layer position with the given settings
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="layerName">The layer name</param>
|
|
|
|
/// <param name="x">The x coordinate</param>
|
|
|
|
/// <param name="y">The y coordinate</param>
|
2019-12-07 13:00:50 +01:00
|
|
|
public LayerPosition(string layerName, int x, int y) {
|
|
|
|
this.Layer = layerName;
|
|
|
|
this.X = x;
|
|
|
|
this.Y = y;
|
|
|
|
}
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <inheritdoc cref="Equals(LayerPosition)"/>
|
2019-12-07 13:00:50 +01:00
|
|
|
public static bool operator ==(LayerPosition left, LayerPosition right) {
|
|
|
|
return left.Equals(right);
|
|
|
|
}
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <inheritdoc cref="Equals(LayerPosition)"/>
|
2019-12-07 13:00:50 +01:00
|
|
|
public static bool operator !=(LayerPosition left, LayerPosition right) {
|
|
|
|
return !left.Equals(right);
|
|
|
|
}
|
|
|
|
|
2020-05-22 20:32:38 +02:00
|
|
|
/// <inheritdoc cref="Equals(object)"/>
|
2019-12-07 13:00:50 +01:00
|
|
|
public bool Equals(LayerPosition other) {
|
|
|
|
return this.Layer == other.Layer && this.X == other.X && this.Y == other.Y;
|
|
|
|
}
|
|
|
|
|
2021-11-22 19:25:18 +01:00
|
|
|
/// <summary>Indicates whether this instance and a specified object are equal.</summary>
|
|
|
|
/// <param name="obj">The object to compare with the current instance.</param>
|
|
|
|
/// <returns>true if <paramref name="obj">obj</paramref> and this instance are the same type and represent the same value; otherwise, false.</returns>
|
2019-12-07 13:00:50 +01:00
|
|
|
public override bool Equals(object obj) {
|
|
|
|
return obj is LayerPosition other && this.Equals(other);
|
|
|
|
}
|
|
|
|
|
2021-11-22 19:25:18 +01:00
|
|
|
/// <summary>Returns the hash code for this instance.</summary>
|
|
|
|
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
|
2019-12-07 13:00:50 +01:00
|
|
|
public override int GetHashCode() {
|
|
|
|
var hashCode = this.Layer.GetHashCode();
|
|
|
|
hashCode = (hashCode * 397) ^ this.X;
|
|
|
|
hashCode = (hashCode * 397) ^ this.Y;
|
|
|
|
return hashCode;
|
|
|
|
}
|
|
|
|
|
2021-11-30 11:46:06 +01:00
|
|
|
/// <summary>Returns the fully qualified type name of this instance.</summary>
|
|
|
|
/// <returns>The fully qualified type name.</returns>
|
2019-12-07 13:00:50 +01:00
|
|
|
public override string ToString() {
|
|
|
|
return $"{nameof(this.Layer)}: {this.Layer}, {nameof(this.X)}: {this.X}, {nameof(this.Y)}: {this.Y}";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|