Class IMapViewExtensions
Extensions for IMapView<T> implementaions that provide basic utility functions for them.
Inheritance
Inherited Members
Namespace: GoRogue.MapViews
Assembly: GoRogue.dll
Syntax
public static class IMapViewExtensions
Remarks
By providing these as extension methods, they effectively act as interface methods that have implementations already defined. If these were regular interface implemenations, all interface implementers would be forced to implement them manually, which is undesireable as the implementation should clearly be the same and is based only on functions/properties defined in IMapView.
Methods
| Improve this Doc View SourceApplyOverlay<T>(ISettableMapView<T>, IMapView<T>)
Sets all the values of the current map to be equal to the corresponding values from the map you pass in.
Declaration
public static void ApplyOverlay<T>(this ISettableMapView<T> self, IMapView<T> overlay)
Parameters
Type | Name | Description |
---|---|---|
ISettableMapView<T> | self | |
IMapView<T> | overlay | The data apply to the map. Must have identical dimensions to the current map. |
Type Parameters
Name | Description |
---|---|
T |
Bounds<T>(IMapView<T>)
Gets a rectangle representing the bounds of the current map view.
Declaration
public static Rectangle Bounds<T>(this IMapView<T> mapView)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView |
Returns
Type | Description |
---|---|
Rectangle | A rectangle representing the map view's bounds. |
Type Parameters
Name | Description |
---|---|
T |
Contains<T>(IMapView<T>, Coord)
Returns whether or not the given position is contained withing the current map view or not.
Declaration
public static bool Contains<T>(this IMapView<T> mapView, Coord position)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView | |
Coord | position | The position to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if the given position is contained within this map view, false otherwise. |
Type Parameters
Name | Description |
---|---|
T |
Contains<T>(IMapView<T>, Int32, Int32)
Returns whether or not the given position is contained withing the current map view or not.
Declaration
public static bool Contains<T>(this IMapView<T> mapView, int x, int y)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView | |
System.Int32 | x | X-value of the position to check. |
System.Int32 | y | Y-value of the position to check. |
Returns
Type | Description |
---|---|
System.Boolean | True if the given position is contained within this map view, false otherwise. |
Type Parameters
Name | Description |
---|---|
T |
ExtendToString<T>(IMapView<T>, Int32, String, String, Func<T, String>, String, String, String, String)
Allows stringifying the contents of a map view. Takes characters to surround the map, and each row, the method used to get the string representation of each element (defaulting to the ToString function of type T), and separation characters for each element and row. Takes the size of the field to give each element, characters to surround the MapView printout, and each row, the method used to get the string representation of each element (defaulting to the ToString function of type T), and separation characters for each element and row.
Declaration
public static string ExtendToString<T>(this IMapView<T> map, int fieldSize, string begin = "", string beginRow = "", Func<T, string> elementStringifier = null, string rowSeparator = "\n", string elementSeparator = " ", string endRow = "", string end = "")
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | map | |
System.Int32 | fieldSize | The amount of space each element should take up in characters. A positive number aligns the text to the right of the space, while a negative number aligns the text to the left. |
System.String | begin | Character(s) that should precede the IMapView printout. |
System.String | beginRow | Character(s) that should precede each row. |
System.Func<T, System.String> | elementStringifier | Function to use to get the string representation of each value. Null uses the ToString function of type T. |
System.String | rowSeparator | Character(s) to separate each row from the next. |
System.String | elementSeparator | Character(s) to separate each element from the next. |
System.String | endRow | Character(s) that should follow each row. |
System.String | end | Character(s) that should follow the IMapView printout. |
Returns
Type | Description |
---|---|
System.String | A string representation of the map, as viewd by the given map view. |
Type Parameters
Name | Description |
---|---|
T |
ExtendToString<T>(IMapView<T>, String, String, Func<T, String>, String, String, String, String)
Allows stringifying the contents of a map view. Takes characters to surround the map printout, and each row, the method used to get the string representation of each element (defaulting to the ToString function of type T), and separation characters for each element and row.
Declaration
public static string ExtendToString<T>(this IMapView<T> map, string begin = "", string beginRow = "", Func<T, string> elementStringifier = null, string rowSeparator = "\n", string elementSeparator = " ", string endRow = "", string end = "")
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | map | |
System.String | begin | Character(s) that should precede the IMapView printout. |
System.String | beginRow | Character(s) that should precede each row. |
System.Func<T, System.String> | elementStringifier | Function to use to get the string representation of each value. null uses the ToString function of type T. |
System.String | rowSeparator | Character(s) to separate each row from the next. |
System.String | elementSeparator | Character(s) to separate each element from the next. |
System.String | endRow | Character(s) that should follow each row. |
System.String | end | Character(s) that should follow the IMapView printout. |
Returns
Type | Description |
---|---|
System.String | A string representation of the map, as viewd by the given map view. |
Type Parameters
Name | Description |
---|---|
T |
Positions<T>(IMapView<T>)
Iterates through each position in the map view. Equivalent to nested for loop for (y = 0...) for (x = 0...)
Declaration
public static IEnumerable<Coord> Positions<T>(this IMapView<T> mapView)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Coord> | All positions in the IMapView. |
Type Parameters
Name | Description |
---|---|
T |
RandomItem<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
Gets the item at a random position in the map view for which the selector returns true. Random positions will continuously be generated until one that qualifies is found.
Declaration
public static T RandomItem<T>(this IMapView<T> mapView, Func<Coord, T, bool> selector, IGenerator rng = null)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView | |
System.Func<Coord, T, System.Boolean> | selector | Function that takes a position, and the value at that position, and returns true if it is an acceptable selection, and false if not. |
Troschuetz.Random.IGenerator | rng | The rng to use. Defaults to DefaultRNG. |
Returns
Type | Description |
---|---|
T | The item at a random position in the IMapView for which the selector returns true. |
Type Parameters
Name | Description |
---|---|
T |
RandomItem<T>(IMapView<T>, IGenerator)
Gets the value at a random position in the IMapView.
Declaration
public static T RandomItem<T>(this IMapView<T> mapView, IGenerator rng = null)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView | |
Troschuetz.Random.IGenerator | rng | The rng to use. Defaults to DefaultRNG. |
Returns
Type | Description |
---|---|
T | The item at a random position in the IMapView. |
Type Parameters
Name | Description |
---|---|
T |
RandomPosition<T>(IMapView<T>, T, IGenerator)
Gets a random position in the map view, whose value in that map view is the specified one. Random positions will continually be generated until one with the specified value is found.
Declaration
public static Coord RandomPosition<T>(this IMapView<T> mapView, T validValue, IGenerator rng = null)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView | |
T | validValue | A value to look for in the IMapView to determine whether or not a generated position is valid. |
Troschuetz.Random.IGenerator | rng | The rng to use. Defaults to DefaultRNG. |
Returns
Type | Description |
---|---|
Coord | A random position whose value in the current IMapView is equal to the one specified. |
Type Parameters
Name | Description |
---|---|
T |
RandomPosition<T>(IMapView<T>, HashSet<T>, IGenerator)
Gets a random position in the map view, whose value in map view is one of the ones specified in the hash set. Random positions will continually be generated until one that has one of the specified values is found.
Declaration
public static Coord RandomPosition<T>(this IMapView<T> mapView, HashSet<T> validValues, IGenerator rng = null)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView | |
System.Collections.Generic.HashSet<T> | validValues | A set of values to look for in the IMapView to determine whether or not a generated position is valid. |
Troschuetz.Random.IGenerator | rng | The rng to use. Defaults to DefaultRNG. |
Returns
Type | Description |
---|---|
Coord | A random position whose value in this IMapView is equal to one of the values specified. |
Type Parameters
Name | Description |
---|---|
T |
RandomPosition<T>(IMapView<T>, IEnumerable<T>, IGenerator)
Gets a random position in the map view, whose value in map view is one of the ones specified. Random positions will continually be generated until one that has one of the specified values is found.
Declaration
public static Coord RandomPosition<T>(this IMapView<T> mapView, IEnumerable<T> validValues, IGenerator rng = null)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView | |
System.Collections.Generic.IEnumerable<T> | validValues | A set of values to look for in the IMapView to determine whether or not a generated position is valid. |
Troschuetz.Random.IGenerator | rng | The rng to use. Defaults to DefaultRNG. |
Returns
Type | Description |
---|---|
Coord | A random position whose value in this IMapView is equal to one of the values specified. |
Type Parameters
Name | Description |
---|---|
T |
RandomPosition<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
Gets a random position in the map view, for which the selector returns true. Random positions will continuously be generated until one that qualifies is found.
Declaration
public static Coord RandomPosition<T>(this IMapView<T> mapView, Func<Coord, T, bool> selector, IGenerator rng = null)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView | |
System.Func<Coord, T, System.Boolean> | selector | Function that takes a position and the value at that position, and returns true if it is an acceptable selection, and false if not. |
Troschuetz.Random.IGenerator | rng | The rng to use. Defaults toDefaultRNG. |
Returns
Type | Description |
---|---|
Coord | A random position in the IMapView for which the selector returns true. |
Type Parameters
Name | Description |
---|---|
T |
RandomPosition<T>(IMapView<T>, IGenerator)
Gets a random position within the IMapView.
Declaration
public static Coord RandomPosition<T>(this IMapView<T> mapView, IGenerator rng = null)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView | |
Troschuetz.Random.IGenerator | rng | The rng to use. Defaults to DefaultRNG. |
Returns
Type | Description |
---|---|
Coord | A random position within the IMapView. |
Type Parameters
Name | Description |
---|---|
T |
RandomPosition<T>(IMapView<T>, IGenerator, T[])
Gets a random position in the map view, whose value in map view is one of the ones
specified in validValues
. Random positions will continually be generated until one that
has one of the specified values is found.
Declaration
public static Coord RandomPosition<T>(this IMapView<T> mapView, IGenerator rng = null, params T[] validValues)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T> | mapView | |
Troschuetz.Random.IGenerator | rng | The rng to use. Defaults to DefaultRNG. |
T[] | validValues | A set of values to look for in the IMapView to determine whether or not a generated position is valid. |
Returns
Type | Description |
---|---|
Coord | A random position whose value in this IMapView is equal to one of the values specified. |
Type Parameters
Name | Description |
---|---|
T |