-
Notifications
You must be signed in to change notification settings - Fork 88
SpireConfig
Alchyr edited this page Dec 2, 2020
·
3 revisions
SpireConfig
provides a simple way for mods to store preferences. It uses the java.util.Properties
class as its back end and stores files outside the Slay the Spire installation directory, in the user preferences directory.
-
Windows:
%LOCALAPPDATA%\ModTheSpire\
-
Linux:
~/.config/ModTheSpire/
-
Mac:
~/Library/Preferences/ModTheSpire/
The two parameters for the SpireConfig
constructor are
- Mod Name: This is your mod's name, a subdirectory with this name will be created in the ModTheSpire directory and your config files will be stored in it.
- Config Name: This is the name of the config file, without the file extension.
SpireConfig config = new SpireConfig("MyMod", "config");
config.setInt("foo", 42);
config.save();
You can also pass a Properties
object to the SpireConfig
constructor to provide it default values. Default values aren't save to file, but are used if a key hasn't been set yet.
Properties defaults = new Properties();
defaults.setProperty("bar", "asdf");
SpireConfig config = new SpireConfig("MyMod", "config", defaults);
System.out.println(config.getString("bar")); // Prints "asdf"