Class LambdaMapView<T>
Class designed to make implementing simple IMapViews more convenient, by providing the "get" functionality via a function that is passed in at construction. For a version that implements ISettableMapView<T> as opposed to IMapView<T>, see LambdaSettableMapView<T>.
Inheritance
Implements
Inherited Members
Namespace: GoRogue.MapViews
Assembly: GoRogue.dll
Syntax
public sealed class LambdaMapView<T> : IMapView<T>
Type Parameters
Name | Description |
---|---|
T | The type of value being returned by the indexer functions. |
Remarks
Despite actual game map representations often consisting of complex types, exposing certain properties as primitive types (via IMapView implementations) for GoRogue algorithms to use is often fairly simple (simply exposing a property in the actual map class, or similar). If your map consists of cells of some sort, where there exists an instance of some class/struct per location that contains information about that location, TranslationMap/LambdaTranslationMap provide convenient ways to implement simple IMapViews. In the case that no such single type exists, however, a more generic IMapView implementation is needed. This class takes the "get" function as a function to shorten the process of creating such an implementation.
Constructors
| Improve this Doc View SourceLambdaMapView(Func<Int32>, Func<Int32>, Func<Coord, T>)
Constructor. Takes functions that retrieve the width and height of the map, and the function used to retrieve the value for a location.
Declaration
public LambdaMapView(Func<int> widthGetter, Func<int> heightGetter, Func<Coord, T> valueGetter)
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Int32> | widthGetter | A function/lambda that retrieves the width of the map being represented. |
System.Func<System.Int32> | heightGetter | A function/lambda that retrieves the height of the map being represented. |
System.Func<Coord, T> | valueGetter | A function/lambda that returns the value of type T associated with the location it is given. |
Remarks
This constructor is useful if the width and height of the map being represented may change -- one can provide lambdas/functions that retrieve the width and height of the map being represented, and these functions will be called any time the Width and Height properties are retrieved.
LambdaMapView(Int32, Int32, Func<Coord, T>)
Constructor. Takes the width and height of the map, and the function to use to retrieve the value for a location.
Declaration
public LambdaMapView(int width, int height, Func<Coord, T> valueGetter)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The (constant) width of the map. |
System.Int32 | height | The (constant) height of the map. |
System.Func<Coord, T> | valueGetter | A lambda/function that returns the value of type T associated with the location it is given. This function is called each time the map view's indexers are called upon to retrieve a value from a location. |
Remarks
This constructor is useful if the width and height of the underlying representation do not change, so they can safely be passed in as constants.
Properties
| Improve this Doc View SourceHeight
The height of the map being represented.
Declaration
public int Height { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Item[Coord]
Given a position, returns the "value" associated with that position, by calling the valueGetter function provided at construction.
Declaration
public T this[Coord pos] { get; }
Parameters
Type | Name | Description |
---|---|---|
Coord | pos | Location to retrieve the value for. |
Property Value
Type | Description |
---|---|
T | The "value" associated with the provided location, according to the valueGetter function provided at construction. |
Item[Int32]
Given an 1D-array-style index, determines the position associated with that index, and returns the "value" associated with that location, by calling the valueGetter function passed in at construction.
Declaration
public T this[int index1D] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index1D | 1D-array-style index for location to retrieve value for. |
Property Value
Type | Description |
---|---|
T | The "value" associated with the given location, according to the valueGetter function provided at construction. |
Item[Int32, Int32]
Given an X and Y value, returns the "value" associated with that location, by calling the valueGetter function provided at construction.
Declaration
public T this[int x, int y] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | x | X-value of location. |
System.Int32 | y | Y-value of location. |
Property Value
Type | Description |
---|---|
T | The "value" associated with that location, according to the valueGetter function provided at construction. |
Width
The width of the map being represented.
Declaration
public int Width { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceToString()
Returns a string representation of the map view.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representation of the map view. |
Overrides
ToString(Func<T, String>)
Returns a string representation of the map view, using elementStringifier
to determine what string represents each value.
Declaration
public string ToString(Func<T, string> elementStringifier)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, System.String> | elementStringifier | Function determining the string representation of each element. |
Returns
Type | Description |
---|---|
System.String | A string representation of the LambdaMapView. |
Remarks
This could be used, for example, on an LambdaMapView of boolean values, to output '#' for false values, and '.' for true values.
ToString(Int32, Func<T, String>)
Prints the values in the LambdaMapView, using the function specified to turn elements into strings, and using the "field length" specified.
Declaration
public string ToString(int fieldSize, Func<T, string> elementStringifier = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | fieldSize | The size of the field to give each value. A positive-number right-aligns the text within the field, while a negative number left-aligns the text. |
System.Func<T, System.String> | elementStringifier | Function to use to convert each element to a string. null defaults to the ToString function of type T. |
Returns
Type | Description |
---|---|
System.String | A string representation of the LambdaMapView. |
Remarks
Each element of type T will have spaces added to cause it to take up exactly
fieldSize
characters, provided fieldSize
is less than the length of the element's string represention.