Interface IReadOnlySpatialMap<T>
Implements the read-only interface of ISpatialMap<T>.
Namespace: SadRogue.Primitives.SpatialMaps
Assembly: TheSadRogue.Primitives.dll
Syntax
public interface IReadOnlySpatialMap<T> : IEnumerable<ItemPositionPair<T>>, IEnumerable
Type Parameters
Name | Description |
---|---|
T |
Remarks
Simply exposes only those functions of ISpatialMap<T> that do not allow direct modification of the data (eg. adding/moving/removing items). This can allow for direct exposure of an ISpatialMap as a property of type IReadOnlySpatialMap, without allowing such an exposure to break data encapsulation principles of something like a game map.
Properties
Count
The number of items in the spatial map.
Declaration
int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Items
Enumerable of the items stored in the spatial map: for use to iterate over all items with a foreach loop.
Declaration
IEnumerable<T> Items { get; }
Property Value
Type | Description |
---|---|
IEnumerable<T> |
Positions
Enumerable of all positions that contain items.
Declaration
IEnumerable<Point> Positions { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Point> |
Methods
AsReadOnly()
Returns a read-only reference to the spatial map. Convenient for "safely" exposing the spatial as a property, without allowing direct modification.
Declaration
IReadOnlySpatialMap<T> AsReadOnly()
Returns
Type | Description |
---|---|
IReadOnlySpatialMap<T> | The current spatial map, as a "read-only" reference. |
CanAdd(T, Point)
Returns true if the given item can be added at the given position; false otherwise.
Declaration
bool CanAdd(T newItem, Point position)
Parameters
Type | Name | Description |
---|---|---|
T | newItem | Item to add. |
Point | position | Position to add item to. |
Returns
Type | Description |
---|---|
Boolean | True if the item can be successfully added at the position given; false otherwise. |
CanAdd(T, Int32, Int32)
Returns true if the given item can be added at the given position; false otherwise.
Declaration
bool CanAdd(T newItem, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
T | newItem | Item to add. |
Int32 | x | X-value of the position to add item to. |
Int32 | y | Y-value of the position to add item to. |
Returns
Type | Description |
---|---|
Boolean | True if the item can be successfully added at the position given; false otherwise. |
CanMove(T, Point)
Returns true if the given item can be moved from its current location to the specified one; false otherwise.
Declaration
bool CanMove(T item, Point target)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to move. |
Point | target | Location to move item to. |
Returns
Type | Description |
---|---|
Boolean | true if the given item can be moved to the given position; false otherwise. |
CanMove(T, Int32, Int32)
Returns true if the given item can be moved from its current location to the specified one; false otherwise.
Declaration
bool CanMove(T item, int targetX, int targetY)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to move. |
Int32 | targetX | X-value of the location to move item to. |
Int32 | targetY | Y-value of the location to move item to. |
Returns
Type | Description |
---|---|
Boolean | true if the given item can be moved to the given position; false otherwise. |
CanMoveAll(Point, Point)
Returns true if there are items at current
and all items at that position
can be moved to target
; false otherwise.
Declaration
bool CanMoveAll(Point current, Point target)
Parameters
Type | Name | Description |
---|---|---|
Point | current | Location to move items from. |
Point | target | Location to move items to. |
Returns
Type | Description |
---|---|
Boolean | true if all items at the position current can be moved to the position target; false if one or more items cannot be moved or there are no items to move. |
CanMoveAll(Int32, Int32, Int32, Int32)
Returns true if there are items at the current position specified, and all items at that position can be moved to the target position; false otherwise.
Declaration
bool CanMoveAll(int currentX, int currentY, int targetX, int targetY)
Parameters
Type | Name | Description |
---|---|---|
Int32 | currentX | X-value of the location to move items from. |
Int32 | currentY | Y-value of the location to move items from. |
Int32 | targetX | X-value of the location to move items to. |
Int32 | targetY | Y-value of the location to move items to. |
Returns
Type | Description |
---|---|
Boolean | true if all items at the position current can be moved to the position target; false if one or more items cannot be moved or there are no items to move. |
Contains(T)
Returns whether or not the spatial map contains the given item.
Declaration
bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to check for. |
Returns
Type | Description |
---|---|
Boolean | True if the given item is contained in the spatial map, false if not. |
Contains(Point)
Returns if there is an item in the spatial map at the given position or not.
Declaration
bool Contains(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to check for. |
Returns
Type | Description |
---|---|
Boolean | True if there is some item at the given position, false if not. |
Contains(Int32, Int32)
Returns if there is an item in the spatial map at the given position or not.
Declaration
bool Contains(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | The x-value of the position to check for. |
Int32 | y | The y-value of the position to check for. |
Returns
Type | Description |
---|---|
Boolean | True if there is some item at the given position, false if not. |
GetItemsAt(Point)
Gets the item(s) at the given position if there are any items, or returns nothing if there is nothing at that position.
Declaration
IEnumerable<T> GetItemsAt(Point position)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position to return the item(s) for. |
Returns
Type | Description |
---|---|
IEnumerable<T> | The item(s) at the given position if there are any items, or nothing if there is nothing at that position. |
GetItemsAt(Int32, Int32)
Gets the item(s) at the given position if there are any items, or returns nothing if there is nothing at that position.
Declaration
IEnumerable<T> GetItemsAt(int x, int y)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | The x-value of the position to return the item(s) for. |
Int32 | y | The y-value of the position to return the item(s) for. |
Returns
Type | Description |
---|---|
IEnumerable<T> | The item(s) at the given position if there are any items, or nothing if there is nothing at that position. |
GetPositionOf(T)
Gets the position associated with the given item in the spatial map. If the item does not exist in the spatial map, throws ArgumentException.
Declaration
Point GetPositionOf(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to get the position for. |
Returns
Type | Description |
---|---|
Point | The position associated with the given item. |
GetPositionOfOrNull(T)
Gets the position associated with the given item in the spatial map, or null if that item is not found.
Declaration
Nullable<Point> GetPositionOfOrNull(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The item to get the position for. |
Returns
Type | Description |
---|---|
Nullable<Point> | The position associated with the given item, if it exists in the spatial map, or null if the item does not exist. |
ToString(Func<T, String>)
Returns a string representation of the IReadOnlySpatialMap, allowing display of the spatial map's items in a specified way.
Declaration
string ToString(Func<T, string> itemStringifier)
Parameters
Type | Name | Description |
---|---|---|
Func<T, String> | itemStringifier | Function that turns an item into a string. |
Returns
Type | Description |
---|---|
String | A string representation of the spatial map. |
TryGetPositionOf(T, out Point)
Attempts to get the position of the given item in the spatial map. If successful, the function will return
true and the position will be stored in the position
parameter. If the item was not found,
position
will have the default value for Point, and the function will return false.
Declaration
bool TryGetPositionOf(T item, out Point position)
Parameters
Type | Name | Description |
---|---|---|
T | item | Item to retrieve the position of. |
Point | position | The position of the item if found, or default(Point) if not. |
Returns
Type | Description |
---|---|
Boolean | True if the item was found in the spatial map, false otherwise. |
Events
ItemAdded
Event that is fired directly after an item has been added to the spatial map.
Declaration
event EventHandler<ItemEventArgs<T>> ItemAdded
Event Type
Type | Description |
---|---|
EventHandler<ItemEventArgs<T>> |
ItemMoved
Event that is fired directly after an item in the spatial map has been moved.
Declaration
event EventHandler<ItemMovedEventArgs<T>> ItemMoved
Event Type
Type | Description |
---|---|
EventHandler<ItemMovedEventArgs<T>> |
ItemRemoved
Event that is fired directly after an item has been removed from the spatial map.
Declaration
event EventHandler<ItemEventArgs<T>> ItemRemoved
Event Type
Type | Description |
---|---|
EventHandler<ItemEventArgs<T>> |