mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-15 17:05:09 +01:00
feat: replace Hashtable with LinkedHashMap
- Keeps the entry order in tact without the need to store it separately
This commit is contained in:
@@ -39,15 +39,12 @@ public abstract class MidnightConfig {
|
|||||||
private static final Pattern DECIMAL_ONLY = Pattern.compile("-?(\\d+\\.?\\d*|\\d*\\.?\\d+|\\.)");
|
private static final Pattern DECIMAL_ONLY = Pattern.compile("-?(\\d+\\.?\\d*|\\d*\\.?\\d+|\\.)");
|
||||||
private static final Pattern HEXADECIMAL_ONLY = Pattern.compile("(-?[#0-9a-fA-F]*)");
|
private static final Pattern HEXADECIMAL_ONLY = Pattern.compile("(-?[#0-9a-fA-F]*)");
|
||||||
|
|
||||||
// private static final List<EntryInfo> entries = new ArrayList<>();
|
private static final LinkedHashMap<String, EntryInfo> entries = new LinkedHashMap<>(); // modid:fieldName -> EntryInfo
|
||||||
private static final Hashtable<String, EntryInfo> entries = new Hashtable<>(); // modid:fieldName -> EntryInfo
|
|
||||||
private static final List<String> entryOrder = Lists.newArrayList(); // ordered list of entries
|
|
||||||
private static boolean reloadScreen = false;
|
private static boolean reloadScreen = false;
|
||||||
|
|
||||||
public static class EntryInfo {
|
public static class EntryInfo {
|
||||||
public Entry entry;
|
public Entry entry;
|
||||||
public Comment comment;
|
public Comment comment;
|
||||||
// @ApiStatus.Obsolete public Condition condition;
|
|
||||||
public Condition[] conditions;
|
public Condition[] conditions;
|
||||||
public final Field field;
|
public final Field field;
|
||||||
public final Class<?> dataType;
|
public final Class<?> dataType;
|
||||||
@@ -96,13 +93,11 @@ public abstract class MidnightConfig {
|
|||||||
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 (Condition condition : this.conditions) {
|
for (Condition condition : this.conditions) {
|
||||||
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());
|
||||||
if (entries.get(requiredOption) instanceof EntryInfo info) {
|
if (entries.get(requiredOption) instanceof EntryInfo info)
|
||||||
this.conditionsMet &= condition.requiredValue().equals(info.tempValue);
|
this.conditionsMet &= condition.requiredValue().equals(info.tempValue);
|
||||||
}
|
|
||||||
if (!this.conditionsMet) break;
|
if (!this.conditionsMet) break;
|
||||||
}
|
}
|
||||||
if (prevConditionState != this.conditionsMet) reloadScreen = true;
|
if (prevConditionState != this.conditionsMet) reloadScreen = true;
|
||||||
@@ -186,7 +181,6 @@ public abstract class MidnightConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
entries.put(key, info);
|
entries.put(key, info);
|
||||||
entryOrder.add(key);
|
|
||||||
}
|
}
|
||||||
public static Class<?> getUnderlyingType(Field field) {
|
public static Class<?> getUnderlyingType(Field field) {
|
||||||
Class<?> rawType = field.getType();
|
Class<?> rawType = field.getType();
|
||||||
@@ -256,7 +250,7 @@ public abstract class MidnightConfig {
|
|||||||
this.parent = parent; this.modid = modid;
|
this.parent = parent; this.modid = modid;
|
||||||
this.translationPrefix = modid + ".midnightconfig.";
|
this.translationPrefix = modid + ".midnightconfig.";
|
||||||
loadValuesFromJson(modid);
|
loadValuesFromJson(modid);
|
||||||
entryOrder.stream().map(entries::get).forEach(info -> {
|
entries.forEach((id, info) -> {
|
||||||
if (info.modid.equals(modid)) {
|
if (info.modid.equals(modid)) {
|
||||||
String tabId = info.entry != null ? info.entry.category() : info.comment.category();
|
String tabId = info.entry != null ? info.entry.category() : info.comment.category();
|
||||||
String name = translationPrefix + "category." + tabId;
|
String name = translationPrefix + "category." + tabId;
|
||||||
@@ -341,7 +335,7 @@ public abstract class MidnightConfig {
|
|||||||
this.list.clear(); fillList();
|
this.list.clear(); fillList();
|
||||||
}
|
}
|
||||||
public void fillList() {
|
public void fillList() {
|
||||||
for (EntryInfo info : entryOrder.stream().map(entries::get).toList()) {
|
for (EntryInfo info : entries.sequencedValues()) {
|
||||||
if (!info.conditionsMet) {
|
if (!info.conditionsMet) {
|
||||||
boolean visibleButLocked = false;
|
boolean visibleButLocked = false;
|
||||||
for (Condition condition : info.conditions) {
|
for (Condition condition : info.conditions) {
|
||||||
|
|||||||
Reference in New Issue
Block a user