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