While I’m currently fully in the middle of implementing tetragon’s entity component system, to not let this blog hang for too long without news I’d like to introduce one of the utility classes which – even though part of the hexagonlib – is thoroughly used in tetragon’s console to output debugging information: The TabularText class!
The class sits in the util.text package and as the name suggests it provides text in tabular form or to put it differently, as a table, for example like the following…
ID DEF.ID COMP.COUNT FAMILY.ID --------------------------------------------- entity1 worldSpaceCL 1 family0 entity10 cellBarn4 1 family1 entity11 cellHouse1 1 family1 entity12 cellHouse2 1 family1 entity13 cellHouse3 1 family1
The class is used by specifying a fixed number of columns and a couple of other optional parameters as well as an optional header row and then data rows are added with the add() method which takes an Array that contains the text of one row, divided into columns. Like this the add() method is typically used inside a loop to feed a number of rows to the tabular text instance. Once all rows have been added the full table can be obtained with either toString() or with the text getter. The class constructor signature looks like this:
TabularText(columns:int, sort:Boolean = false, div:String = null, fill:String = null, rowLeading:String = null, colMaxLength:int = 0, header:Array = null)
Many CLI commands in tetragon utilize the TabularText class to list data in a table-like layout so that the output is easier to read than as it would be in an unformatted chunk of text.
The following method is from the ResourceIndex class and gives a good example on how to make use of the TabularText class.
/**
* Returns a string dump of all mapped resource package files.
*/
public function dumpPackageList():String
{
var t:TabularText = new TabularText(2, true, " ", null, " ", 0, ["ID", "PATH"]);
for (var id:String in _packageFiles)
{
t.add([id, _packageFiles[id]]);
}
return toString() + ": Resource Package Filesn" + t;
}
If you encounter any methods in tetragon’s API that are named dump() or dumpSomething() then you can be almost sure to expect some text output that is formatted by TabularText.
TabularText API docs: help.hexagonstar.com/hexagonlib/com/hexagonstar/util/string/TabularText.html
