Rogue: Savage Rats, a retro-themed dungeon crawler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
rogue-savage-rats/src/mightypork/gamecore/core/InitTaskConfig.java

80 lines
1.5 KiB

package mightypork.gamecore.core;
import mightypork.gamecore.config.Config;
import mightypork.utils.annotations.Stub;
import mightypork.utils.exceptions.IllegalValueException;
/**
* Initialize config. To apply this initializer, you must extend it. That
* ensures that the workdir initializer has already finished when the code is
* executed (such as resolving a file path for the config file).
*
* @author Ondřej Hruška (MightyPork)
*/
public abstract class InitTaskConfig extends InitTask {
/**
* Add a config with given alias
*
* @param alias config alias
* @param config config to add
*/
protected void addConfig(String alias, Config config)
{
if (app.configs.containsKey(alias)) {
throw new IllegalValueException("The alias is already used.");
}
app.configs.put(alias, config);
}
/**
* Initialize the main config.
*
* @return the main config.
*/
protected abstract Config buildConfig();
/**
* Initialize extra configs.<br>
* the addConfig() method can be used to register configs.
*/
@Stub
protected void buildExtraConfigs()
{
}
// locked uninitialized to encourage the use of the build* methods.
@Override
public final void init()
{
}
@Override
public final void run()
{
addConfig("main", buildConfig());
buildExtraConfigs();
}
@Override
public String getName()
{
return "config";
}
@Override
public String[] getDependencies()
{
return new String[] { "workdir" };
}
}