Show / Hide Table of Contents

Class TranslationMap<T1, T2>

Map view class capable of taking complex data and providing a simpler view of it. For a version that provides "set" functionality, see SettableTranslationMap<T1, T2>.

Inheritance
System.Object
TranslationMap<T1, T2>
LambdaTranslationMap<T1, T2>
Implements
IMapView<T2>
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 abstract class 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

Many GoRogue algorithms work on a IMapView of a simple data type, which is likely to be a poor match for your game's actual map data. For example, map generation works with bools, and SenseMap calculation with doubles, while your map data may model each map cell as a class or struct containing many different member values. This class allows you to build descendant classes that override the TranslateGet method(s) for simple mapping, or the "this" indexers if you need full access to the underlying data for context, in order to present a simplified view of your data to an algorithm without having to create the large amount of duplicate code associated with multiple ISettableMapView instances that all extract data from a Cell or Tile class.

If your TranslateGet implementation is simple, or you do not want to create a full subclass, you should look at LambdaTranslationMap<T1, T2> instead.

Constructors

| Improve this Doc View Source

TranslationMap(IMapView<T1>)

Constructor. Takes an existing map view to create a view from.

Declaration
protected TranslationMap(IMapView<T1> baseMap)
Parameters
Type Name Description
IMapView<T1> baseMap

Your underlying map data.

Properties

| Improve this Doc View Source

BaseMap

The underlying map.

Declaration
public IMapView<T1> BaseMap { get; }
Property Value
Type Description
IMapView<T1>
| Improve this Doc View Source

Height

The height of the underlying map.

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

Item[Coord]

Given a position, translates and returns the "value" associated with that position. the other indexers call this indexer for its functionality, so overriding this functionality also changes those overloads.

Declaration
public virtual T2 this[Coord pos] { get; }
Parameters
Type Name Description
Coord pos

Location to get the value for.

Property Value
Type Description
T2

The translated "value" associated with the provided location.

| 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. This function calls Item[Coord], so override that indexer to change functionality.

Declaration
public T2 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
T2

The "value" associated with the given location, according to the translation function.

| Improve this Doc View Source

Item[Int32, Int32]

Given an X and Y value, translates and returns the "value" associated with that location. This function calls this[Coord pos], so override that indexer to change functionality.

Declaration
public T2 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
T2

The translated "value" associated with that location.

| Improve this Doc View Source

Width

The width of the underlying map.

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

Methods

| Improve this Doc View Source

ToString()

Returns a string representation of the TranslationMap.

Declaration
public override string ToString()
Returns
Type Description
System.String

A string representation of the TranslationMap.

Overrides
System.Object.ToString()
| Improve this Doc View Source

ToString(Func<T2, String>)

Returns a string representation of the map view, using elementStringifier to determine what string represents each value.

Declaration
public string ToString(Func<T2, string> elementStringifier)
Parameters
Type Name Description
System.Func<T2, System.String> elementStringifier

Function determining the string representation of each element.

Returns
Type Description
System.String

A string representation of the TranslationMap.

Remarks

This could be used, for example, on an TranslationMap of boolean values, to output '#' for false values, and '.' for true values.

| Improve this Doc View Source

ToString(Int32, Func<T2, String>)

Prints the values in the map view, using the function specified to turn elements into strings, and using the "field length" specified.

Declaration
public string ToString(int fieldSize, Func<T2, 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<T2, 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 TranslationMap.

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.

| Improve this Doc View Source

TranslateGet(T1)

Translates your map data into the view type using just the map data value itself. If you need the location as well to perform the translation, implement TranslateGet(Coord, T1) instead.

Declaration
protected virtual T2 TranslateGet(T1 value)
Parameters
Type Name Description
T1 value

The data value from your map.

Returns
Type Description
T2

A value of the mapped data type

| Improve this Doc View Source

TranslateGet(Coord, T1)

Translates your map data into the view type using the position and the map data value. If you need only the data value to perform the translation, implement TranslateGet(T1) instead.

Declaration
protected virtual T2 TranslateGet(Coord position, T1 value)
Parameters
Type Name Description
Coord position

The position of the given data value in your map.

T1 value

The data value from your map.

Returns
Type Description
T2

A value of the mapped data type

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