using System; using JetBrains.Annotations; namespace Robust.Shared.Map; /// /// This structure contains the data for an individual Tile in a MapGrid. /// [PublicAPI, Serializable] public readonly struct Tile : IEquatable { /// /// Internal type ID of this tile. /// public readonly ushort TypeId; /// /// Rendering flags. /// public readonly TileRenderFlag Flags; /// /// Variant of this tile to render. /// public readonly byte Variant; /// /// An empty tile that can be compared against. /// public static readonly Tile Empty = new(0); /// /// Is this tile space (empty)? /// public bool IsEmpty => TypeId == 0; /// /// Creates a new instance of a grid tile. /// /// Internal type ID. /// Flags used by toolbox's rendering. /// The visual variant this tile is using. public Tile(ushort typeId, TileRenderFlag flags = 0, byte variant = 0) { TypeId = typeId; Flags = flags; Variant = variant; } /// /// Explicit conversion of Tile to uint . This should only /// be used in special cases like serialization. Do NOT use this in /// content. /// public static explicit operator uint(Tile tile) { return ((uint)tile.TypeId << 16) | (uint)tile.Flags << 8 | tile.Variant; } /// /// Explicit conversion of uint to Tile . This should only /// be used in special cases like serialization. Do NOT use this in /// content. /// public static explicit operator Tile(uint tile) { return new( (ushort)(tile >> 16), (TileRenderFlag)(tile >> 8), (byte)tile ); } /// /// Check for equality by value between two objects. /// public static bool operator ==(Tile a, Tile b) { return a.Equals(b); } /// /// Check for inequality by value between two objects. /// public static bool operator !=(Tile a, Tile b) { return !a.Equals(b); } /// /// Generates String representation of this Tile. /// /// String representation of this Tile. public override string ToString() { return $"Tile {TypeId}, {Flags}, {Variant}"; } /// public bool Equals(Tile other) { return TypeId == other.TypeId && Flags == other.Flags && Variant == other.Variant; } /// public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) return false; return obj is Tile other && Equals(other); } /// public override int GetHashCode() { unchecked { return (TypeId.GetHashCode() * 397) ^ Flags.GetHashCode() ^ Variant.GetHashCode(); } } } public enum TileRenderFlag : byte { }