Added some stuff to the new config init
This commit is contained in:
@@ -35,7 +35,7 @@ public final class ModInfo
|
||||
public static final String ID = "lod";
|
||||
/** The internal mod name */
|
||||
public static final String NAME = "DistantHorizons";
|
||||
/** Human readable version of NAME */
|
||||
/** Human-readable version of NAME */
|
||||
public static final String READABLE_NAME = "Distant Horizons";
|
||||
public static final String API = "LodAPI";
|
||||
public static final String VERSION = "1.6.2a";
|
||||
|
||||
@@ -13,24 +13,6 @@ import java.lang.annotation.Target;
|
||||
* @version 02-07-2022
|
||||
*/
|
||||
public class ConfigAnnotations {
|
||||
/** A textField, button, etc. that can be interacted with */
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface Entry
|
||||
{
|
||||
String name() default "";
|
||||
|
||||
@Deprecated
|
||||
int width() default 150;
|
||||
|
||||
@Deprecated
|
||||
double minValue() default Double.MIN_NORMAL;
|
||||
|
||||
@Deprecated
|
||||
double maxValue() default Double.MAX_VALUE;
|
||||
|
||||
}
|
||||
|
||||
/** For making categories */
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
@@ -39,7 +21,7 @@ public class ConfigAnnotations {
|
||||
|
||||
}
|
||||
|
||||
/** Makes text (looks like @Entry but dosnt save and has no button */
|
||||
/** Makes text (looks like @Entry but doesn't save and has no button) */
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface Comment
|
||||
@@ -57,15 +39,4 @@ public class ConfigAnnotations {
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/** DONT USE AS IT WILL BE REMOVED IN THE REWORK OF THE CONFIG */
|
||||
@Deprecated
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface ScreenEntry
|
||||
{
|
||||
String name() default "";
|
||||
|
||||
int width() default 100;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,25 +5,40 @@ import com.seibel.lod.core.util.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftWrapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Config class should extend this
|
||||
* Indexes and sets everything up for the file handling and gui
|
||||
*
|
||||
* @author coolGi2007
|
||||
*/
|
||||
public abstract class ConfigBase {
|
||||
public static final File ConfigPath = SingletonHandler.get(IMinecraftWrapper.class).getGameDirectory().toPath().resolve("config").resolve(ModInfo.NAME+".toml").toFile();
|
||||
public class ConfigBase {
|
||||
public static final List<ConfigEntry> entries = new ArrayList<>();
|
||||
public static final List<String> categories = new ArrayList<>();
|
||||
|
||||
public static void init(Class<?> config) {
|
||||
initNestedClass(config);
|
||||
categories.add(""); // Add root category to category list
|
||||
initNestedClass(config, ""); // Init root category
|
||||
|
||||
// File handling (load from file)
|
||||
}
|
||||
|
||||
private static void initNestedClass(Class<?> config) {
|
||||
private static void initNestedClass(Class<?> config, String category) {
|
||||
// Put all the entries in entries
|
||||
|
||||
for (Field field : config.getFields())
|
||||
{
|
||||
if (ConfigEntry.class.isAssignableFrom(field.getType())) { // If item is type ConfigEntry
|
||||
// entries.add(field);
|
||||
}
|
||||
|
||||
if (field.isAnnotationPresent(ConfigAnnotations.Category.class)) { // If it's a category then init the stuff inside it and put it in the category list
|
||||
String NCategory = (category.isEmpty() ? "" : category + ".") + field.getName();
|
||||
categories.add(NCategory);
|
||||
initNestedClass(field.getType(), NCategory);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,20 @@ public class ConfigEntry<T> {
|
||||
}
|
||||
|
||||
|
||||
/** Should not be needed for anything other than the gui/file handling */
|
||||
public String getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
/** Should not be needed for anything other than the gui/file handling */
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
/** Should not be needed for anything other than the gui/file handling */
|
||||
public String getNameWCategory() {
|
||||
return (this.category.isEmpty() ? "" : this.category + ".") + this.name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the option is valid
|
||||
*
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
package com.seibel.lod.core.config.file;
|
||||
|
||||
import com.seibel.lod.core.ModInfo;
|
||||
import com.seibel.lod.core.util.SingletonHandler;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftWrapper;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Handles all stuff to do with the files
|
||||
*
|
||||
* @author coolGi2007
|
||||
*/
|
||||
public class ConfigFileHandling {
|
||||
public static final File ConfigPath = SingletonHandler.get(IMinecraftWrapper.class).getGameDirectory().toPath().resolve("config").resolve(ModInfo.NAME+".toml").toFile();
|
||||
|
||||
public static void saveToFile() {
|
||||
|
||||
}
|
||||
|
||||
public static void loadFromFile() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user