Class LambdaTranslationMap<T1, T2>
A simple TranslationMap<T1, T2> implementation that allows you to provide a function/lambda at construction to use as the TranslateGet implementation. For a version offering "set" functionality, see LambdaSettableTranslationMap<T1, T2>.
Implements
Inherited Members
Namespace: GoRogue.MapViews
Assembly: GoRogue.dll
Syntax
public sealed class LambdaTranslationMap<T1, T2> : TranslationMap<T1, T2>, IMapView<T2>
Type Parameters
Name | Description |
---|---|
T1 | The type of your underlying data. |
T2 | The type of the data being exposed to the algorithm. |
Remarks
If you have a view that simply exposes a simple property of your underlying data, it can be tedious to write a TranslationMap<T1, T2> implementation for all of them. This class simplifies that task by letting you just provide the translation method as a function/lambda, without needing to build the rest of the class infrastructure.
Constructors
| Improve this Doc View SourceLambdaTranslationMap(IMapView<T1>, Func<T1, T2>)
Constructor. Takes an existing map view to create a view from and a getter function taking only a value of type T1.
Declaration
public LambdaTranslationMap(IMapView<T1> baseMap, Func<T1, T2> getter)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T1> | baseMap | Your underlying map data. |
System.Func<T1, T2> | getter | The TranslateGet implementation. |
Remarks
If a position is also needed to perform the translation, an overload is provided taking a corresponding function.
LambdaTranslationMap(IMapView<T1>, Func<Coord, T1, T2>)
Constructor. Takes an existing map view to create a view from and a getter function taking a value of type T1 and its corresponding position.
Declaration
public LambdaTranslationMap(IMapView<T1> baseMap, Func<Coord, T1, T2> getter)
Parameters
Type | Name | Description |
---|---|---|
IMapView<T1> | baseMap | Your underlying map data. |
System.Func<Coord, T1, T2> | getter | The TranslateGet implementation. |
Methods
| Improve this Doc View SourceTranslateGet(Coord, T1)
Translates your map data into the view type by calling the getter function specified in the class constructor.
Declaration
protected override T2 TranslateGet(Coord position, T1 value)
Parameters
Type | Name | Description |
---|---|---|
Coord | position | Position corresponding to given data value of your map. |
T1 | value | The data value from your map. |
Returns
Type | Description |
---|---|
T2 | A value of the mapped data type (via the getter specified in the class constructor). |