Show / Hide Table of Contents

Class ArrayMap<T>

Implementation of the ISettableMapView<T> interface that uses a 1D array to store data.

Inheritance
System.Object
ArrayMap<T>
Implements
ISettableMapView<T>
IMapView<T>
System.ICloneable
System.IEquatable<ArrayMap<T>>
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
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 Source

ArrayMap(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 existingArray.

| Improve this Doc View Source

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 Source

Height

The height of the map.

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

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

Width

The width of the map.

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

Methods

| Improve this Doc View Source

Clone()

Performs deep copy of array map.

Declaration
public object Clone()
Returns
Type Description
System.Object

The cloned ArrayMap.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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

GetHashCode()

Returns a hash-value for this object.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32
Overrides
System.Object.GetHashCode()
| Improve this Doc View Source

SetToDefault()

Sets each element in the ArrayMap to the default for type T.

Declaration
public void SetToDefault()
| Improve this Doc View Source

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

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.

| Improve this Doc View Source

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 Source

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

| Improve this Doc View Source

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[]
| Improve this Doc View Source

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.

Implements

ISettableMapView<T>
IMapView<T>
System.ICloneable
System.IEquatable<T>

Extension Methods

Utility.Yield<T>(T)
IMapViewExtensions.ApplyOverlay<T>(ISettableMapView<T>, IMapView<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