Just a commit to save the progress

This commit is contained in:
sasanaps@hotmail.com
2022-04-20 20:00:33 +10:00
parent b431670255
commit a3bbdc421f
6 changed files with 40 additions and 16 deletions
@@ -21,7 +21,10 @@ public class ConfigAnnotations {
}
/** Makes text (looks like @Entry but doesn't save and has no button) */
/**
* Makes text (looks like normal entry but doesn't save and has no button)
* Accepts string and the text is the value
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Comment
@@ -25,7 +25,7 @@ public class ConfigBase {
Double
Float
Byte
Map<String, Boolean> or MultiOption
Map<String, ?>
*/
public static final List<Class<?>> acceptableInputs = new ArrayList<>();
private static void addAcceptableInputs() {
@@ -12,6 +12,7 @@ public class ConfigEntry<T> {
public String name; // This should only be set once in the init
private T value;
private T defaultValue;
private String comment;
private T min;
private T max;
@@ -20,12 +21,19 @@ public class ConfigEntry<T> {
/** Creates the entry */
private ConfigEntry(T value, String comment, T min, T max, boolean show) {
this.value = value;
this.defaultValue = value;
this.comment = comment;
this.min = min;
this.max = max;
this.show = show;
}
/** Gets the default value of the option */
public T getDefaultValue() {
return this.defaultValue;
}
/** Gets the value */
public T get() {
return this.value;
@@ -24,6 +24,7 @@ public class ConfigFileHandling {
public static final Path ConfigPath = SingletonHandler.get(IMinecraftWrapper.class).getGameDirectory().toPath().resolve("config").resolve(ModInfo.NAME+".toml");
public static final CommentedFileConfig config = CommentedFileConfig.builder(ConfigPath.toFile()).autosave().build();
/** Saves the config to the file */
public static void saveToFile() {
if (!Files.exists(ConfigPath))
try {
@@ -40,8 +41,9 @@ public class ConfigFileHandling {
config.close();
}
/** Loads the config from the file */
public static void loadFromFile() {
// Attempt to load the file and if it fails then save config to file
try {
if (Files.exists(ConfigPath))
config.load();
@@ -54,6 +56,7 @@ public class ConfigFileHandling {
return;
}
// Load all the entries
for (ConfigEntry<?> entry : ConfigBase.entries) {
createComment(entry, config);
loadEntry(entry, config);
@@ -62,11 +65,13 @@ public class ConfigFileHandling {
config.close();
}
// Save an entry when only given the entry
public static void saveEntry(ConfigEntry<?> entry) {
loadConfig(config);
saveEntry(entry, config);
config.close();
}
// Save an entry
@SuppressWarnings("unchecked")
public static void saveEntry(ConfigEntry<?> entry, CommentedFileConfig workConfig) {
if (!entry.get().getClass().isAssignableFrom(HashMap.class)) {
@@ -75,13 +80,15 @@ public class ConfigFileHandling {
workConfig.set(entry.getNameWCategory(), getStringFromHashMap((HashMap<String, ?>) entry.get()));
}
}
// Loads an entry when only given the entry
public static void loadEntry(ConfigEntry<?> entry) {
loadConfig(config);
loadEntry(entry, config);
config.close();
}
// Loads an entry
@SuppressWarnings("unchecked") // Suppress due to its always safe. (I think. See reasons below.)
public static <T> void loadEntry(ConfigEntry<T> entry, CommentedFileConfig workConfig) {
if (workConfig.contains(entry.getNameWCategory())) {
@@ -102,11 +109,13 @@ public class ConfigFileHandling {
}
}
// Creates the comment for an entry when only given the entry
public static void createComment(ConfigEntry<?> entry) {
loadConfig(config);
createComment(entry, config);
config.close();
}
// Creates a comment for an entry
public static void createComment(ConfigEntry<?> entry, CommentedFileConfig workConfig) {
workConfig.setComment(entry.getNameWCategory(), entry.getComment());
}
@@ -131,7 +140,7 @@ public class ConfigFileHandling {
// Stuff for converting HashMap's and String's
// Stuff for converting HashMap's and String's (uses json)
public static String getStringFromHashMap(HashMap<String, ?> item) {
JSONObject jsonObject = new JSONObject();
@@ -141,9 +150,8 @@ public class ConfigFileHandling {
return jsonObject.toJSONString();
}
public static <type> HashMap<String, ?> getHashMapFromString(String s) {
HashMap<String, type> map = new HashMap<>();
public static <T> HashMap<String, ?> getHashMapFromString(String s) {
HashMap<String, T> map = new HashMap<>();
JSONObject jsonObject = null;
try {
@@ -153,7 +161,7 @@ public class ConfigFileHandling {
}
for (int i = 0; i < jsonObject.keySet().toArray().length; i++) {
map.put((String) jsonObject.keySet().toArray()[i], (type) jsonObject.get(jsonObject.keySet().toArray()[i]));
map.put((String) jsonObject.keySet().toArray()[i], (T) jsonObject.get(jsonObject.keySet().toArray()[i]));
}
return map;
}
@@ -1,7 +1,7 @@
package com.seibel.lod.core.wrapperInterfaces;
package com.seibel.lod.core.config.gui;
/**
* The bace for all screens
* The base for all screens
*
* @author coolGi
*/
@@ -10,13 +10,16 @@ public abstract class AbstractScreen {
public int height;
public int mouseX = 0;
public int mouseY = 0;
/** Weather it should close when you press the escape key */
public boolean shouldCloseOnEsc = true;
/** Called once when the screen is opened */
public abstract void init();
/** Called every frame */
public abstract void render(float delta);
public void tick() {}
/** What happens when the user closes the screen*/
public void onClose() {}
}
@@ -1,10 +1,7 @@
package com.seibel.lod.core.config.gui;
import com.seibel.lod.core.wrapperInterfaces.AbstractScreen;
/**
* @author coolGi2007
* @author leetom?
*/
public class ConfigScreen extends AbstractScreen {
@Override
@@ -14,6 +11,11 @@ public class ConfigScreen extends AbstractScreen {
@Override
public void render(float delta) {
System.out.println(delta);
System.out.println("Updated config screen with the delta of " + delta);
}
@Override
public void tick() {
System.out.println("Ticked");
}
}