The module configuration file in Umbra makes it possible to declare custom properties.
Since the name of those properties is not known by Umbra, we have to use some convoluted syntax :

floatParam { name="playerSpeed" value=8.0 }



would be more readable. This is because libtcod’s parser needs to know the structure syntax before parsing the file. That means that to be able to parse this file :

myStruct {

You need to declare the properties in your code like this :

TCODParserStruct *myStruct = parser.newStructure("myStruct");
myStruct->addProperty("someStringProperty", TCOD_TYPE_STRING, false);
myStruct->addProperty("someIntProperty", TCOD_TYPE_INT, false);

Or rather needed. I just updated it on svn to allow dynamic properties declaration. Just declare the structure in your code :

TCODParserStruct *myStruct = parser.newStructure("myStruct");

and you can directly parse this file (you still need to declare the properties type, but directly inside the file) :

myStruct {
   string someStringProperty="stringValue"
   int someIntProperty=5

All types are supported except value lists and custom types, with following syntax :

bool b=true
char c='r'
int i=4
float f=4.3
string s="foo"
color col=#FF6600
dice d="3d20"

You can also declare lists with the type[] syntax :

bool[] boolList = [ true, false ]
int[] intList = [3,4]

and so on..

WARNING ! That means that bool, char, int, float, color and dice can no longer be used as property name. They’re now keywords. If you were using such property names, you’ll have to rename them.

The consequence is that configuration when using Umbra is now the easiest in the world. Example of code inside the render function of a Umbra module :

TCODConsole::root->setForegroundColor( TCODColor ( 124,12,4 ) );

You want to make that color configurable ? Easy. Replace the code with this :

TCODConsole::root->setForegroundColor( getColorParam("myConfigurableColor") );

Then add the property in your module’s configuration :

module "myModule" {
     color myConfigurableColor = "124,12,4"

That’s it !

2 comments so far

Add Your Comment
  1. Holy crap, that’s brilliant!
    I’ll need to make a quick tip video about that ASAP!!!
    Oh, BTW, and colour name constants should be recognised by the parser as well – this way your custom colour would just be:
    color myConfigurableColor = darkerAzure

  2. Excellent! I was always wary of using the config module too heavily, due to some of the cumbersome syntax. This will make things extremely easy. Great work as always, jice 😉