base api refactoring and javadocs
This commit is contained in:
@@ -4,7 +4,7 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import draylar.omegaconfig.api.Comment;
|
import draylar.omegaconfig.api.Comment;
|
||||||
import draylar.omegaconfig.api.Config;
|
import draylar.omegaconfig.api.Config;
|
||||||
import draylar.omegaconfig.api.SyncableExclusionStrategy;
|
import draylar.omegaconfig.gson.SyncableExclusionStrategy;
|
||||||
import draylar.omegaconfig.exception.NoValidConstructorException;
|
import draylar.omegaconfig.exception.NoValidConstructorException;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
|||||||
@@ -5,6 +5,13 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a description on a config entry.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* When a configuration is serialized, any field elements with the {@link Comment} annotation
|
||||||
|
* will be prefixed with a // comment on the previous line, with the value specified by this annotation.
|
||||||
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.FIELD)
|
@Target(ElementType.FIELD)
|
||||||
public @interface Comment {
|
public @interface Comment {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package draylar.omegaconfig.api;
|
|||||||
|
|
||||||
import draylar.omegaconfig.OmegaConfig;
|
import draylar.omegaconfig.OmegaConfig;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.StringTag;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -14,19 +13,12 @@ public interface Config {
|
|||||||
* Useful for saving modified values during runtime.
|
* Useful for saving modified values during runtime.
|
||||||
*/
|
*/
|
||||||
default void save() {
|
default void save() {
|
||||||
|
OmegaConfig.writeConfig((Class<Config>) getClass(), this);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return an instance of this Config class with all default values.
|
|
||||||
*/
|
|
||||||
default Config getDefault() {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default CompoundTag writeSyncingTag() {
|
default CompoundTag writeSyncingTag() {
|
||||||
CompoundTag tag = new CompoundTag();
|
CompoundTag tag = new CompoundTag();
|
||||||
tag.putString("ConfigName", getFileName());
|
tag.putString("ConfigName", getName());
|
||||||
|
|
||||||
// all config vs. individual fields
|
// all config vs. individual fields
|
||||||
if(Arrays.stream(getClass().getAnnotations()).anyMatch(annotation -> annotation instanceof Syncing)) {
|
if(Arrays.stream(getClass().getAnnotations()).anyMatch(annotation -> annotation instanceof Syncing)) {
|
||||||
@@ -53,8 +45,34 @@ public interface Config {
|
|||||||
return hasSyncingField | classSyncs;
|
return hasSyncingField | classSyncs;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getFileName();
|
/**
|
||||||
|
* Returns the name of this config, which is used for the name of the config file saved to disk, and syncing.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* The name returned by this method should generally follow Identifier conventions, but this is not enforced:
|
||||||
|
* <ul>
|
||||||
|
* <li>Lowercase
|
||||||
|
* <li>No special characters ($, %, ^, etc.)
|
||||||
|
* <li>No spaces
|
||||||
|
*
|
||||||
|
* @return the name of this config, which is used for the name of the config file saved to disk.
|
||||||
|
*/
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the modid associated with this configuration class.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* This functionality is used for libraries like ModMenu, which depend on
|
||||||
|
* modids for configuration screen instances in their menu.
|
||||||
|
* If you are intending for this config to have a ModMenu config
|
||||||
|
* screen, this method should return the modid specified in your fabric.mod.json.
|
||||||
|
*
|
||||||
|
* If this method is not overridden, null will be returned, which
|
||||||
|
* means this config is not explicitly associated with any particular mod.
|
||||||
|
*
|
||||||
|
* @return the modid of the mod associated with this config, or null if none was specified
|
||||||
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
default String getModid() {
|
default String getModid() {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
package draylar.omegaconfig.api;
|
package draylar.omegaconfig.gson;
|
||||||
|
|
||||||
import com.google.gson.ExclusionStrategy;
|
import com.google.gson.ExclusionStrategy;
|
||||||
import com.google.gson.FieldAttributes;
|
import com.google.gson.FieldAttributes;
|
||||||
|
import draylar.omegaconfig.api.Syncing;
|
||||||
|
|
||||||
public class SyncableExclusionStrategy implements ExclusionStrategy {
|
public class SyncableExclusionStrategy implements ExclusionStrategy {
|
||||||
|
|
||||||
Reference in New Issue
Block a user