Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filename and subdirectory overrides to Config class annotation #33

Merged
merged 4 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/java/com/gtnewhorizon/gtnhlib/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
*/
String category() default "general";

/**
* The subdirectory of the config directory to use. Defaults to none (config/). If you want to use a subdirectory,
* you must specify it as a relative path (e.g. "myMod").
*/
String configSubDirectory();

/**
* The name of the configuration file. Defaults to the modid. The file extension (.cfg) is added automatically.
*/
String filename();

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.TYPE })
@interface LangKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,17 @@ public static void registerConfig(Class<?> configClass) throws ConfigException {
val category = Optional.of(cfg.category().trim()).map((cat) -> cat.length() == 0 ? null : cat).orElseThrow(
() -> new ConfigException("Config class " + configClass.getName() + " has an empty category!"));
val rawConfig = configs.computeIfAbsent(cfg.modid(), (ignored) -> {
val c = new Configuration(configDir.resolve(cfg.modid() + ".cfg").toFile());
Path newConfigDir = configDir;
if (cfg.configSubDirectory() != null) {
newConfigDir = newConfigDir.resolve(cfg.configSubDirectory());
}
String fileName;
if (cfg.fileName() != null) {
fileName = cfg.fileName();
Caedis marked this conversation as resolved.
Show resolved Hide resolved
} else {
fileName = cfg.modid();
}
val c = new Configuration(newConfigDir.resolve(fileName + ".cfg").toFile());
c.load();
return c;
});
Expand Down
Loading