Compare commits

...
10 Commits
15 changed files with 250 additions and 28 deletions
+2
View File
@@ -123,3 +123,5 @@ run/
/run/
/server-run/
/out.map
/omega-config-base/out.map
/omega-config-gui/out.map
+3 -3
View File
@@ -15,7 +15,7 @@ buildscript {
}
plugins {
id "fabric-loom" version "0.7-SNAPSHOT"
id "fabric-loom" version "0.8-SNAPSHOT"
id "maven-publish"
id "java-library"
}
@@ -207,8 +207,8 @@ repositories {
}
dependencies {
compile project(":omega-config-base")
compile project(":omega-config-gui")
implementation project(":omega-config-base")
implementation project(":omega-config-gui")
modRuntime "com.terraformersmc:modmenu:1.16.8"
modCompileOnly "com.terraformersmc:modmenu:1.16.8"
+1 -1
View File
@@ -8,7 +8,7 @@ yarn_mappings=1.16.5+build.5
loader_version=0.11.2
# Mod Properties
mod_version=1.0.1
mod_version=1.0.5
maven_group=draylar
archives_base_name=omega-config
+1 -1
View File
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
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
zipStorePath=wrapper/dists
@@ -85,14 +85,16 @@ public class OmegaConfig {
writeConfig(configClass, object);
REGISTERED_CONFIGURATIONS.add(object);
return object;
} catch (IOException ioException) {
LOGGER.error(ioException);
LOGGER.info(String.format("Read error, using default values for config %s.", configClass.toString()));
} catch (Exception e) {
LOGGER.error(e);
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;
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
exception.printStackTrace();
throw new NoValidConstructorException();
}
}
@@ -103,7 +105,7 @@ public class OmegaConfig {
// Cursed time.
List<String> lines = new ArrayList<>(Arrays.asList(json.split("\n")));
Map<Integer, String> insertions = new HashMap<>();
Map<Integer, String> insertions = new TreeMap<>();
Map<String, String> keyToComments = new HashMap<>();
// populate key -> comments map
@@ -136,14 +138,20 @@ public class OmegaConfig {
}
// insertions -> list
insertions.forEach(lines::add);
for (Map.Entry<Integer, String> entry : insertions.entrySet()) {
Integer key = entry.getKey();
String value = entry.getValue();
lines.add(key, value);
}
// list -> string
StringBuilder res = new StringBuilder();
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()));
@@ -195,7 +203,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 "";
}
}
@@ -14,8 +14,8 @@
"omega-config.mixins.json"
],
"depends": {
"fabricloader": ">=0.11.2",
"fabricloader": "*",
"fabric": "*",
"minecraft": "1.16.5"
"minecraft": "*"
}
}
+1 -1
View File
@@ -1,3 +1,3 @@
dependencies {
compile project(":omega-config-base")
implementation project(":omega-config-base")
}
@@ -14,8 +14,8 @@
"omega-config-gui.mixins.json"
],
"depends": {
"fabricloader": ">=0.11.2",
"fabricloader": "*",
"fabric": "*",
"minecraft": "1.16.5"
"minecraft": "*"
}
}
@@ -1,11 +1,18 @@
package draylar.omegatest;
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;
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 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
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";
}
}
@@ -1,4 +1,4 @@
package draylar.omegatest;
package draylar.omegatest.config;
import draylar.omegaconfig.api.Comment;
import draylar.omegaconfig.api.Config;
@@ -6,15 +6,15 @@ import draylar.omegaconfig.api.Syncing;
import org.jetbrains.annotations.Nullable;
@Syncing
public class TestConfig implements Config {
public class SimpleConfigTest implements Config {
@Comment(value = "Hello!")
boolean v = false;
public boolean v = false;
@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.")
public Test test = new Test();
@@ -0,0 +1,131 @@
package draylar.omegatest.config;
import draylar.omegaconfig.api.Comment;
import draylar.omegaconfig.api.Config;
public class StructuresConfigTest implements Config {
@Comment("Mo' Structures feature toggles.")
public Features features = new Features();
@Comment("Chances are once per the number of chunks. A Chance 500 makes a feature spawn every 500 chunks. Affected by biomes it spawns in and the chunk, so not all are proportional.")
public FeatureChances feature_chances = new FeatureChances();
@Comment("Structure toggles. These do not have chances, but in the future they may. ")
public Structures structures = new Structures();
@Comment("Structure chances. Seperation is the least amount of chunks that a structure will spawn from itself. Spacing is the maximum amount of chunks, and both are used to randomly spawn structures and can be tweaked.")
public StructureChances structureChances = new StructureChances();
@Override
public String getName() {
return "mostructures-config-v2";
}
public static class Features {
@Comment("Airplanes & Air Balloons")
public boolean air_features = true;
@Comment("Fallen Trees")
public boolean fallen_trees = true;
@Comment("Desert Features")
public boolean desert_features = true;
@Comment("Ruins")
public boolean ruins = true;
@Comment("Lamppost")
public boolean lamppost = true;
@Comment("Boulder")
public boolean boulder = true;
@Comment("Volcanic Vent")
public boolean volcanic_vent = true;
@Comment("Beach Features")
public boolean beach_features = true;
@Comment("Boats")
public boolean boats = true;
}
public static class FeatureChances {
@Comment("Airplanes & Air Balloons")
public int air_feature_chance = 4600;
@Comment("Fallen Trees")
public int fallen_trees_chance = 17;
@Comment("Desert Features")
public int desert_features_chance = 555;
@Comment("Ruins")
public int ruins_chance = 3500;
@Comment("Lamppost")
public int lamppost_chance = 100;
@Comment("Boulder")
public int boulder_chance = 4000;
@Comment("Volcanic Vent")
public int volcanic_vent_chance = 85;
@Comment("Beach Features")
public int beach_features_chance = 75;
@Comment("Boats")
public int boats_chance = 4000;
}
public static class Structures {
@Comment("Barnhouse")
public boolean barn_house = true;
@Comment("Jungle Pyramid")
public boolean jungle_pyramid = true;
@Comment("Big Pyramid")
public boolean big_pyramid = true;
@Comment("The Castle In The Sky")
public boolean the_castle_in_the_sky = true;
@Comment("Villager Tower")
public boolean villager_tower = true;
@Comment("Abandoned Churches")
public boolean abandoned_churches = true;
@Comment("Villager Market")
public boolean villager_market = true;
@Comment("Pillager Factory")
public boolean pillager_factory = true;
@Comment("Ice Tower")
public boolean ice_tower = true;
@Comment("Boar Hat Tavern")
public boolean tavern = true;
@Comment("Killer Bunny Castle")
public boolean killer_bunny_castle = true;
}
public static class StructureChances {
@Comment("Barn House")
public int barn_house_seperation = 16;
public int barn_house_spacing = 40;
@Comment("Big Pyramid")
public int big_pyramid_seperation = 5;
public int big_pyramid_spacing = 25;
@Comment("Jungle Pyramid")
public int jungle_pyramid_seperation = 5;
public int jungle_pyramid_spacing = 25;
@Comment("The Castle In The Sky")
public int the_castle_in_the_sky_seperation = 8;
public int the_castle_in_the_sky_spacing = 32;
@Comment("Villager Tower")
public int villager_tower_seperation = 16;
public int villager_tower_spacing = 40;
@Comment("Abandoned Church")
public int abandoned_church_seperation = 16;
public int abandoned_church_spacing = 40;
@Comment("Villager Market")
public int villager_market_seperation = 27;
public int villager_market_spacing = 50;
@Comment("Pillager Factory")
public int pillager_factory_seperation = 27;
public int pillager_factory_spacing = 50;
@Comment("Ice Tower")
public int ice_tower_seperation = 8;
public int ice_tower_spacing = 32;
@Comment("Boar Hat Tavern")
public int tavern_seperation = 16;
public int tavern_spacing = 46;
@Comment("Killer Bunny Castle")
public int killer_bunny_castle_seperation = 25;
public int killer_bunny_castle_spacing = 50;
}
@Override
public String getExtension() {
return "json5";
}
}
+2 -2
View File
@@ -19,8 +19,8 @@
]
},
"depends": {
"fabricloader": ">=0.11.2",
"fabricloader": "*",
"fabric": "*",
"minecraft": "1.16.5"
"minecraft": "*"
}
}