Changes in configuration

In Herculeum I originally had a single class called Configuration that holds configuration for the system and knows how to set it up. It was soon clear that the class would be gigantic in proportions, even when loading of some of the stuff was in other classes. I made little code-pushing today and break off configuration of levels into separate functions in appropriately named modules ( and

def init_level(rng, item_generator, creature_generator, level_size):

This function creates configuration for a level (or multiple similarly themed levels).

Calling this identically named functions from different modules started looking like repeating myself. Also, in order to create a new configuration I would have to write the configuration and add call to it in the main configuration class. I wanted to avoid that and added this little piece of code in the original configuration class:

config_names = filter(lambda x: x[0] != '_',
config_modules = map(lambda x: getattr(pyherc.config.levels, x),
configurators = map(lambda x: getattr(x, 'init_level'),
for configurator in configurators:

Now I can add new level configurations simply by adding a module with init_level function and placing it in pyherc.config.levels – folder. Building your system to be easily extendable without need to be modified is usually a good thing. Of course one can not anticipate all the changes of future, so some common sense and good judgement is required (as always with software development).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s