Class LambdaSettableMapView<T>
Class designed to make implementing simple ISettableMapViews more convenient, by providing the get/set functionality via a function that is passed in at construction. For a version that implements IMapView<T> as opposed to ISettableMapView<T>, see LambdaMapView<T>.
Inheritance
Inherited Members
Namespace: GoRogue.MapViews
Assembly: GoRogue.dll
Syntax
public sealed class LambdaSettableMapView<T> : ISettableMapView<T>, IMapView<T>
Type Parameters
Name | Description |
---|---|
T | The type of value being returned by the indexer functions. |
Remarks
See LambdaMapView<T>. Identical in nature, but takes both get and set functionality via functions.
Constructors
| Improve this Doc View SourceLambdaSettableMapView(Func<Int32>, Func<Int32>, Func<Coord, T>, Action<Coord, T>)
Constructor. Takes functions that retrieve the width and height of the map, and the functions used to retrieve/set the value for a location.
Declaration
public LambdaSettableMapView(Func<int> widthGetter, Func<int> heightGetter, Func<Coord, T> valueGetter, Action<Coord, T> valueSetter)
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. |
System.Action<Coord, T> | valueSetter | A function/lambda that updates the map being represented accordingly, given a type T and position to which it was set. |
Remarks
This constructor is useful if the width and height of the map being represented may change -- one can provide 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.
LambdaSettableMapView(Int32, Int32, Func<Coord, T>, Action<Coord, T>)
Constructor. Takes the width and height of the map, and the functions to use to retrieve/set the value for a location.
Declaration
public LambdaSettableMapView(int width, int height, Func<Coord, T> valueGetter, Action<Coord, T> valueSetter)
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 function/lambda that returns the value of type T associated with the location it is given. |
System.Action<Coord, T> | valueSetter | A function/lambda that updates the map being represented accordingly, given a type T and position to which it was set. |
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/sets the "value" associated with that location, by calling the valueGetter/valueSetter functions provided at construction.
Declaration
public T this[Coord pos] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Coord | pos | Location to retrieve/set 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/sets the "value" associated with that location, by calling the valueGetter/valueSetter function passed in at construction.
Declaration
public T this[int index1D] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index1D | 1D-array-style index for location to get/set the 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/sets the "value" associated with that location, by calling the valueGetter/valueSetter functions provided at construction.
Declaration
public T this[int x, int y] { get; set; }
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 LambdaSettableMapView.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representation of the LambdaSettableMapView. |
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 LambdaSettableMapView. |
Remarks
This could be used, for example, on an LambdaSettableMapView of boolean values, to output '#' for false values, and '.' for true values.
ToString(Int32, Func<T, String>)
Prints the values in the LambdaSettableMapView, 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 LambdaSettableMapView. |
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.