Replies: 7 comments 4 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Though with the way you have done it, only |
Beta Was this translation helpful? Give feedback.
-
JSON is actually a good file format for devs, since it's usually structured to be similar to how corresponding Java class is structured. Designing via JSON will be easier then designing via Java. {
"percent": {
"$comment": "single line comment",
"$defaults": { "$min": 0, "$max": 100, "$value": 20 },
"$value": 20
},
"enable": {
"$comment": [
"multi-line?"
],
"$defaults": { "value": true },
"$value": false
},
"someSubCategory": {
"sub":{
"$defaults": { "$all": ["NO", "YES"], "$value": "NO" },
"$value": "NO"
}
}
} propertySo for each entry in a config, sub-categories included, there should be:
interface IConfigProp<T> {
T get(); //get value
String getName(); //get name
UnmodifiableList<String> getComments();
IConfigDefaults<T> getDefaults(); //get default setup
T_ <T_> getAs(Class<T_> type);
} T can be category, so sub-category is supported. commentsI recommend using List or at least String[] for comments, since representing multi-line comments( defaults
interface IConfigDefaults<T> extends Predicate<T> {
boolean test(T value);
T getDefaultValue();
} All "bounds" related data, like |
Beta Was this translation helpful? Give feedback.
-
I personally am against JSON because of the poor readability format with the stringent syntax, a minor typo can be hard to diagnose especially with Gson's error messages when parsing. The interfaces looks good and aren't verbose. As I've written in the OP, the goal isn't to propose a configuration language/format/denotation (JSON or what not). That can come in a separate proposal (I know that most people in the discord have expressed likeability and interest towards TOML and HOCON). |
Beta Was this translation helpful? Give feedback.
-
I want to be able to trace the owner of a Configuration, like: public class ModConfiguration extends Configuration {
public final String modId;
public final Class<?> clazz;
public ModConfiguration(String modidIn, Class<?> clazzIn, File file){
super(fileWrapper);
modId = modidIn;
clazz = clazzIn;
}
} When creating a class-based config for an FMLMod: - cfg = new Configuration(file);
+ cfg = new ModConfiguration(modid, cls, file); This is just a simple example, and other methods can also be used to record. However, the two existing Maps cannot be traced back. private static Map<String, Configuration> CONFIGS = Maps.newHashMap();
private static Map<String, Set<Class<?>>> MOD_CONFIG_CLASSES = Maps.newHashMap(); Creating an additional Map can also solve the problem, but I think creating and using subclasses is more in line with human logic. |
Beta Was this translation helpful? Give feedback.
-
the upper limit is |
Beta Was this translation helpful? Give feedback.
-
Currently, the class-based configuration method is inconvenient to migrate. If I want to modify its format, I still need to keep the old fields for compatibility. This leads to many problems:
Therefore, we need: |
Beta Was this translation helpful? Give feedback.
-
Summary
To provide a concise but extensive configuration API for devs, and for the players to edit config with ease whether in-game or in their filesystems.
Goals
Non Goals
Motivation
Description
The typical configuration class looks like this for Forge mods:
and the outputted
modid.cfg
(the whitespace at the bottom isn't added in on purpose):I believe the current
@Config
annotation does serve well, without any extraneous getters/setters, you are able to set config properties, however, it isn't very reactive and you will have to refresh theConfigManager
of any changes.First of all, the mod id should be inferred; we should try to eliminate places to state the mod id other than the mod's main class and/or manifest. The value in those constant areas should propagate properly.
(note: syntax isn't final!)
While more verbose, the field types should be converted to something that is observable. Not only does this allow devs to react to configuration changes on an entry-to-entry basis, it also allows for file watchers to change in-memory configuration entries singularly.
For file watchers, since Java's APIs do not offer any type of callback. We will have to poll on a different thread to watch for configuration changes and react to these
Observables
on our own. This may be a drawback and may have to be an opted-in/opted-out service for each configuration class.Currently, inner classes seem fine, but it may depend on how complex the implementation ends up.
-ConfigAnytime.register(ConfigClass.class);
ConfigAnytime
will be absorbed and replaced. It will have no place anymore where our configuration system can be loaded at any point in time. We will have a mock mod container so existing mods that depends on it do not break.Forge currently offers
ITypeAdapter
but it is package-private, and never meant for devs to touch. But we will change that, and offer something more abundant. First, it definitely will have to be generic, for any type. The "adapter" should instead cover both serializing and deserializing. The "generic" way also means arrays won't have to be treated differently.More description describing more of the API in the coming days!
Dependencies
References
No response
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions