Allowd option for values to go out of range

This commit is contained in:
coolGi
2023-07-16 23:40:35 +09:30
parent c5041de5d4
commit 8727cd09af
5 changed files with 36 additions and 8 deletions
@@ -27,6 +27,7 @@ import com.seibel.distanthorizons.api.enums.config.quickOptions.EThreadPreset;
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode;
import com.seibel.distanthorizons.core.config.eventHandlers.QuickRenderToggleConfigEventHandler;
import com.seibel.distanthorizons.core.config.eventHandlers.RenderCacheConfigEventHandler;
import com.seibel.distanthorizons.core.config.eventHandlers.UnsafeValuesConfigListener;
import com.seibel.distanthorizons.core.config.eventHandlers.presets.ThreadPresetConfigEventHandler;
import com.seibel.distanthorizons.core.config.eventHandlers.presets.RenderQualityPresetConfigEventHandler;
import com.seibel.distanthorizons.core.config.types.ConfigCategory;
@@ -1011,10 +1012,17 @@ public class Config
+ " Additionally, only stuff that's loaded after you enable this \n"
+ " will render their debug wireframes.")
.build();
// Note: This will reset on game restart, and should have a warning on the tooltip
public static ConfigEntry<Boolean> allowUnsafeValues = new ConfigEntry.Builder<Boolean>()
.set(false)
.setAppearance(EConfigEntryAppearance.ONLY_IN_GUI)
.addListener(UnsafeValuesConfigListener.INSTANCE)
.build();
// can be set to public inorder to show in the config file and UI
private static ConfigCategory exampleConfigScreen = new ConfigCategory.Builder()
public static ConfigCategory exampleConfigScreen = new ConfigCategory.Builder()
.set(ExampleConfigScreen.class)
.build();
@@ -68,7 +68,7 @@ public class ConfigBase
}};
/** Disables the minimum and maximum of any variable */
public boolean disableMinMax = false; // Very fun to use
public boolean disableMinMax = false; // Very fun to use, but should always be disabled by default
public final List<AbstractConfigType<?, ?>> entries = new ArrayList<>();
@@ -0,0 +1,19 @@
package com.seibel.distanthorizons.core.config.eventHandlers;
import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.config.listeners.IConfigListener;
public class UnsafeValuesConfigListener implements IConfigListener {
public static UnsafeValuesConfigListener INSTANCE = new UnsafeValuesConfigListener();
@Override
public void onConfigValueSet() {
Config.Client.Advanced.Debugging.allowUnsafeValues.configBase.disableMinMax =
Config.Client.Advanced.Debugging.allowUnsafeValues.get();
}
@Override
public void onUiModify() {
}
}
@@ -147,6 +147,7 @@ public class ConfigFileHandling {
if (entry.getType() == workConfig.get(entry.getNameWCategory()).getClass()) { // If the types are the same
entry.setWithoutSaving((T) workConfig.get(entry.getNameWCategory()));
entry.clampWithinRange();
return;
}
LOGGER.warn("Entry ["+ entry.getNameWCategory() +"] is invalid. Expected " + entry.getType() + " but got " + workConfig.get(entry.getNameWCategory()).getClass() + ". Using default value.");
@@ -107,7 +107,7 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
@SuppressWarnings("unchecked") // Suppress due to its always safe
public void setMin(T newMin) {
if (newMin == null)
newMin = (T) NumberUtil.getMinimum(newMin.getClass());
newMin = (T) NumberUtil.getMinimum(this.value.getClass());
this.min = newMin;
}
/** Gets the max value */
@@ -118,7 +118,7 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
@SuppressWarnings("unchecked") // Suppress due to its always safe
public void setMax(T newMax) {
if (newMax == null)
newMax = (T) NumberUtil.getMinimum(newMax.getClass());
newMax = (T) NumberUtil.getMinimum(this.value.getClass());
this.max = newMax;
}
/** Sets the min and max within a single setter */
@@ -143,8 +143,8 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
@SuppressWarnings("unchecked") // Suppress due to its always safe
public void clampWithinRange(T min, T max) {
byte validness = this.isValid(min, max);
if (validness == -1) this.value = (T) NumberUtil.getMinimum(min.getClass());
if (validness == 1) this.value = (T) NumberUtil.getMinimum(max.getClass());
if (validness == -1) this.value = (T) NumberUtil.getMinimum(this.value.getClass());
if (validness == 1) this.value = (T) NumberUtil.getMaximum(this.value.getClass());
}
@Override
@@ -221,7 +221,7 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
if (Number.class.isAssignableFrom(value.getClass())) { // Only check min max if it is a number
if (this.max != null && Float.parseFloat(value.toString()) > Float.parseFloat(max.toString()))
return 1;
if (this.min != null && Float.parseFloat(value.toString()) < Float.parseFloat(min.toString()))
if (min != null && Float.parseFloat(value.toString()) < Float.parseFloat(min.toString()))
return -1;
return 0;