mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 17:47:24 +02:00
* Move MapManager queries to SharedMapSystem Moves all variants of FindGridsIntersecting/TryFindGridAt to SharedMapSystem Hollows out the MapManager methods and converts them into relays to SharedMapSystem * Move CreateGrid to SharedMapSystem Moves the functionality for CreateGrid and its variants to SharedMapSystem Hollows out the MapManager methods and converts them into relays for the SharedMapSystem methods Obsoletes them too Also moves over the GetAllMapGrids and GetAllGrids methods * Move RaiseOnTileChanged to SharedMapSystem Also moves the SuppressOnTileChanged flag member to SharedMapSystem Hollows out and obsoletes the MapManager versions * Move default value constants to SharedMapSystem * Converts map pausing events into LocalizedEntityCommands * Move MapManager related delegates/structs to SharedMapSystem Moves the GridCreationOptions struct to the same namespace as SharedMapSystem and converts it into a record struct Move the GridCallback delegates to the same namespace as SharedMapSystem * Move CullDeletionHistory to SharedMapSystem Well, that was less painful than I thought it would be * Actually obsolete the NetworkedMapManager method * Rename file * Doc comments for new SharedMapSystem methods * Doc comment * Doc comments * Fix access * Purge all references to IMapManagerInternal * Cull easy IMapManager references * The rest * Purge IMapManager * Private internal FindGridsIntersecting method * please die * 41 * notes --------- Co-authored-by: ArtisticRoomba <145879011+ArtisticRoomba@users.noreply.github.com>
84 lines
2.8 KiB
C#
84 lines
2.8 KiB
C#
using JetBrains.Annotations;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Map.Components;
|
|
using Robust.Shared.Maths;
|
|
|
|
namespace Robust.Shared.GameObjects;
|
|
|
|
public abstract partial class SharedMapSystem
|
|
{
|
|
/// <summary>
|
|
/// If the supplied coordinates intersects a grid will align with the tile center, otherwise returns the coordinates.
|
|
/// </summary>
|
|
/// <param name="coordinates"></param>
|
|
/// <returns></returns>
|
|
[Pure]
|
|
public EntityCoordinates AlignToGrid(EntityCoordinates coordinates)
|
|
{
|
|
// Check if the parent is already a grid.
|
|
if (_gridQuery.TryGetComponent(coordinates.EntityId, out var gridComponent))
|
|
{
|
|
var tile = CoordinatesToTile(coordinates.EntityId, gridComponent, coordinates);
|
|
return ToCenterCoordinates(coordinates.EntityId, tile, gridComponent);
|
|
}
|
|
|
|
// Check if mappos intersects a grid.
|
|
var mapPos = _transform.ToMapCoordinates(coordinates);
|
|
|
|
if (TryFindGridAt(mapPos, out var gridUid, out gridComponent))
|
|
{
|
|
var tile = CoordinatesToTile(gridUid, gridComponent, coordinates);
|
|
return ToCenterCoordinates(gridUid, tile, gridComponent);
|
|
}
|
|
|
|
// No grid so just return it.
|
|
return coordinates;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a tileRef to EntityCoordinates.
|
|
/// </summary>
|
|
[Pure]
|
|
public EntityCoordinates ToCoordinates(TileRef tileRef, MapGridComponent? gridComponent = null)
|
|
{
|
|
return ToCoordinates(tileRef.GridUid, tileRef.GridIndices, gridComponent);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a tileRef to EntityCoordinates.
|
|
/// </summary>
|
|
[Pure]
|
|
public EntityCoordinates ToCoordinates(EntityUid gridUid, Vector2i tile, MapGridComponent? gridComponent = null)
|
|
{
|
|
if (!_gridQuery.Resolve(gridUid, ref gridComponent))
|
|
{
|
|
return EntityCoordinates.Invalid;
|
|
}
|
|
|
|
return new EntityCoordinates(gridUid, tile * gridComponent.TileSize);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a tileRef to EntityCoordinates for the center of the tile.
|
|
/// </summary>
|
|
[Pure]
|
|
public EntityCoordinates ToCenterCoordinates(TileRef tileRef, MapGridComponent? gridComponent = null)
|
|
{
|
|
return ToCenterCoordinates(tileRef.GridUid, tileRef.GridIndices, gridComponent);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts a tileRef to EntityCoordinates for the center of the tile.
|
|
/// </summary>
|
|
[Pure]
|
|
public EntityCoordinates ToCenterCoordinates(EntityUid gridUid, Vector2i tile, MapGridComponent? gridComponent = null)
|
|
{
|
|
if (!_gridQuery.Resolve(gridUid, ref gridComponent))
|
|
{
|
|
return EntityCoordinates.Invalid;
|
|
}
|
|
|
|
return new EntityCoordinates(gridUid, tile * gridComponent.TileSize + gridComponent.TileSizeHalfVector);
|
|
}
|
|
}
|