Compare commits
1
Commits
1.0.3-beta
...
1.0.4-beta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e9eac06fc |
+1
-1
@@ -8,7 +8,7 @@ yarn_mappings=1.16.5+build.5
|
||||
loader_version=0.11.2
|
||||
|
||||
# Mod Properties
|
||||
mod_version=1.0.3
|
||||
mod_version=1.0.4
|
||||
maven_group=draylar
|
||||
archives_base_name=omega-config
|
||||
|
||||
|
||||
@@ -147,7 +147,9 @@ public class OmegaConfig {
|
||||
lines.forEach(str -> res.append(String.format("%s%n", str)));
|
||||
|
||||
try {
|
||||
Files.write(getConfigPath(instance), res.toString().getBytes());
|
||||
Path configPath = getConfigPath(instance);
|
||||
configPath.toFile().getParentFile().mkdirs();
|
||||
Files.write(configPath, res.toString().getBytes());
|
||||
} catch (IOException ioException) {
|
||||
LOGGER.error(ioException);
|
||||
LOGGER.info(String.format("Write error, using default values for config %s.", configClass.toString()));
|
||||
@@ -199,7 +201,7 @@ public class OmegaConfig {
|
||||
}
|
||||
|
||||
public static Path getConfigPath(Config config) {
|
||||
return Paths.get(FabricLoader.getInstance().getConfigDir().toString(), String.format("%s.json", config.getName()));
|
||||
return Paths.get(FabricLoader.getInstance().getConfigDir().toString(), config.getDirectory(), String.format("%s.%s", config.getName(), config.getExtension()));
|
||||
}
|
||||
|
||||
public static boolean configExists(Config config) {
|
||||
|
||||
@@ -78,7 +78,33 @@ public interface Config {
|
||||
return null;
|
||||
}
|
||||
|
||||
default boolean hasMenu() {
|
||||
return true;
|
||||
/**
|
||||
* Returns the file extension of this config.
|
||||
*
|
||||
* <p>
|
||||
* The file extension is used while serializing this config to a local file.
|
||||
* The primary use-case of switching this would be supporting existing config files
|
||||
* when porting from other json5 config libraries.
|
||||
*
|
||||
* @return the file extension of this config
|
||||
*/
|
||||
default String getExtension() {
|
||||
return "json";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the directory of this config, assuming the base directory is the instance config directory.
|
||||
*
|
||||
* <p>
|
||||
* By default, a config such as 'my_config' will appear at /config/my_config.json.
|
||||
* If this method specifies a directory, such as 'configurations',
|
||||
* the config file will appear at /config/configurations/my_config.json.
|
||||
*
|
||||
* Nested directories can be specified by using a string such as 'configurations/client'.
|
||||
*
|
||||
* @return the directory of this config
|
||||
*/
|
||||
default String getDirectory() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package draylar.omegatest;
|
||||
|
||||
import draylar.omegaconfig.api.Config;
|
||||
|
||||
public class NestedConfig implements Config {
|
||||
|
||||
public boolean test = false;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "nested";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDirectory() {
|
||||
return "test";
|
||||
}
|
||||
}
|
||||
@@ -123,4 +123,9 @@ public class NewTestConfig implements Config {
|
||||
public int killer_bunny_castle_seperation = 25;
|
||||
public int killer_bunny_castle_spacing = 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExtension() {
|
||||
return "json5";
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ public class OmegaTestMain implements ModInitializer {
|
||||
|
||||
public static final TestConfig CONFIG = OmegaConfig.register(TestConfig.class);
|
||||
public static final NewTestConfig MO_CONFIG = OmegaConfig.register(NewTestConfig.class);
|
||||
public static final NestedConfig NESTED = OmegaConfig.register(NestedConfig.class);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
|
||||
Reference in New Issue
Block a user