Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c21e5ff3ff | ||
|
|
a6d2e3b1f8 | ||
|
|
0ff71f0a09 | ||
|
|
1b636fa0d8 | ||
|
|
1e3e886346 | ||
|
|
8b42f5a9c5 | ||
|
|
9e9eac06fc |
+3
-3
@@ -15,7 +15,7 @@ buildscript {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "fabric-loom" version "0.7-SNAPSHOT"
|
id "fabric-loom" version "0.8-SNAPSHOT"
|
||||||
id "maven-publish"
|
id "maven-publish"
|
||||||
id "java-library"
|
id "java-library"
|
||||||
}
|
}
|
||||||
@@ -207,8 +207,8 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(":omega-config-base")
|
implementation project(":omega-config-base")
|
||||||
compile project(":omega-config-gui")
|
implementation project(":omega-config-gui")
|
||||||
modRuntime "com.terraformersmc:modmenu:1.16.8"
|
modRuntime "com.terraformersmc:modmenu:1.16.8"
|
||||||
modCompileOnly "com.terraformersmc:modmenu:1.16.8"
|
modCompileOnly "com.terraformersmc:modmenu:1.16.8"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ yarn_mappings=1.16.5+build.5
|
|||||||
loader_version=0.11.2
|
loader_version=0.11.2
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.0.3
|
mod_version=1.0.5
|
||||||
maven_group=draylar
|
maven_group=draylar
|
||||||
archives_base_name=omega-config
|
archives_base_name=omega-config
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
jdk:
|
||||||
|
- openjdk16
|
||||||
@@ -85,14 +85,16 @@ public class OmegaConfig {
|
|||||||
writeConfig(configClass, object);
|
writeConfig(configClass, object);
|
||||||
REGISTERED_CONFIGURATIONS.add(object);
|
REGISTERED_CONFIGURATIONS.add(object);
|
||||||
return object;
|
return object;
|
||||||
} catch (IOException ioException) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(ioException);
|
LOGGER.error(e);
|
||||||
LOGGER.info(String.format("Read error, using default values for config %s.", configClass.toString()));
|
LOGGER.info(String.format("Encountered an error while reading %s config, falling back to default values.", config.getName()));
|
||||||
|
LOGGER.info(String.format("If this problem persists, delete the config file %s and try again.", config.getName() + "." + config.getExtension()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
throw new NoValidConstructorException();
|
throw new NoValidConstructorException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,7 +149,9 @@ public class OmegaConfig {
|
|||||||
lines.forEach(str -> res.append(String.format("%s%n", str)));
|
lines.forEach(str -> res.append(String.format("%s%n", str)));
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (IOException ioException) {
|
||||||
LOGGER.error(ioException);
|
LOGGER.error(ioException);
|
||||||
LOGGER.info(String.format("Write error, using default values for config %s.", configClass.toString()));
|
LOGGER.info(String.format("Write error, using default values for config %s.", configClass.toString()));
|
||||||
@@ -199,7 +203,7 @@ public class OmegaConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Path getConfigPath(Config config) {
|
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) {
|
public static boolean configExists(Config config) {
|
||||||
|
|||||||
@@ -78,7 +78,33 @@ public interface Config {
|
|||||||
return null;
|
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 "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile project(":omega-config-base")
|
implementation project(":omega-config-base")
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
package draylar.omegatest;
|
package draylar.omegatest;
|
||||||
|
|
||||||
import draylar.omegaconfig.OmegaConfig;
|
import draylar.omegaconfig.OmegaConfig;
|
||||||
|
import draylar.omegatest.config.ClassConfigTest;
|
||||||
|
import draylar.omegatest.config.NestedConfigTest;
|
||||||
|
import draylar.omegatest.config.StructuresConfigTest;
|
||||||
|
import draylar.omegatest.config.SimpleConfigTest;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
|
||||||
public class OmegaTestMain implements ModInitializer {
|
public class OmegaTestMain implements ModInitializer {
|
||||||
|
|
||||||
public static final TestConfig CONFIG = OmegaConfig.register(TestConfig.class);
|
public static final SimpleConfigTest CONFIG = OmegaConfig.register(SimpleConfigTest.class);
|
||||||
public static final NewTestConfig MO_CONFIG = OmegaConfig.register(NewTestConfig.class);
|
public static final StructuresConfigTest MO_CONFIG = OmegaConfig.register(StructuresConfigTest.class);
|
||||||
|
public static final NestedConfigTest NESTED = OmegaConfig.register(NestedConfigTest.class);
|
||||||
|
public static final ClassConfigTest CLASS = OmegaConfig.register(ClassConfigTest.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package draylar.omegatest.config;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ClassConfigTest implements Config {
|
||||||
|
|
||||||
|
public List<TestClass> l = Arrays.asList(
|
||||||
|
new TestClass(true, 1, "hello")
|
||||||
|
);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "class-config";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class TestClass {
|
||||||
|
public final boolean a;
|
||||||
|
public final int b;
|
||||||
|
public String c;
|
||||||
|
|
||||||
|
public TestClass(boolean a, int b, String c) {
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
this.c = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package draylar.omegatest.config;
|
||||||
|
|
||||||
|
import draylar.omegaconfig.api.Config;
|
||||||
|
|
||||||
|
public class NestedConfigTest implements Config {
|
||||||
|
|
||||||
|
public boolean test = false;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "nested";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDirectory() {
|
||||||
|
return "test";
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
-5
@@ -1,4 +1,4 @@
|
|||||||
package draylar.omegatest;
|
package draylar.omegatest.config;
|
||||||
|
|
||||||
import draylar.omegaconfig.api.Comment;
|
import draylar.omegaconfig.api.Comment;
|
||||||
import draylar.omegaconfig.api.Config;
|
import draylar.omegaconfig.api.Config;
|
||||||
@@ -6,15 +6,15 @@ import draylar.omegaconfig.api.Syncing;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@Syncing
|
@Syncing
|
||||||
public class TestConfig implements Config {
|
public class SimpleConfigTest implements Config {
|
||||||
|
|
||||||
@Comment(value = "Hello!")
|
@Comment(value = "Hello!")
|
||||||
boolean v = false;
|
public boolean v = false;
|
||||||
|
|
||||||
@Comment(value = "I'm a double.")
|
@Comment(value = "I'm a double.")
|
||||||
double doubleTest = 0.0;
|
public double doubleTest = 0.0;
|
||||||
|
|
||||||
String stringTest = "Hello, world!";
|
public String stringTest = "Hello, world!";
|
||||||
|
|
||||||
@Comment(value = "This is an inner static class.")
|
@Comment(value = "This is an inner static class.")
|
||||||
public Test test = new Test();
|
public Test test = new Test();
|
||||||
+7
-2
@@ -1,9 +1,9 @@
|
|||||||
package draylar.omegatest;
|
package draylar.omegatest.config;
|
||||||
|
|
||||||
import draylar.omegaconfig.api.Comment;
|
import draylar.omegaconfig.api.Comment;
|
||||||
import draylar.omegaconfig.api.Config;
|
import draylar.omegaconfig.api.Config;
|
||||||
|
|
||||||
public class NewTestConfig implements Config {
|
public class StructuresConfigTest implements Config {
|
||||||
@Comment("Mo' Structures feature toggles.")
|
@Comment("Mo' Structures feature toggles.")
|
||||||
public Features features = new Features();
|
public Features features = new Features();
|
||||||
|
|
||||||
@@ -123,4 +123,9 @@ public class NewTestConfig implements Config {
|
|||||||
public int killer_bunny_castle_seperation = 25;
|
public int killer_bunny_castle_seperation = 25;
|
||||||
public int killer_bunny_castle_spacing = 50;
|
public int killer_bunny_castle_spacing = 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExtension() {
|
||||||
|
return "json5";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user