mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 14:52:35 +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.
99 lines
3.3 KiB
C#
99 lines
3.3 KiB
C#
using Robust.Shared.Interfaces.Map;
|
|
using Robust.Shared.Maths;
|
|
using System.Collections.Generic;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Robust.Shared.Map
|
|
{
|
|
public partial class MapManager
|
|
{
|
|
class Map : IMap
|
|
{
|
|
public GameTick CreatedTick { get; }
|
|
public IMapGrid DefaultGrid { get; set; }
|
|
public MapId Index { get; }
|
|
private readonly MapManager _mapManager;
|
|
private readonly Dictionary<GridId, MapGrid> _grids = new Dictionary<GridId, MapGrid>();
|
|
|
|
public Map(MapManager mapManager, MapId mapID)
|
|
{
|
|
Index = mapID;
|
|
_mapManager = mapManager;
|
|
CreatedTick = _mapManager._gameTiming.CurTick;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IMapGrid CreateGrid(GridId? gridId = null, ushort chunkSize = 16, float snapSize = 1)
|
|
{
|
|
return _mapManager.CreateGrid(Index, gridId);
|
|
}
|
|
|
|
public void AddGrid(MapGrid grid)
|
|
{
|
|
_grids.Add(grid.Index, grid);
|
|
}
|
|
|
|
public void RemoveGrid(MapGrid grid)
|
|
{
|
|
_grids.Remove(grid.Index);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if a grid exists with the given ID.
|
|
/// </summary>
|
|
/// <param name="gridId">The ID of the grid to check.</param>
|
|
/// <returns></returns>
|
|
public bool GridExists(GridId gridId)
|
|
{
|
|
return _grids.ContainsKey(gridId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the grid associated with the given grid ID. If the grid with the given ID does not exist, return null.
|
|
/// </summary>
|
|
/// <param name="gridId">The id of the grid to get.</param>
|
|
/// <returns></returns>
|
|
public IMapGrid GetGrid(GridId gridId)
|
|
{
|
|
_grids.TryGetValue(gridId, out var output);
|
|
return output;
|
|
}
|
|
|
|
public IEnumerable<IMapGrid> GetAllGrids()
|
|
{
|
|
return _grids.Values;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IMapGrid FindGridAt(GridCoordinates worldPos)
|
|
{
|
|
var pos = worldPos.ToWorld(_mapManager).Position;
|
|
return FindGridAt(pos);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IMapGrid FindGridAt(Vector2 worldPos)
|
|
{
|
|
foreach (var kvGrid in _grids)
|
|
if (kvGrid.Value.AABBWorld.Contains(worldPos) && kvGrid.Value != DefaultGrid)
|
|
return kvGrid.Value;
|
|
return DefaultGrid;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Finds all grids that intersect the rectangle in the world.
|
|
/// </summary>
|
|
/// <param name="worldArea">The are in world coordinates to search.</param>
|
|
/// <returns></returns>
|
|
public IEnumerable<IMapGrid> FindGridsIntersecting(Box2 worldArea)
|
|
{
|
|
var gridList = new List<MapGrid>();
|
|
foreach (var kvGrid in _grids)
|
|
if (kvGrid.Value.AABBWorld.Intersects(worldArea))
|
|
gridList.Add(kvGrid.Value);
|
|
return gridList;
|
|
}
|
|
}
|
|
}
|
|
}
|