mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-16 07:12:27 +02:00
* Removed unused method TileRef.GetStep(). Removed unused property TileRef.TileSize. Removed unused property TileRef.Tile, made the field public with the same name. Made the TileRef struct readonly. Removed property TileRef.TileDef. Removed property TileRef.LocalPos. Renamed GridTile to GridIndices. Implemented IEquatable on TileRef. Implemented Equality operators on TileRef. Added PublicAPI attribute to TileRef. Added doc comments to TileRef. * Modified Tile: Added the PublicApi annotation. Made struct readonly. Filled out doc comments. Changed auto properties to readonly fields. Renamed TileId to TypeId. Added a static Empty tile to the struct. Implemented IEquatable. * Modified MapCoordinates: Added PublicApi attribute. Implemented IEquatable. Filled out doc comments. Removed Map property. * Modified ScreenCoordinates: Filled out doc comments. Added the PublicApi attribute. Implemented IEquatable. * Modified GridCoordinates: Removed method IsValidLocation. * Removed property GridCoordinates.Grid. * Removed GridCoordinates.Map. * Removed GridCoordinates.MapId. * Removed property GridCoordinates.IsWorld. Removed constructors taking a MapId. * Removed static IoCManager calls from GridCoordinates. * Modified GridCoordinates: Added attribute PublicApi. Filled out doc comments. * Filled out doc comments for MapGrid. Filled out doc comments for MapIndices. Misc refactors for both. * added command to teleport grids. * Added method Box2.Intersect. Added method Box2.Union. Placement manager now spawns new grids to place tiles not connected to an existing grid.
115 lines
3.2 KiB
C#
115 lines
3.2 KiB
C#
using System;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace Robust.Shared.Map
|
|
{
|
|
/// <summary>
|
|
/// This structure contains the data for an individual Tile in a <c>MapGrid</c>.
|
|
/// </summary>
|
|
[PublicAPI, Serializable]
|
|
public readonly struct Tile : IEquatable<Tile>
|
|
{
|
|
/// <summary>
|
|
/// Internal type ID of this tile.
|
|
/// </summary>
|
|
public readonly ushort TypeId;
|
|
|
|
/// <summary>
|
|
/// Optional per-tile data of this tile.
|
|
/// </summary>
|
|
public readonly ushort Data;
|
|
|
|
/// <summary>
|
|
/// An empty tile that can be compared against.
|
|
/// </summary>
|
|
public static readonly Tile Empty = new Tile(0);
|
|
|
|
/// <summary>
|
|
/// Is this tile space (empty)?
|
|
/// </summary>
|
|
public bool IsEmpty => TypeId == 0;
|
|
|
|
/// <summary>
|
|
/// Creates a new instance of a grid tile.
|
|
/// </summary>
|
|
/// <param name="typeId">Internal type ID.</param>
|
|
/// <param name="data">Optional per-tile data.</param>
|
|
public Tile(ushort typeId, ushort data = 0)
|
|
{
|
|
TypeId = typeId;
|
|
Data = data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Explicit conversion of <c>Tile</c> to <c>uint</c> . This should only
|
|
/// be used in special cases like serialization. Do NOT use this in
|
|
/// content.
|
|
/// </summary>
|
|
public static explicit operator uint(Tile tile)
|
|
{
|
|
return ((uint)tile.TypeId << 16) | tile.Data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Explicit conversion of <c>uint</c> to <c>Tile</c> . This should only
|
|
/// be used in special cases like serialization. Do NOT use this in
|
|
/// content.
|
|
/// </summary>
|
|
public static explicit operator Tile(uint tile)
|
|
{
|
|
return new Tile(
|
|
(ushort)(tile >> 16),
|
|
(ushort)tile
|
|
);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check for equality by value between two objects.
|
|
/// </summary>
|
|
public static bool operator ==(Tile a, Tile b)
|
|
{
|
|
return a.Equals(b);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check for inequality by value between two objects.
|
|
/// </summary>
|
|
public static bool operator !=(Tile a, Tile b)
|
|
{
|
|
return !a.Equals(b);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generates String representation of this Tile.
|
|
/// </summary>
|
|
/// <returns>String representation of this Tile.</returns>
|
|
public override string ToString()
|
|
{
|
|
return $"Tile {TypeId}, {Data}";
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public bool Equals(Tile other)
|
|
{
|
|
return TypeId == other.TypeId && Data == other.Data;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override bool Equals(object obj)
|
|
{
|
|
if (ReferenceEquals(null, obj))
|
|
return false;
|
|
return obj is Tile other && Equals(other);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override int GetHashCode()
|
|
{
|
|
unchecked
|
|
{
|
|
return (TypeId.GetHashCode() * 397) ^ Data.GetHashCode();
|
|
}
|
|
}
|
|
}
|
|
}
|