mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-15 17:05:09 +01:00
clean: additional refactoring
This commit is contained in:
@@ -73,11 +73,11 @@ public class EntryInfo {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantValue") //pertains to requiredModLoaded
|
||||
public void updateConditions() {
|
||||
boolean prevConditionState = this.conditionsMet;
|
||||
if (this.conditions.length > 0) this.conditionsMet = true; // reset conditions
|
||||
for (MidnightConfig.Condition condition : this.conditions) {
|
||||
//noinspection ConstantValue
|
||||
if (!condition.requiredModId().isEmpty() && !PlatformFunctions.isModLoaded(condition.requiredModId()))
|
||||
this.conditionsMet = false;
|
||||
String requiredOption = condition.requiredOption().contains(":") ? condition.requiredOption() : (this.modid + ":" + condition.requiredOption());
|
||||
@@ -89,6 +89,7 @@ public class EntryInfo {
|
||||
}
|
||||
|
||||
public <T> void writeList(int index, T value) {
|
||||
//noinspection unchecked
|
||||
var list = (List<T>) this.value;
|
||||
if (index >= list.size())
|
||||
list.add(value);
|
||||
|
||||
@@ -29,8 +29,8 @@ import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** MidnightConfig by Martin "Motschen" Prokoph
|
||||
* Single class config library - feel free to copy!
|
||||
* Based on <a href="https://github.com/Minenash/TinyConfig">...</a>
|
||||
* Minimalist config library - feel free to copy!
|
||||
* Originally based on <a href="https://github.com/Minenash/TinyConfig">...</a>
|
||||
* Credits to Minenash */
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -73,8 +73,9 @@ public abstract class MidnightConfig {
|
||||
|
||||
for (Field field : config.getFields()) {
|
||||
EntryInfo info = new EntryInfo(field, modid);
|
||||
//noinspection ConstantValue
|
||||
if ((field.isAnnotationPresent(Entry.class) || field.isAnnotationPresent(Comment.class)) && !field.isAnnotationPresent(Server.class) && !field.isAnnotationPresent(Hidden.class) && PlatformFunctions.isClientEnv())
|
||||
instance.initClient(modid, field, info);
|
||||
instance.addClientEntry(field, info);
|
||||
if (field.isAnnotationPresent(Entry.class))
|
||||
try { info.defaultValue = field.get(null);
|
||||
} catch (IllegalAccessException ignored) {}
|
||||
@@ -83,10 +84,9 @@ public abstract class MidnightConfig {
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private void initClient(String modid, Field field, EntryInfo info) {
|
||||
public void addClientEntry(Field field, EntryInfo info) {
|
||||
Entry e = info.entry;
|
||||
String key = modid + ":" + field.getName();
|
||||
if (e != null) {
|
||||
if (e != null && info.dataType != null) {
|
||||
if (info.dataType == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, (int) e.min(), (int) e.max(), true);
|
||||
else if (info.dataType == float.class) textField(info, Float::parseFloat, DECIMAL_ONLY, (float) e.min(), (float) e.max(), false);
|
||||
else if (info.dataType == double.class) textField(info, Double::parseDouble, DECIMAL_ONLY, e.min(), e.max(), false);
|
||||
@@ -106,7 +106,7 @@ public abstract class MidnightConfig {
|
||||
}, func);
|
||||
}
|
||||
}
|
||||
entries.put(key, info);
|
||||
entries.put(modid + ":" + field.getName(), info);
|
||||
}
|
||||
|
||||
public static Class<?> getUnderlyingType(Field field) {
|
||||
@@ -165,10 +165,10 @@ public abstract class MidnightConfig {
|
||||
public void loadValuesFromJson() {
|
||||
try {
|
||||
gson.fromJson(Files.newBufferedReader(getJsonFilePath()), configClass);
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
write(modid);
|
||||
}
|
||||
|
||||
entries.values().forEach(info -> {
|
||||
if (info.field != null && info.entry != null) {
|
||||
try {
|
||||
@@ -184,7 +184,12 @@ public abstract class MidnightConfig {
|
||||
configInstances.get(modid).writeChanges(modid);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void writeChanges(String modid) {
|
||||
this.writeChanges();
|
||||
}
|
||||
|
||||
public void writeChanges() {
|
||||
try {
|
||||
Path path;
|
||||
if (!Files.exists(path = getJsonFilePath()))
|
||||
@@ -205,7 +210,6 @@ public abstract class MidnightConfig {
|
||||
|
||||
// Overridable method
|
||||
public void onTabInit(String tabName, MidnightConfigListWidget list, MidnightConfigScreen screen) {
|
||||
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
|
||||
@@ -26,7 +26,7 @@ public class MidnightConfigListWidget extends ElementListWidget<ButtonEntry> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawHeaderAndFooterSeparators(DrawContext context) {
|
||||
public void drawHeaderAndFooterSeparators(DrawContext context) {
|
||||
if (renderHeaderSeparator)
|
||||
super.drawHeaderAndFooterSeparators(context);
|
||||
else
|
||||
|
||||
@@ -34,9 +34,7 @@ public class MidnightConfigScreen extends Screen {
|
||||
public final String translationPrefix, modid;
|
||||
public final Screen parent;
|
||||
public MidnightConfigListWidget list;
|
||||
public TabManager tabManager = new TabManager(a -> {
|
||||
}, a -> {
|
||||
});
|
||||
public TabManager tabManager = new TabManager(a -> {}, a -> {});
|
||||
public Map<String, Tab> tabs = new LinkedHashMap<>();
|
||||
public Tab prevTab;
|
||||
public TabNavigationWidget tabNavigation;
|
||||
|
||||
@@ -2,13 +2,11 @@ package eu.midnightdust.lib.util;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
@Deprecated
|
||||
public class MidnightColorUtil {
|
||||
/**
|
||||
* @param colorStr e.g. "FFFFFF" or "#FFFFFF"
|
||||
* @return Color as RGB
|
||||
*/
|
||||
@Deprecated
|
||||
public static Color hex2Rgb(String colorStr) {
|
||||
try { return Color.decode("#" + colorStr.replace("#", ""));
|
||||
} catch (Exception ignored) { return Color.BLACK; }
|
||||
|
||||
@@ -21,6 +21,7 @@ public class AutoModMenu implements ModMenuApi {
|
||||
MidnightConfig.configInstances.forEach((modid, cClass) -> {
|
||||
if (!MidnightLib.hiddenMods.contains(modid))
|
||||
map.put(modid, parent -> MidnightConfig.getScreen(parent, modid));
|
||||
}); return map;
|
||||
});
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ yarn_mappings=1.21.9-pre3+build.3
|
||||
enabled_platforms=fabric,neoforge
|
||||
|
||||
archives_base_name=midnightlib
|
||||
mod_version=1.7.6-rc.1
|
||||
mod_version=1.8.0-rc.1
|
||||
maven_group=eu.midnightdust
|
||||
release_type=release
|
||||
curseforge_id=488090
|
||||
|
||||
Reference in New Issue
Block a user