Compare commits

..
13 Commits
Author SHA1 Message Date
DraylarandGitHub 24c0d9a039 Version bump to 1.1.0 2021-12-09 00:13:32 -06:00
DraylarandGitHub 6db4f12eed Merge pull request #6 from RDKRACZ/patch-1
Add "library" badge for ModMenu; Add contact tags to the fabric.mod.json file.
2021-12-09 00:13:04 -06:00
DraylarandGitHub 6ed97d4e00 Merge pull request #4 from alkyaly/fix/comments-in-nested-classes
Fixes comments not applying when inside nested classes.
2021-12-09 00:11:55 -06:00
DraylarandGitHub 3ecbae5593 Merge pull request #5 from alkyaly/fix/multiline
Fixes multi-line comments breaking
2021-12-09 00:11:44 -06:00
K0RRandGitHub d15fcd0732 Update gradle.properties 2021-09-09 12:42:47 +02:00
K0RRandGitHub bd2cc57eb9 Update fabric.mod.json 2021-08-18 13:20:55 +02:00
K0RRandGitHub 539d3ee1af Update gradle-wrapper.properties 2021-08-18 13:18:37 +02:00
adrianoy ebfaac9fb9 Add multiline comments more sensibly... 2021-08-10 01:21:53 -03:00
K0RRandGitHub fbc0a2b354 Add "library" badge for ModMenu; Add contact tags to the fabric.mod.json file.
>It aims to achieve the following goals:
Be lightweight (<10 KB) for JIJ usage

It's 15 KB already :)
2021-08-04 20:18:04 +02:00
adrianoy 3da79e7860 Fixes multi-line comments breaking 2021-07-28 03:38:36 -03:00
adrianoy 228c1bb7e6 This check does nothing. 2021-07-25 23:54:52 -03:00
adrianoy e09f903332 oops. 2021-07-25 22:21:02 -03:00
adrianoy 1fe4d53565 Makes comments apply when inside nested classes of nested classes. 2021-07-25 22:20:35 -03:00
8 changed files with 152 additions and 29 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx2G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
# check these on https://fabricmc.net/versions.html
minecraft_version=1.17
yarn_mappings=1.17+build.7
loader_version=0.11.3
@@ -9,6 +9,6 @@ loader_version=0.11.3
#Fabric api
fabric_version=0.34.10+1.17
# Mod Properties
mod_version=1.0.8
mod_version=1.1.0
maven_group=draylar
archives_base_name=omega-config
+2 -2
View File
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
@@ -23,7 +23,12 @@ import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class OmegaConfig {
@@ -109,10 +114,9 @@ public class OmegaConfig {
addFieldComments(field, keyToComments);
}
// get inner-class fields
// TODO: recursively get inner classes?
for (Class<?> innerClass : configClass.getDeclaredClasses()) {
for (Field field : innerClass.getDeclaredFields()) {
// "flattens" all the inner classes of the Config class into a single list
for (Class<?> clazz : flatten(configClass.getDeclaredClasses())) {
for (Field field : clazz.getDeclaredFields()) {
addFieldComments(field, keyToComments);
}
}
@@ -120,14 +124,18 @@ public class OmegaConfig {
// Find areas we should insert comments into...
for (int i = 0; i < lines.size(); i++) {
String at = lines.get(i);
String startingWhitespace = getStartingWhitespace(at);
// Check if we should insert comment
for (Map.Entry<String, String> entry : keyToComments.entrySet()) {
String key = entry.getKey();
String comment = entry.getValue();
if (at.trim().startsWith(String.format("\"%s\"", key))) {
insertions.put(i + insertions.size(), String.format("%s//%s", getStartingWhitespace(at), comment));
// Check if we should insert comment
if (at.trim().startsWith(String.format("\"%s\"", entry.getKey()))) {
if (comment.contains("\n")) {
comment = startingWhitespace + "//" + String.join(String.format("\n%s//", startingWhitespace), comment.split("\n"));
} else {
comment = String.format("%s//%s", startingWhitespace, comment);
}
insertions.put(i + insertions.size(), comment);
break;
}
}
@@ -154,6 +162,28 @@ public class OmegaConfig {
}
}
private static List<Class<?>> flatten(Class<?>[] array) {
List<Class<?>> list = new ArrayList<>();
for (Class<?> clazz : array) {
populateRecursively(list, clazz);
}
return list;
}
private static void populateRecursively(List<Class<?>> list, Class<?> aClass) {
list.add(aClass);
Class<?>[] classes = aClass.getDeclaredClasses();
if (classes.length != 0) {
for (Class<?> clazz : classes) {
populateRecursively(list, clazz);
}
}
}
private static void addFieldComments(Field field, Map<String, String> keyToComments) {
String fieldName = field.getName();
Annotation[] annotations = field.getDeclaredAnnotations();
@@ -8,7 +8,11 @@
"Draylar",
"Frqnny"
],
"contact": {},
"contact": {
"homepage": "https://github.com/Draylar/omega-config",
"sources": "https://github.com/Draylar/omega-config",
"issues": "https://github.com/Draylar/omega-config/issues"
},
"license": "MIT",
"environment": "*",
"mixins": [
@@ -18,5 +22,10 @@
"fabricloader": "*",
"fabric": "*",
"minecraft": "*"
}
},
"custom": {
"modmenu": {
"badges": [ "library" ]
}
}
}
@@ -7,7 +7,11 @@
"authors": [
"Draylar"
],
"contact": {},
"contact": {
"homepage": "https://github.com/Draylar/omega-config",
"sources": "https://github.com/Draylar/omega-config",
"issues": "https://github.com/Draylar/omega-config/issues"
},
"license": "MIT",
"environment": "*",
"mixins": [
@@ -17,5 +21,10 @@
"fabricloader": "*",
"fabric": "*",
"minecraft": "*"
}
},
"custom": {
"modmenu": {
"badges": [ "library" ]
}
}
}
@@ -2,6 +2,7 @@ package draylar.omegatest;
import draylar.omegaconfig.OmegaConfig;
import draylar.omegatest.config.ClassConfigTest;
import draylar.omegatest.config.CommentedNestedClassConfig;
import draylar.omegatest.config.NestedConfigTest;
import draylar.omegatest.config.SimpleConfigTest;
import draylar.omegatest.config.StructuresConfigTest;
@@ -13,6 +14,7 @@ public class OmegaTestMain implements ModInitializer {
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);
public static final CommentedNestedClassConfig COMMENTED_NESTED_CLASS = OmegaConfig.register(CommentedNestedClassConfig.class);
@Override
public void onInitialize() {
@@ -0,0 +1,73 @@
package draylar.omegatest.config;
import draylar.omegaconfig.api.Comment;
import draylar.omegaconfig.api.Config;
public class CommentedNestedClassConfig implements Config {
@Comment("Very nested test")
public First first = new First();
@Comment("True")
public boolean test = false;
@Comment("First-Level")
public VeryNested veryNested = new VeryNested();
public static class First {
@Comment("Cucumbers")
public boolean cucumbers = true;
@Comment("InnerFirst")
public InnerFirst innerFirst = new InnerFirst();
@Comment("InnerSecond")
public InnerSecond innerSecond = new InnerSecond();
public static class InnerFirst {
@Comment("Number of Tomatoes")
public int numberOfTomatoes = 10;
}
public static class InnerSecond {
@Comment("Inner Second First")
public InnerSecondFirst innerSecondFirst = new InnerSecondFirst();
public static class InnerSecondFirst {
@Comment("Olive Oil")
public String oliveOil = "oliveOil";
}
}
}
public static class VeryNested {
@Comment("Second-Level")
public Very very = new Very();
public static class Very {
@Comment("Third-Level")
public VeryVery veryVery = new VeryVery();
public static class VeryVery {
@Comment("Forth-Level")
public VeryVeryVery veryVeryVery = new VeryVeryVery();
public static class VeryVeryVery {
@Comment("Fifth-Level")
public VeryVeryVeryVery veryVeryVeryVery = new VeryVeryVeryVery();
public static class VeryVeryVeryVery {
@Comment("Sixth-Level")
public String last = "last";
}
}
}
}
}
@Override
public String getName() {
return "commented-inner-classes";
}
@Override
public String getExtension() {
return "json5";
}
}
@@ -13,16 +13,16 @@ public class StructuresConfigTest implements Config {
@Comment("""
Welcome to Mo'Structures Config!
//
// Here, you can turn off structures, change their chance, and also change their salt.
//
// To turn off a structure, simply go to the corresponding entry and set `activated` to false.
//
// Mo' Structures uses the vanilla structure spawning system. That is-
// - Seperation is the minimum chunks between structures
// - Spacing is the average chunks between structures
//
// Salt is a special field that gives structures unique spawning positions. DO NOT TOUCH IT, ONLY ADVANCED TROUBLESHOOTING!
Here, you can turn off structures, change their chance, and also change their salt.
To turn off a structure, simply go to the corresponding entry and set `activated` to false.
Mo' Structures uses the vanilla structure spawning system. That is-
- Seperation is the minimum chunks between structures
- Spacing is the average chunks between structures
Salt is a special field that gives structures unique spawning positions. DO NOT TOUCH IT, ONLY ADVANCED TROUBLESHOOTING!
""")
public final Map<String, StructureConfigEntry> structureConfigEntries = new HashMap<>(17);