Skip to content

TableValues

namespace Griff.Scenes;
public sealed class TableValues : Component

Gives its entity’s other components their values from a row of a table, with no code: an enemy’s Health and Damage from the Enemies table’s Slime row. Sets says which properties take which columns, one a line (Health.Max = Health); left empty, every property named like a column takes it (a column called “Speed” sets every Speed, one called “Health.Max” sets that one). The values are set as the entity starts in the game (spawned ones straight away), and again whenever the row changes while the game runs, so balancing a table while playing shows at once. A row renamed in the Tables panel is still found by its old name; a table or row that isn’t there is flagged in the Inspector, a line of Sets naming a property the entity hasn’t got is noted above its fields, and anything missing (a column too) is said in Output as the game starts.

This is a component: its saved properties are on its component page.

public string? Applied { get; set; }

Set by the game: which values it set last, so a rewind (which brings back what they were) doesn’t set them again, rolling new dice, unless the row has changed since. Leave it be.

public string? PickedRow { get; }

The row SavedRow picked as the game last set the values; null for none. Set by the game.

public string? Row { get; set; }

The row they come from, e.g. “Slime”. Empty takes the row named like the entity, so a Slime prefab finds the Slime row.

public string? RowName { get; }

The row it reads: the one SavedRow picked, else Row, or the entity’s name when that’s empty.

public string? SavedRow { get; set; }

A name in the game’s save data (Game.SaveData) holding the row to read instead, e.g. “hero”: a menu’s Choice with Save As “hero” picks the class the hero plays. With nothing saved under it, Row is read.

public IReadOnlyList<string> Sets { get; set; }

Which property takes which column, one a line: Health.Max = Health (a component’s property, then the column), Speed (every Speed on the entity, from the Speed column) or Patrol.Speed = Walk Speed. A number property given dice rolls them once, as the entity starts. Empty sets every property named like a column.

public string? Table { get; set; }

The table the values come from, e.g. “Enemies” (Assets/Tables/Enemies.table).

public IReadOnlyList<string> Apply(TableSet tables, string session)

Sets the properties from the row, unless they were set from it as it is already (Applied, with session telling one game from another). Returns what went wrong, if anything: a table, row or column that isn’t there, or a value that doesn’t fit its property.

public static object? Convert(TableValue value, Type type)

value as a property of type takes it: a number, whole number (rounded) or yes/no as they are; dice rolled for a number, written out for text; a choice for an enum by its name; text that reads as a color (“#FF004D”) for a color; for a list, the text split on commas and line breaks, trimmed, with empty pieces dropped.

public IReadOnlyList<string> LineProblems()

The lines of Sets that name a component or property its entity hasn’t got, each said in words.

public IReadOnlyList<TableValues.Line> Lines()

Sets, each line read; blank lines and those starting with # are left out.

public IReadOnlyList<string> Settable()

What a line of Sets can set on its entity: each property of its other components that takes a value from a table (a number, whole number, true or false, name, choice, color or list of names), as “Health.Max”.

public override string? SetupNote()

What Sets does, or which of its lines name a component or property the entity hasn’t got.

public IReadOnlyList<TableValues.Target> Targets(IReadOnlyList<string>? columns)

As Targets, knowing only the names of the table’s columns.

public IReadOnlyList<TableValues.Target> Targets(Table? table, ICollection<string>? problems = null)

The properties it sets and the columns they take: as Sets says, or with it empty, every property of the entity’s other components named like one of table’s columns. Lines that match nothing are in problems.

public override bool Uses(string property)
public static string WriteLine(string target, string? column)

A line of Sets written: “Health.Max = Health”, or just “Speed” when the column’s named like the property.