Anvil
Anvil.API.TwoDimArray< T > Class Template Reference

A two dimensional array data resource. More...

+ Inheritance diagram for Anvil.API.TwoDimArray< T >:
+ Collaboration diagram for Anvil.API.TwoDimArray< T >:

Public Member Functions

bool? GetBool (int rowIndex, int columnIndex)
 Gets the specified boolean value. More...
 
bool? GetBool (int rowIndex, string columnName)
 Gets the specified boolean value. More...
 
int GetColumnIndex (string columnName)
 Gets the index of the column with the specified name/label. More...
 
T? GetEnum< T > (int rowIndex, int columnIndex)
 Gets the specified enum value value. More...
 
T? GetEnum< T > (int rowIndex, string columnName)
 Gets the specified StrRef value. More...
 
IEnumerator< T > GetEnumerator ()
 
float? GetFloat (int rowIndex, int columnIndex)
 Gets the specified float value. More...
 
float? GetFloat (int rowIndex, string columnName)
 Gets the specified float value. More...
 
int? GetInt (int rowIndex, int columnIndex)
 Gets the specified int value. More...
 
int? GetInt (int rowIndex, string columnName)
 Gets the specified int value. More...
 
GetRow (int rowIndex)
 Gets the row at the specified index. More...
 
string? GetString (int rowIndex, int columnIndex)
 Gets the specified string value. More...
 
string? GetString (int rowIndex, string columnName)
 Gets the specified string value. More...
 
StrRefGetStrRef (int rowIndex, int columnIndex)
 Gets the specified StrRef value. More...
 
StrRefGetStrRef (int rowIndex, string columnName)
 Gets the specified StrRef value. More...
 
TwoDimArray< T >? GetTable< T > (int rowIndex, int columnIndex)
 Interprets the specified value as a table name, and returns the associated table. More...
 
TwoDimArray< T >? GetTable< T > (int rowIndex, string columnName)
 Interprets the specified value as a table name, and returns the associated table. More...
 
T? GetTableEntry< T > (int rowIndex, int columnIndex, TwoDimArray< T > table)
 Interprets the specified value as a table index, and returns the associated table entry. More...
 
T? GetTableEntry< T > (int rowIndex, string columnName, TwoDimArray< T > table)
 Interprets the specified value as a table index, and returns the associated table entry. More...
 
Vector3? GetVector3 (int rowIndex, int columnIndexX, int columnIndexY, int columnIndexZ)
 Gets the specified Vector3 value. More...
 
Vector3? GetVector3 (int rowIndex, string columnNameX, string columnNameY, string columnNameZ)
 Gets the specified Vector3 value. More...
 

Properties

int ColumnCount [get]
 Gets the number of columns in this 2da. More...
 
string[] Columns [get]
 Gets the column labels/names for this 2da. More...
 
int Count [get]
 
int RowCount [get]
 Gets the number of rows in this 2da. More...
 
IReadOnlyList< T > Rows [get]
 Gets a read-only list of all rows in this 2da. More...
 
this[int rowIndex] [get]
 

Detailed Description

A two dimensional array data resource.

A two dimensional array resource, with a decoded row type.

Examples

/*
* Define a implementation to deserialize "xptable.2da", and use this class to determine how much XP is remaining until the next level.
*/
using System.Linq;
using Anvil.API;
namespace NWN.Anvil.Samples
{
// This is the deserialization class for this specific type of 2da.
// We can implement our own helper functions here that operate on the 2da data, and cache it.
public sealed class ExpTableEntry : ITwoDimArrayEntry
{
public int Level { get; private set; }
public int XP { get; private set; }
// RowIndex is already populated externally, and we do not need to assign it in InterpretEntry.
public int RowIndex { get; init; }
// InterpretEntry is where we populate our entry properties (Level & XP) with the correct data.
public void InterpretEntry(TwoDimArrayEntry entry)
{
Level = entry.GetInt("Level").GetValueOrDefault(0);
XP = entry.GetInt("XP").GetValueOrDefault(0);
}
}
[ServiceBinding(typeof(XPReportService))]
public class XPReportService
{
// The TwoDimArray is created here.
// ExpTableEntry (the type above) is passed in as a type parameter to be used to create our row data from exptable.2da.
private readonly TwoDimArray<ExpTableEntry> expTable = NwGameTables.GetTable<ExpTableEntry>("exptable.2da")!;
public XPReportService()
{
NwModule.Instance.OnClientEnter += OnClientEnter;
}
private void OnClientEnter(ModuleEvents.OnClientEnter onClientEnter)
{
NwPlayer player = onClientEnter.Player;
NwCreature? creature = player.ControlledCreature;
if (creature == null)
{
return;
}
int nextLevel = GetLevelFromXp(creature.Xp) + 1;
if (nextLevel > MaxLevel)
{
return;
}
player.SendServerMessage($"Next level up: {GetXpForLevel(nextLevel) - creature.Xp}");
}
public int MaxLevel => expTable[^1].Level;
public int GetXpForLevel(int level)
{
return expTable.First(entry => entry.Level == level).XP;
}
public int GetLevelFromXp(int xp)
{
int level = 1;
foreach (ExpTableEntry entry in expTable.Rows)
{
if (entry.XP > xp)
{
break;
}
level = entry.Level;
}
return level;
}
}
}
Template Parameters
TThe row/entry type to decode the array.
Type Constraints
T :class 
T :ITwoDimArrayEntry 
T :new() 

Member Function Documentation

◆ GetBool() [1/2]

bool? Anvil.API.TwoDimArray< T >.GetBool ( int  rowIndex,
int  columnIndex 
)
inline

Gets the specified boolean value.

Parameters
rowIndexThe index of the row to query.
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.

◆ GetBool() [2/2]

bool? Anvil.API.TwoDimArray< T >.GetBool ( int  rowIndex,
string  columnName 
)
inline

Gets the specified boolean value.

Parameters
rowIndexThe index of the row to query.
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.

◆ GetColumnIndex()

int Anvil.API.TwoDimArray< T >.GetColumnIndex ( string  columnName)
inline

Gets the index of the column with the specified name/label.

Parameters
columnNameThe column to lookup.
Returns
The zero-based index of the column if found, otherwise -1.

◆ GetEnum< T >() [1/2]

T? Anvil.API.TwoDimArray< T >.GetEnum< T > ( int  rowIndex,
int  columnIndex 
)
inline

Gets the specified enum value value.

Parameters
rowIndexThe index of the row to query.
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.
Type Constraints
T :struct 
T :Enum 

◆ GetEnum< T >() [2/2]

T? Anvil.API.TwoDimArray< T >.GetEnum< T > ( int  rowIndex,
string  columnName 
)
inline

Gets the specified StrRef value.

Parameters
rowIndexThe index of the row to query.
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.
Type Constraints
T :struct 
T :Enum 

◆ GetFloat() [1/2]

float? Anvil.API.TwoDimArray< T >.GetFloat ( int  rowIndex,
int  columnIndex 
)
inline

Gets the specified float value.

Parameters
rowIndexThe index of the row to query.
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.

◆ GetFloat() [2/2]

float? Anvil.API.TwoDimArray< T >.GetFloat ( int  rowIndex,
string  columnName 
)
inline

Gets the specified float value.

Parameters
rowIndexThe index of the row to query.
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.

◆ GetInt() [1/2]

int? Anvil.API.TwoDimArray< T >.GetInt ( int  rowIndex,
int  columnIndex 
)
inline

Gets the specified int value.

Parameters
rowIndexThe index of the row to query.
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.

◆ GetInt() [2/2]

int? Anvil.API.TwoDimArray< T >.GetInt ( int  rowIndex,
string  columnName 
)
inline

Gets the specified int value.

Parameters
rowIndexThe index of the row to query.
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.

◆ GetRow()

T Anvil.API.TwoDimArray< T >.GetRow ( int  rowIndex)
inline

Gets the row at the specified index.

Parameters
rowIndexThe row index.

◆ GetString() [1/2]

string? Anvil.API.TwoDimArray< T >.GetString ( int  rowIndex,
int  columnIndex 
)
inline

Gets the specified string value.

Parameters
rowIndexThe index of the row to query.
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.

◆ GetString() [2/2]

string? Anvil.API.TwoDimArray< T >.GetString ( int  rowIndex,
string  columnName 
)
inline

Gets the specified string value.

Parameters
rowIndexThe index of the row to query.
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.

◆ GetStrRef() [1/2]

StrRef? Anvil.API.TwoDimArray< T >.GetStrRef ( int  rowIndex,
int  columnIndex 
)
inline

Gets the specified StrRef value.

Parameters
rowIndexThe index of the row to query.
columnIndexThe index of the column to query.
Returns
The associated value. null if no value is set.

◆ GetStrRef() [2/2]

StrRef? Anvil.API.TwoDimArray< T >.GetStrRef ( int  rowIndex,
string  columnName 
)
inline

Gets the specified StrRef value.

Parameters
rowIndexThe index of the row to query.
columnNameThe name/label of the column to query.
Returns
The associated value. null if no value is set.

◆ GetTable< T >() [1/2]

TwoDimArray<T>? Anvil.API.TwoDimArray< T >.GetTable< T > ( int  rowIndex,
int  columnIndex 
)
inline

Interprets the specified value as a table name, and returns the associated table.

Parameters
rowIndexThe index of the row to query.
columnIndexThe index of the column to query.
Template Parameters
TThe type of table entry.
Returns
The associated value, otherwise null.
Type Constraints
T :class 
T :ITwoDimArrayEntry 
T :new() 

◆ GetTable< T >() [2/2]

TwoDimArray<T>? Anvil.API.TwoDimArray< T >.GetTable< T > ( int  rowIndex,
string  columnName 
)
inline

Interprets the specified value as a table name, and returns the associated table.

Parameters
rowIndexThe index of the row to query.
columnNameThe name/label of the column to query.
Template Parameters
TThe type of table entry.
Returns
The associated value, otherwise null.
Type Constraints
T :class 
T :ITwoDimArrayEntry 
T :new() 

◆ GetTableEntry< T >() [1/2]

T? Anvil.API.TwoDimArray< T >.GetTableEntry< T > ( int  rowIndex,
int  columnIndex,
TwoDimArray< T >  table 
)
inline

Interprets the specified value as a table index, and returns the associated table entry.

Parameters
rowIndexThe index of the row to query.
columnIndexThe index of the column to query.
tableThe table that should be used to resolve the value.
Template Parameters
TThe type of table entry.
Returns
The associated value, otherwise the default array entry value (typically null)
Type Constraints
T :class 
T :ITwoDimArrayEntry 
T :new() 

◆ GetTableEntry< T >() [2/2]

T? Anvil.API.TwoDimArray< T >.GetTableEntry< T > ( int  rowIndex,
string  columnName,
TwoDimArray< T >  table 
)
inline

Interprets the specified value as a table index, and returns the associated table entry.

Parameters
rowIndexThe index of the row to query.
columnNameThe name/label of the column to query.
tableThe table that should be used to resolve the value.
Template Parameters
TThe type of table entry.
Returns
The associated value, otherwise the default array entry value (typically null)
Type Constraints
T :class 
T :ITwoDimArrayEntry 
T :new() 

◆ GetVector3() [1/2]

Vector3? Anvil.API.TwoDimArray< T >.GetVector3 ( int  rowIndex,
int  columnIndexX,
int  columnIndexY,
int  columnIndexZ 
)
inline

Gets the specified Vector3 value.

Parameters
rowIndexThe index of the row to query.
columnIndexXThe index of the column containing the x component of the vector.
columnIndexYThe index of the column containing the y component of the vector.
columnIndexZThe index of the column containing the z component of the vector.
Returns
The associated value. null if no value is set.

◆ GetVector3() [2/2]

Vector3? Anvil.API.TwoDimArray< T >.GetVector3 ( int  rowIndex,
string  columnNameX,
string  columnNameY,
string  columnNameZ 
)
inline

Gets the specified Vector3 value.

Parameters
rowIndexThe index of the row to query.
columnNameXThe name/label of the column containing the x component of the vector.
columnNameYThe name/label of the column containing the y component of the vector.
columnNameZThe name/label of the column containing the z component of the vector.
Returns
The associated value. null if no value is set.

Property Documentation

◆ ColumnCount

int Anvil.API.TwoDimArray< T >.ColumnCount
get

Gets the number of columns in this 2da.

◆ Columns

string [] Anvil.API.TwoDimArray< T >.Columns
get

Gets the column labels/names for this 2da.

◆ RowCount

int Anvil.API.TwoDimArray< T >.RowCount
get

Gets the number of rows in this 2da.

◆ Rows

IReadOnlyList<T> Anvil.API.TwoDimArray< T >.Rows
get

Gets a read-only list of all rows in this 2da.


The documentation for this class was generated from the following files: