Show / Hide Table of Contents

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
System.Object
LambdaMapView<T>
Implements
IMapView<T>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
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 Source

LambdaMapView(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.

| Improve this Doc View Source

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 Source

Height

The height of the map being represented.

Declaration
public int Height { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

Width

The width of the map being represented.

Declaration
public int Width { get; }
Property Value
Type Description
System.Int32

Methods

| Improve this Doc View Source

ToString()

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
System.Object.ToString()
| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

Implements

IMapView<T>

Extension Methods

Utility.Yield<T>(T)
IMapViewExtensions.Bounds<T>(IMapView<T>)
IMapViewExtensions.Contains<T>(IMapView<T>, Int32, Int32)
IMapViewExtensions.Contains<T>(IMapView<T>, Coord)
IMapViewExtensions.ExtendToString<T>(IMapView<T>, String, String, Func<T, String>, String, String, String, String)
IMapViewExtensions.ExtendToString<T>(IMapView<T>, Int32, String, String, Func<T, String>, String, String, String, String)
IMapViewExtensions.Positions<T>(IMapView<T>)
IMapViewExtensions.RandomItem<T>(IMapView<T>, IGenerator)
IMapViewExtensions.RandomItem<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, T, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IEnumerable<T>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, HashSet<T>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IGenerator, T[])
IMapViewExtensions.RandomPosition<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IGenerator)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX