Skip to content

Commit 6a00bda

Browse files
committed
Better config format, fix comments
1 parent c07b45d commit 6a00bda

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/GCCore.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ public static void loadModConfig(Object rootConfigObject, ModContainer modContai
203203
}
204204
net.modificationstation.stationapi.impl.config.object.ConfigCategory configCategory = new net.modificationstation.stationapi.impl.config.object.ConfigCategory(modContainer.getMetadata().getId(), configField.getAnnotation(GConfig.class).visibleName(), null, configField, objField, configField.isAnnotationPresent(MultiplayerSynced.class), HashMultimap.create(), true);
205205
readDeeper(rootConfigObject, configField, modConfigFile.path(""), configCategory, totalReadFields, totalReadCategories, isMultiplayer, defaultEntry);
206+
readDeeper(rootConfigObject, configField, modConfigFile.path(), configCategory, totalReadFields, totalReadCategories, isMultiplayer, defaultEntry);
206207
if (!loaded) {
207208
MOD_CONFIGS.put(configID, BiTuple.of(MOD_CONFIGS.remove(configID).one(), configCategory));
208209
} else {
@@ -308,8 +309,7 @@ public static String saveConfig(EntrypointContainer<Object> container, net.modif
308309
GlassYamlFile configFile = new GlassYamlFile(new File(FabricLoader.getInstance().getConfigDir().toFile(), container.getProvider().getMetadata().getId() + "/" + category.parentField.getAnnotation(GConfig.class).value() + ".yml"));
309310
configFile.createNewFile();
310311
GlassYamlFile serverExported = new GlassYamlFile();
311-
// The path("") is critical for saving a shitton of copy-paste snowflake code. Thank you library maker, for not being controlling.
312-
saveDeeper(configFile.path(""), serverExported.path(""), category, category.parentField, readValues, readCategories);
312+
saveDeeper(configFile.path(), serverExported.path(), category, category.parentField, readValues, readCategories);
313313

314314
if (EventStorage.PRE_SAVE_LISTENERS.containsKey(container.getProvider().getMetadata().getId())) {
315315
EventStorage.PRE_SAVE_LISTENERS.get(container.getProvider().getMetadata().getId()).getEntrypoint().onPreConfigSaved(source, new GlassYamlFile(configFile.getConfigurationFile()), configFile);
@@ -341,9 +341,9 @@ else if (entry instanceof ConfigEntry) {
341341
}
342342
Object jsonElement = configFactory.apply(((ConfigEntry<?>) entry).value);
343343
if (!((ConfigEntry<?>) entry).multiplayerLoaded) {
344-
YamlFileWrapper child = newValues.setChild(entry.id, jsonElement);
344+
newValues.setChild(entry.id, jsonElement);
345345
if (entry.description != null && !entry.description.isEmpty()) {
346-
child.comment(entry.description);
346+
newValues.path(entry.id).comment(entry.description);
347347
}
348348
}
349349
if (entry.multiplayerSynced) {

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/GlassYamlFile.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.simpleyaml.configuration.comments.format.YamlCommentFormat;
44
import org.simpleyaml.configuration.file.YamlFile;
5-
import org.simpleyaml.configuration.file.YamlFileWrapper;
65
import org.simpleyaml.configuration.implementation.api.QuoteStyle;
76

87
import java.io.*;
@@ -22,8 +21,11 @@ public GlassYamlFile(String override) throws IOException {
2221
public GlassYamlFile(File file) throws IllegalArgumentException {
2322
super(file);
2423
options().useComments(true);
25-
options().quoteStyleDefaults().setDefaultQuoteStyle(QuoteStyle.DOUBLE);
2624
setCommentFormat(YamlCommentFormat.PRETTY);
25+
options().quoteStyleDefaults().setQuoteStyle(List.class, QuoteStyle.DOUBLE);
26+
options().quoteStyleDefaults().setQuoteStyle(Map.class, QuoteStyle.DOUBLE);
27+
options().quoteStyleDefaults().setQuoteStyle(String.class, QuoteStyle.DOUBLE);
28+
options().quoteStyleDefaults().setQuoteStyle(String[].class, QuoteStyle.DOUBLE);
2729
options().headerFormatter()
2830
.prefixFirst("#####################################################")
2931
.commentPrefix("## ")
@@ -47,7 +49,6 @@ public Float getFloat(String key) {
4749
return (Float) get(key);
4850
}
4951

50-
// WHyyyy
5152
public <T extends Enum<?>> T getEnum(String key, Class<T> targetEnum, T defaultValue) {
5253
return targetEnum.getEnumConstants()[getInt(key, defaultValue.ordinal())];
5354
}
@@ -87,4 +88,8 @@ private void merge(Map<String, Object> self, Map<String, Object> other) {
8788
public GlassYamlWrapper path(String path) {
8889
return new GlassYamlWrapper(this, path);
8990
}
91+
92+
public GlassYamlWrapper path() {
93+
return new GlassYamlWrapper(this, "");
94+
}
9095
}

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/GlassYamlWrapper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import org.simpleyaml.configuration.file.YamlFile;
44
import org.simpleyaml.configuration.file.YamlFileWrapper;
5+
import org.simpleyaml.configuration.implementation.api.YamlImplementation;
6+
7+
import java.util.*;
58

69
// And so the code crimes continue.
710
public class GlassYamlWrapper extends YamlFileWrapper {
@@ -23,6 +26,7 @@ public <T> Object getChild(String key, Class<T> type) {
2326

2427
@Override
2528
public GlassYamlWrapper path(String path) {
26-
return new GlassYamlWrapper(this.configuration, path, this);
29+
// Fixes some fuckery with comments.
30+
return new GlassYamlWrapper(this.configuration, path, Objects.equals(this.path, "") ? null : this);
2731
}
2832
}

0 commit comments

Comments
 (0)