[config] Allow auxiliary metadata to reside in a sub-object of "libjf"
This commit is contained in:
parent
de5b205caf
commit
dfbc973f03
|
@ -84,8 +84,10 @@ and it will be mentioned in the GUI.
|
|||
|
||||
```json
|
||||
"custom": {
|
||||
"libjf:config": {
|
||||
"referencedConfigs": ["libjf-web-v0"]
|
||||
"libjf": {
|
||||
"config": {
|
||||
"referencedConfigs": ["libjf-web-v0"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.libjf.gson;
|
||||
|
||||
import com.google.gson.*;
|
||||
import io.gitlab.jfronny.gson.*;
|
||||
import net.fabricmc.loader.api.metadata.CustomValue;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package io.gitlab.jfronny.libjf.config.impl;
|
||||
|
||||
import io.gitlab.jfronny.libjf.unsafe.SafeLog;
|
||||
import net.fabricmc.loader.api.metadata.CustomValue;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class AuxiliaryMetadata {
|
||||
|
@ -14,24 +10,4 @@ public class AuxiliaryMetadata {
|
|||
else referencedConfigs = List.copyOf(referencedConfigs);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static AuxiliaryMetadata load(CustomValue cv) {
|
||||
if (cv == null) return null;
|
||||
AuxiliaryMetadata meta = new AuxiliaryMetadata();
|
||||
meta.referencedConfigs = new LinkedList<>();
|
||||
if (cv.getType() == CustomValue.CvType.OBJECT) {
|
||||
CustomValue.CvObject root = cv.getAsObject();
|
||||
if (root.containsKey("referencedConfigs")) {
|
||||
CustomValue referencedConfigs = root.get("referencedConfigs");
|
||||
if (referencedConfigs.getType() == CustomValue.CvType.ARRAY) {
|
||||
for (CustomValue value : referencedConfigs.getAsArray()) {
|
||||
if (value.getType() == CustomValue.CvType.STRING) {
|
||||
meta.referencedConfigs.add(value.getAsString());
|
||||
} else SafeLog.error("Could not load config metadata: referenced config is not a string");
|
||||
}
|
||||
} else SafeLog.error("Could not load config metadata: referencedConfigs is not an array");
|
||||
}
|
||||
} else SafeLog.error("Could not load config metadata: root is not an object");
|
||||
return meta;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ package io.gitlab.jfronny.libjf.config.impl;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import io.gitlab.jfronny.gson.Gson;
|
||||
import io.gitlab.jfronny.gson.GsonBuilder;
|
||||
import io.gitlab.jfronny.libjf.LibJf;
|
||||
import io.gitlab.jfronny.libjf.config.api.ConfigHolder;
|
||||
import io.gitlab.jfronny.libjf.config.api.ConfigInstance;
|
||||
import io.gitlab.jfronny.libjf.gson.FabricLoaderGsonGenerator;
|
||||
import io.gitlab.jfronny.libjf.gson.HiddenAnnotationExclusionStrategy;
|
||||
import io.gitlab.jfronny.libjf.unsafe.SafeLog;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
@ -24,7 +24,7 @@ public class ConfigHolderImpl implements ConfigHolder {
|
|||
public static final ConfigHolderImpl INSTANCE = new ConfigHolderImpl();
|
||||
private ConfigHolderImpl() {
|
||||
}
|
||||
public static final String MODULE_ID = LibJf.MOD_ID + ":config";
|
||||
public static final String MODULE_ID = "libjf:config";
|
||||
public static Gson GSON = new GsonBuilder()
|
||||
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
|
||||
.excludeFieldsWithModifiers(Modifier.PRIVATE)
|
||||
|
@ -50,7 +50,13 @@ public class ConfigHolderImpl implements ConfigHolder {
|
|||
AuxiliaryMetadata meta = new AuxiliaryMetadata();
|
||||
if (container.isPresent()) {
|
||||
CustomValue cv = container.get().getMetadata().getCustomValue(MODULE_ID);
|
||||
if (cv != null) meta = AuxiliaryMetadata.load(cv);
|
||||
if (cv == null) {
|
||||
cv = container.get().getMetadata().getCustomValue("libjf");
|
||||
if (cv != null) {
|
||||
cv = cv.getAsObject().get("config");
|
||||
}
|
||||
}
|
||||
if (cv != null) meta = GSON.fromJson(FabricLoaderGsonGenerator.toGson(cv), AuxiliaryMetadata.class);
|
||||
}
|
||||
else {
|
||||
SafeLog.warn("Attempted to register config for a mod that is not installed: " + modId);
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
]
|
||||
},
|
||||
"custom": {
|
||||
"libjf:config": {
|
||||
"referencedConfigs": ["libjf-web-v0"]
|
||||
"libjf": {
|
||||
"config": {
|
||||
"referencedConfigs": ["libjf-web-v0"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue