Class ArrayMap<T>
Implementation of the ISettableMapView<T> interface that uses a 1D array to store data.
Inheritance
Inherited Members
Namespace: GoRogue.MapViews
Assembly: GoRogue.dll
Syntax
[Serializable]
public sealed class ArrayMap<T> : ISettableMapView<T>, IMapView<T>, ICloneable, IEquatable<ArrayMap<T>>
Type Parameters
| Name | Description |
|---|---|
| T | The type of value being stored. |
Remarks
An ArrayMap<T> can be implicitly converted to its underlying 1D array, which allows exposing that array to code that works with 1D arrays. Modifications in the array appear in the map view as well.
If you need a 2D array instead of 1D, then you should use ArrayMap2D<T> instead.
Constructors
| Improve this Doc View SourceArrayMap(T[], Int32)
Constructor. Takes an existing 1D array to use as the underlying array, and the width of the 2D area represented by that array.
Declaration
public ArrayMap(T[] existingArray, int width)
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | existingArray | Existing 1D array to use as the underlying array. |
| System.Int32 | width | The width of the 2D area represented by |
ArrayMap(Int32, Int32)
Constructor. Takes width and height of array.
Declaration
public ArrayMap(int width, int height)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | width | Width of array. |
| System.Int32 | height | Height of array. |
Properties
| Improve this Doc View SourceHeight
The height of the map.
Declaration
public int Height { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Item[Coord]
Given a position, returns/sets the "value" associated with that location.
Declaration
public T this[Coord pos] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| Coord | pos | Location to get/set the value for. |
Property Value
| Type | Description |
|---|---|
| T | The "value" associated with the provided location. |
Item[Int32]
Returns/sets the value associated with the given index in the underlying array.
Declaration
public T this[int index1D] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index1D | 1D index of location to retrieve the "value" for. |
Property Value
| Type | Description |
|---|---|
| T | The "value" associated with the given location. |
Item[Int32, Int32]
Given an X and Y value, returns/sets the "value" associated with that location.
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. |
Width
The width of the map.
Declaration
public int Width { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Methods
| Improve this Doc View SourceClone()
Performs deep copy of array map.
Declaration
public object Clone()
Returns
| Type | Description |
|---|---|
| System.Object | The cloned ArrayMap. |
Equals(ArrayMap<T>)
Compares the current ArrayMap to the one given.
Declaration
public bool Equals(ArrayMap<T> other)
Parameters
| Type | Name | Description |
|---|---|---|
| ArrayMap<T> | other |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the given ArrayMap<T> with a reference to the same underlying array, false otherwise. |
Equals(Object)
Compares the current ArrayMap to the object given.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the given object is an ArrayMap<T> with a reference to the same underlying array, false otherwise. |
Overrides
GetHashCode()
Returns a hash-value for this object.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 |
Overrides
SetToDefault()
Sets each element in the ArrayMap to the default for type T.
Declaration
public void SetToDefault()
ToString()
Returns a string representation of the 2D array.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | A string representation of the 2D array. |
Overrides
ToString(Func<T, String>)
Returns a string representation of the map data, using elementStringifier
to determine what string represents which 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 map data. |
Remarks
This could be used, for example, on an ArrayMap of boolean values, to output '#' for false values, and '.' for true values.
ToString(Int32, Func<T, String>)
Prints the values in the ArrayMap, 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 ArrayMap. |
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.
Operators
| Improve this Doc View SourceEquality(ArrayMap<T>, ArrayMap<T>)
Compares the two ArrayMap instances.
Declaration
public static bool operator ==(ArrayMap<T> lhs, ArrayMap<T> rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| ArrayMap<T> | lhs | |
| ArrayMap<T> | rhs |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the two given ArrayMap<T> instances have a reference to the same underlying array, false otherwise. |
Implicit(ArrayMap<T> to T[])
Allows implicit conversion to 1D array.
Declaration
public static implicit operator T[](ArrayMap<T> arrayMap)
Parameters
| Type | Name | Description |
|---|---|---|
| ArrayMap<T> | arrayMap | ArrayMap to convert. |
Returns
| Type | Description |
|---|---|
| T[] |
Inequality(ArrayMap<T>, ArrayMap<T>)
Compares the two ArrayMap instances.
Declaration
public static bool operator !=(ArrayMap<T> lhs, ArrayMap<T> rhs)
Parameters
| Type | Name | Description |
|---|---|---|
| ArrayMap<T> | lhs | |
| ArrayMap<T> | rhs |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if the two given ArrayMap<T> instances do NOT have a reference to the same underlying array, false otherwise. |