diff --git a/api/src/main/java/com/seibel/distanthorizons/coreapi/interfaces/config/IConfigEntry.java b/api/src/main/java/com/seibel/distanthorizons/coreapi/interfaces/config/IConfigEntry.java deleted file mode 100644 index c1ad8ab01..000000000 --- a/api/src/main/java/com/seibel/distanthorizons/coreapi/interfaces/config/IConfigEntry.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This file is part of the Distant Horizons mod - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.distanthorizons.coreapi.interfaces.config; - - -import java.util.function.Consumer; - -/** - * Use for making the config variables - * - * @author coolGi - * @version 2022-5-26 - */ -public interface IConfigEntry -{ - - /** Gets the default value of the option */ - T getDefaultValue(); - - void setApiValue(T newApiValue); - T getApiValue(); - /** @return true if this config is able to be overridden by the API and an API user has set it */ - boolean apiIsOverriding(); - - /** Returns true if this config can be set via the API. */ - boolean getAllowApiOverride(); - - void set(T newValue); - T get(); - /** gets the option ignoring what the API has overridden */ - T getTrueValue(); - - /** Sets the value without saving */ - void setWithoutSaving(T newValue); - - /** Gets the min value */ - T getMin(); - /** Sets the min value */ - void setMin(T newMin); - /** Gets the max value */ - T getMax(); - /** Sets the max value */ - void setMax(T newMax); - /** Sets the min and max in 1 setter */ - void setMinMax(T newMin, T newMax); - - /** Gets the comment */ - String getComment(); - /** Sets the comment */ - void setComment(String newComment); - - /** - * Checks if the option is valid - * - * 0 == valid - * 2 == invalid - * 1 == number too high - * -1 == number too low - */ - byte isValid(); // TODO replace with an enum - /** Checks if a value is valid */ - byte isValid(T value); - - /** Is the value of this equal to another */ - boolean equals(IConfigEntry obj); - - void addValueChangeListener(Consumer onValueChangeFunc); - -} diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiAmbientOcclusionConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiAmbientOcclusionConfig.java index 5c7f19bc3..d7045b324 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiAmbientOcclusionConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiAmbientOcclusionConfig.java @@ -21,7 +21,7 @@ package com.seibel.distanthorizons.core.api.external.methods.config.client; import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiAmbientOcclusionConfig; -import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; import com.seibel.distanthorizons.core.config.Config; public class DhApiAmbientOcclusionConfig implements IDhApiAmbientOcclusionConfig diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiDebuggingConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiDebuggingConfig.java index 80ab59b40..8b02e333c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiDebuggingConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiDebuggingConfig.java @@ -21,7 +21,7 @@ package com.seibel.distanthorizons.core.api.external.methods.config.client; import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiDebuggingConfig; -import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.api.enums.rendering.EDhApiDebugRendering; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFarFogConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFarFogConfig.java index 7b02e5917..1fab043fd 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFarFogConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFarFogConfig.java @@ -22,7 +22,7 @@ package com.seibel.distanthorizons.core.api.external.methods.config.client; import com.seibel.distanthorizons.api.enums.rendering.EDhApiFogFalloff; import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiFarFogConfig; -import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; import com.seibel.distanthorizons.core.config.Config; public class DhApiFarFogConfig implements IDhApiFarFogConfig diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFogConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFogConfig.java index eee726d9f..13db26165 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFogConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiFogConfig.java @@ -25,9 +25,9 @@ import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiFarFogConfig; import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiFogConfig; import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiHeightFogConfig; -import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; import com.seibel.distanthorizons.core.config.Config; -import com.seibel.distanthorizons.coreapi.util.converters.ApiFogDrawModeConverter; +import com.seibel.distanthorizons.core.config.api.converters.ApiFogDrawModeConverter; public class DhApiFogConfig implements IDhApiFogConfig { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGenericRenderingConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGenericRenderingConfig.java index f80195f65..559e12d53 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGenericRenderingConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGenericRenderingConfig.java @@ -21,7 +21,7 @@ package com.seibel.distanthorizons.core.api.external.methods.config.client; import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiGenericRenderingConfig; -import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; import com.seibel.distanthorizons.core.config.Config; public class DhApiGenericRenderingConfig implements IDhApiGenericRenderingConfig diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGraphicsConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGraphicsConfig.java index a131c2fbb..bee86e991 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGraphicsConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiGraphicsConfig.java @@ -23,10 +23,10 @@ import com.seibel.distanthorizons.api.enums.config.*; import com.seibel.distanthorizons.api.enums.rendering.EDhApiTransparency; import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; import com.seibel.distanthorizons.api.interfaces.config.client.*; -import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; import com.seibel.distanthorizons.api.enums.rendering.EDhApiRendererMode; import com.seibel.distanthorizons.core.config.Config; -import com.seibel.distanthorizons.coreapi.util.converters.RenderModeEnabledConverter; +import com.seibel.distanthorizons.core.config.api.converters.RenderModeEnabledConverter; public class DhApiGraphicsConfig implements IDhApiGraphicsConfig { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiHeightFogConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiHeightFogConfig.java index 5a12d7fbb..29ba5b2c5 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiHeightFogConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiHeightFogConfig.java @@ -24,7 +24,7 @@ import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogMixMode; import com.seibel.distanthorizons.api.enums.rendering.EDhApiHeightFogDirection; import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiHeightFogConfig; -import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; import com.seibel.distanthorizons.core.config.Config; public class DhApiHeightFogConfig implements IDhApiHeightFogConfig diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiThreadingConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiThreadingConfig.java index cf3b86b4b..a8ab06966 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiThreadingConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiThreadingConfig.java @@ -21,7 +21,7 @@ package com.seibel.distanthorizons.core.api.external.methods.config.client; import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiMultiThreadingConfig; -import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; import com.seibel.distanthorizons.core.config.Config; public class DhApiMultiThreadingConfig implements IDhApiMultiThreadingConfig diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiplayerConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiplayerConfig.java index 438627832..1c83575a8 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiplayerConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiMultiplayerConfig.java @@ -21,7 +21,7 @@ package com.seibel.distanthorizons.core.api.external.methods.config.client; import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiMultiplayerConfig; -import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.api.enums.config.EDhApiServerFolderNameMode; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java index 3135a62a3..15fd60be2 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/client/DhApiNoiseTextureConfig.java @@ -21,7 +21,7 @@ package com.seibel.distanthorizons.core.api.external.methods.config.client; import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; import com.seibel.distanthorizons.api.interfaces.config.client.IDhApiNoiseTextureConfig; -import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; import com.seibel.distanthorizons.core.config.Config; public class DhApiNoiseTextureConfig implements IDhApiNoiseTextureConfig diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/common/DhApiWorldGenerationConfig.java b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/common/DhApiWorldGenerationConfig.java index f87c0b5ca..fa8b47039 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/common/DhApiWorldGenerationConfig.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/external/methods/config/common/DhApiWorldGenerationConfig.java @@ -21,7 +21,7 @@ package com.seibel.distanthorizons.core.api.external.methods.config.common; import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; import com.seibel.distanthorizons.api.interfaces.config.both.IDhApiWorldGenerationConfig; -import com.seibel.distanthorizons.api.objects.config.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiDistantGeneratorMode; import com.seibel.distanthorizons.core.config.Config; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/AppliedConfigState.java b/core/src/main/java/com/seibel/distanthorizons/core/config/AppliedConfigState.java deleted file mode 100644 index 42a531950..000000000 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/AppliedConfigState.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of the Distant Horizons mod - * licensed under the GNU LGPL v3 License. - * - * Copyright (C) 2020 James Seibel - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.seibel.distanthorizons.core.config; - -import com.seibel.distanthorizons.core.config.types.ConfigEntry; - -// TODO: Make this integrate with the config system -public class AppliedConfigState -{ - final ConfigEntry entry; - T activeValue; - - - - public AppliedConfigState(ConfigEntry entryToWatch) - { - this.entry = entryToWatch; - this.activeValue = entryToWatch.get(); - } - - - - /** Returns true if the value was changed */ - public boolean pollNewValue() - { - T newValue = this.entry.get(); - if (newValue.equals(this.activeValue)) - { - return false; - } - this.activeValue = newValue; - return true; - } - - public T get() { return this.activeValue; } - -} diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index 7756c04b2..719ebd25c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -45,14 +45,11 @@ import java.util.*; import java.util.List; /** - * This handles any configuration the user has access to.

- * - * Note:
- * Only add simpler listeners here (IE listeners that only depend on 1 config entry). - * For listeners that depend on 2 or more config entries, add them before the config menu is opened. - * Otherwise, you will have issues where only some of the config entries will exist when your listener is created. + * This handles any configuration the user has access to. * * @author coolGi + * + * @see ConfigHandler */ @SuppressWarnings("ConcatenationWithEmptyString") public class Config @@ -1849,7 +1846,6 @@ public class Config try { - // TODO automatically get all instances of AbstractPresetConfigEventHandler and fire "setUiOnlyConfigValues" ThreadPresetConfigEventHandler.INSTANCE.setUiOnlyConfigValues(); RenderQualityPresetConfigEventHandler.INSTANCE.setUiOnlyConfigValues(); QuickRenderToggleConfigEventHandler.INSTANCE.setUiOnlyConfigValues(); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigBase.java b/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigHandler.java similarity index 66% rename from core/src/main/java/com/seibel/distanthorizons/core/config/ConfigBase.java rename to core/src/main/java/com/seibel/distanthorizons/core/config/ConfigHandler.java index 5639298cb..c7811a5f6 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigBase.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigHandler.java @@ -26,29 +26,28 @@ import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.wrapperInterfaces.config.ILangWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper; import com.seibel.distanthorizons.coreapi.ModInfo; -import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.lang.invoke.MethodHandles; import java.lang.reflect.Field; import java.nio.file.Path; import java.util.*; /** - * Indexes and sets everything up for the file handling and gui. - * This should be init after singletons have been bound + * Sets up everything in {@link Config} for the file/GUI and keeps track of all + * entries therein.
+ * This should be run after the singletons have been bound. * * @author coolGi * @author Ran - * @version 2023-8-26 + * + * @see Config */ -public class ConfigBase +public class ConfigHandler { - /** Our own config instance, don't modify unless you are the DH mod */ - public static ConfigBase INSTANCE; - private static final Logger LOGGER = DhLoggerBuilder.getLogger(); + private static final IMinecraftSharedWrapper MC_SHARED = SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class); + /** * What the config works with *
@@ -69,7 +68,7 @@ public class ConfigBase *
Map *
HashMap */ - public static final List> ACCEPTABLE_INPUTS = new ArrayList>() + private static final List> ACCEPTABLE_INPUTS = new ArrayList>() {{ this.add(Boolean.class); this.add(Byte.class); @@ -89,15 +88,18 @@ public class ConfigBase - public ConfigFileHandler configFileHandler; + public static ConfigHandler INSTANCE; + public final ConfigFileHandler configFileHandler; public final int configVersion; + public final List> configEntryList = new ArrayList<>(); public boolean isLoaded = false; - - /** Disables the minimum and maximum of any variable */ - public boolean disableMinMax = false; // Very fun to use, but should always be disabled by default - public final List> entries = new ArrayList<>(); + /** + * Disables the minimum and maximum validation.
+ * Fun to use, but should be disabled by default. + */ + public boolean runMinMaxValidation = true; @@ -109,14 +111,13 @@ public class ConfigBase { if (INSTANCE != null) { - LOGGER.debug("ConfigBase setup already run, ignoring."); + LOGGER.debug("ConfigHandler setup already run, ignoring."); return; } - INSTANCE = new ConfigBase(Config.class, ModInfo.CONFIG_FILE_VERSION); + INSTANCE = new ConfigHandler(Config.class, ModInfo.CONFIG_FILE_VERSION); } - - private ConfigBase(Class configClass, int configVersion) + private ConfigHandler(Class configClass, int configVersion) { LOGGER.info("Initialising config for [" + ModInfo.NAME + "]"); @@ -124,73 +125,88 @@ public class ConfigBase this.initNestedClass(configClass, ""); // Init root category - Path configPath = getConfigPath(ModInfo.NAME); - this.configFileHandler = new ConfigFileHandler(this, configPath); + Path configPath = getConfigPath(); + this.configFileHandler = new ConfigFileHandler(configPath); this.configFileHandler.loadFromFile(); this.isLoaded = true; LOGGER.info("Config for [" + ModInfo.NAME + "] initialised"); } /** Gets the default config path given a mod name */ - private static Path getConfigPath(String modName) + private static Path getConfigPath() { - return SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class) - .getInstallationDirectory().toPath().resolve("config").resolve(modName + ".toml"); + return MC_SHARED + .getInstallationDirectory().toPath() + .resolve("config") + .resolve(ModInfo.NAME + ".toml"); } + /** Put all the config entries into configEntryList */ private void initNestedClass(Class configClass, String category) { - // Put all the entries in entries - for (Field field : configClass.getFields()) { - if (AbstractConfigType.class.isAssignableFrom(field.getType())) + // ignore any non-config variables + if (AbstractConfigBase.class.isAssignableFrom(field.getType())) { - try + continue; + } + + + // add this config to the master list + try + { + this.configEntryList.add((AbstractConfigBase) field.get(field.getType())); + } + catch (IllegalAccessException e) + { + LOGGER.warn("Unable to add config ["+field.getType().getName()+"], error: ["+e.getMessage()+"].", e); + continue; + } + + + // set any necessary variables in this config + AbstractConfigBase configBase = this.configEntryList.get(this.configEntryList.size() - 1); + configBase.category = category; + configBase.name = field.getName(); + + + // validate the config's input type + if (ConfigEntry.class.isAssignableFrom(field.getType())) + { + if (!isAcceptableType(configBase.getType())) { - this.entries.add((AbstractConfigType) field.get(field.getType())); + LOGGER.error("Invalid variable type at [" + (category.isEmpty() ? "" : category + ".") + field.getName() + "]."); + LOGGER.error("Type [" + configBase.getType() + "] is not one of these types [" + ACCEPTABLE_INPUTS.toString() + "]"); + this.configEntryList.remove(this.configEntryList.size() - 1); // Delete the entry if it is invalid so the game can still run } - catch (IllegalAccessException exception) + } + + // recursively add deeper categories if present + if (ConfigCategory.class.isAssignableFrom(field.getType())) + { + ConfigCategory configCategory = (ConfigCategory) configBase; + + if (configCategory.getDestination() == null) { - LOGGER.warn(exception); + configCategory.destination = configBase.getNameAndCategory(); } - AbstractConfigType entry = this.entries.get(this.entries.size() - 1); - entry.category = category; - entry.name = field.getName(); - entry.configBase = this; - - if (ConfigEntry.class.isAssignableFrom(field.getType())) - { - // If item is type ConfigEntry - if (!isAcceptableType(entry.getType())) - { - LOGGER.error("Invalid variable type at [" + (category.isEmpty() ? "" : category + ".") + field.getName() + "]."); - LOGGER.error("Type [" + entry.getType() + "] is not one of these types [" + ACCEPTABLE_INPUTS.toString() + "]"); - this.entries.remove(this.entries.size() - 1); // Delete the entry if it is invalid so the game can still run - } - } - - if (ConfigCategory.class.isAssignableFrom(field.getType())) - { // If it's a category then init the stuff inside it and put it in the category list - assert entry instanceof ConfigCategory; - if (((ConfigCategory) entry).getDestination() == null) - ((ConfigCategory) entry).destination = entry.getNameWCategory(); - if (entry.get() != null) - { - this.initNestedClass(((ConfigCategory) entry).get(), ((ConfigCategory) entry).getDestination()); - } + // shouldn't happen, but just in case + if (configBase.get() != null) + { + this.initNestedClass(configCategory.get(), configCategory.getDestination()); } } } } - private static boolean isAcceptableType(Class Clazz) + private static boolean isAcceptableType(Class inputClass) { - if (Clazz.isEnum()) + if (inputClass.isEnum()) { return true; } - return ACCEPTABLE_INPUTS.contains(Clazz); + return ACCEPTABLE_INPUTS.contains(inputClass); } @@ -219,9 +235,9 @@ public class ConfigBase String ending = "\",\n"; // config entries - for (AbstractConfigType entry : this.entries) + for (AbstractConfigBase entry : this.configEntryList) { - String entryPrefix = "distanthorizons.config." + entry.getNameWCategory(); + String entryPrefix = "distanthorizons.config." + entry.getNameAndCategory(); if (checkEnums && entry.getType().isEnum() diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigEntryWithPresetOptions.java b/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigPresetOptions.java similarity index 87% rename from core/src/main/java/com/seibel/distanthorizons/core/config/ConfigEntryWithPresetOptions.java rename to core/src/main/java/com/seibel/distanthorizons/core/config/ConfigPresetOptions.java index dcf639db9..243aec1ff 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigEntryWithPresetOptions.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigPresetOptions.java @@ -24,7 +24,7 @@ import com.seibel.distanthorizons.core.config.types.ConfigEntry; import java.util.HashMap; import java.util.HashSet; -public class ConfigEntryWithPresetOptions +public class ConfigPresetOptions { public final ConfigEntry configEntry; @@ -32,7 +32,11 @@ public class ConfigEntryWithPresetOptions - public ConfigEntryWithPresetOptions(ConfigEntry configEntry, HashMap configOptionByQualityOption) + //=============// + // constructor // + //=============// + + public ConfigPresetOptions(ConfigEntry configEntry, HashMap configOptionByQualityOption) { this.configEntry = configEntry; this.configOptionByQualityOption = configOptionByQualityOption; @@ -40,6 +44,10 @@ public class ConfigEntryWithPresetOptions + //=========// + // methods // + //=========// + public void updateConfigEntry(TQuickEnum quickQuality) { TConfig newValue = this.configOptionByQualityOption.get(quickQuality); diff --git a/api/src/main/java/com/seibel/distanthorizons/api/objects/config/DhApiConfigValue.java b/core/src/main/java/com/seibel/distanthorizons/core/config/api/DhApiConfigValue.java similarity index 74% rename from api/src/main/java/com/seibel/distanthorizons/api/objects/config/DhApiConfigValue.java rename to core/src/main/java/com/seibel/distanthorizons/core/config/api/DhApiConfigValue.java index af0f7c915..ffd835881 100644 --- a/api/src/main/java/com/seibel/distanthorizons/api/objects/config/DhApiConfigValue.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/api/DhApiConfigValue.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package com.seibel.distanthorizons.api.objects.config; +package com.seibel.distanthorizons.core.config.api; import com.seibel.distanthorizons.api.interfaces.config.IDhApiConfigValue; -import com.seibel.distanthorizons.coreapi.interfaces.config.IConfigEntry; +import com.seibel.distanthorizons.core.config.types.ConfigEntry; import com.seibel.distanthorizons.coreapi.interfaces.config.IConverter; -import com.seibel.distanthorizons.coreapi.util.converters.DefaultConverter; +import com.seibel.distanthorizons.core.config.api.converters.DefaultConverter; import java.util.function.Consumer; @@ -41,7 +41,7 @@ import java.util.function.Consumer; */ public class DhApiConfigValue implements IDhApiConfigValue { - private final IConfigEntry configEntry; + private final ConfigEntry configBase; private final IConverter configConverter; @@ -53,9 +53,9 @@ public class DhApiConfigValue implements IDhApiConfigValue newConfigEntry) + public DhApiConfigValue(ConfigEntry configBase) { - this.configEntry = newConfigEntry; + this.configBase = configBase; this.configConverter = (IConverter) new DefaultConverter(); } @@ -63,22 +63,22 @@ public class DhApiConfigValue implements IDhApiConfigValue * There is no reason for API users to create this object.

*/ - public DhApiConfigValue(IConfigEntry newConfigEntry, IConverter newConverter) + public DhApiConfigValue(ConfigEntry configBase, IConverter newConverter) { - this.configEntry = newConfigEntry; + this.configBase = configBase; this.configConverter = newConverter; } - public apiType getValue() { return this.configConverter.convertToApiType(this.configEntry.get()); } - public apiType getTrueValue() { return this.configConverter.convertToApiType(this.configEntry.getTrueValue()); } - public apiType getApiValue() { return this.configConverter.convertToApiType(this.configEntry.getApiValue()); } + public apiType getValue() { return this.configConverter.convertToApiType(this.configBase.get()); } + public apiType getTrueValue() { return this.configConverter.convertToApiType(this.configBase.getTrueValue()); } + public apiType getApiValue() { return this.configConverter.convertToApiType(this.configBase.getApiValue()); } public boolean setValue(apiType newValue) { - if (this.configEntry.getAllowApiOverride()) + if (this.configBase.getAllowApiOverride()) { - this.configEntry.setApiValue(this.configConverter.convertToCoreType(newValue)); + this.configBase.setApiValue(this.configConverter.convertToCoreType(newValue)); return true; } else @@ -89,11 +89,11 @@ public class DhApiConfigValue implements IDhApiConfigValue implements IDhApiConfigValue onValueChangeFunc) { - this.configEntry.addValueChangeListener((coreValue) -> + this.configBase.addValueChangeListener((coreValue) -> { apiType apiValue = this.configConverter.convertToApiType(coreValue); onValueChangeFunc.accept(apiValue); diff --git a/api/src/main/java/com/seibel/distanthorizons/coreapi/util/converters/ApiFogDrawModeConverter.java b/core/src/main/java/com/seibel/distanthorizons/core/config/api/converters/ApiFogDrawModeConverter.java similarity index 96% rename from api/src/main/java/com/seibel/distanthorizons/coreapi/util/converters/ApiFogDrawModeConverter.java rename to core/src/main/java/com/seibel/distanthorizons/core/config/api/converters/ApiFogDrawModeConverter.java index 4bb9bcef8..607b28acc 100644 --- a/api/src/main/java/com/seibel/distanthorizons/coreapi/util/converters/ApiFogDrawModeConverter.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/api/converters/ApiFogDrawModeConverter.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.seibel.distanthorizons.coreapi.util.converters; +package com.seibel.distanthorizons.core.config.api.converters; import com.seibel.distanthorizons.api.enums.rendering.EDhApiFogDrawMode; import com.seibel.distanthorizons.coreapi.interfaces.config.IConverter; diff --git a/api/src/main/java/com/seibel/distanthorizons/coreapi/util/converters/DefaultConverter.java b/core/src/main/java/com/seibel/distanthorizons/core/config/api/converters/DefaultConverter.java similarity index 95% rename from api/src/main/java/com/seibel/distanthorizons/coreapi/util/converters/DefaultConverter.java rename to core/src/main/java/com/seibel/distanthorizons/core/config/api/converters/DefaultConverter.java index d9448e6f0..b48261a8c 100644 --- a/api/src/main/java/com/seibel/distanthorizons/coreapi/util/converters/DefaultConverter.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/api/converters/DefaultConverter.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.seibel.distanthorizons.coreapi.util.converters; +package com.seibel.distanthorizons.core.config.api.converters; import com.seibel.distanthorizons.coreapi.interfaces.config.IConverter; diff --git a/api/src/main/java/com/seibel/distanthorizons/coreapi/util/converters/RenderModeEnabledConverter.java b/core/src/main/java/com/seibel/distanthorizons/core/config/api/converters/RenderModeEnabledConverter.java similarity index 95% rename from api/src/main/java/com/seibel/distanthorizons/coreapi/util/converters/RenderModeEnabledConverter.java rename to core/src/main/java/com/seibel/distanthorizons/core/config/api/converters/RenderModeEnabledConverter.java index c916e6822..21c1b647f 100644 --- a/api/src/main/java/com/seibel/distanthorizons/coreapi/util/converters/RenderModeEnabledConverter.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/api/converters/RenderModeEnabledConverter.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.seibel.distanthorizons.coreapi.util.converters; +package com.seibel.distanthorizons.core.config.api.converters; import com.seibel.distanthorizons.api.enums.rendering.EDhApiRendererMode; import com.seibel.distanthorizons.coreapi.interfaces.config.IConverter; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/UnsafeValuesConfigListener.java b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/UnsafeValuesConfigListener.java index e39e0f624..e54f1e27a 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/UnsafeValuesConfigListener.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/UnsafeValuesConfigListener.java @@ -20,23 +20,22 @@ package com.seibel.distanthorizons.core.config.eventHandlers; import com.seibel.distanthorizons.core.config.Config; +import com.seibel.distanthorizons.core.config.ConfigHandler; import com.seibel.distanthorizons.core.config.listeners.IConfigListener; +/** + * handles enabling/disabling config validation when the + * {@link Config.Client.Advanced.Debugging#allowUnsafeValues} option + * is changed. + */ 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(); - } + { ConfigHandler.INSTANCE.runMinMaxValidation = !Config.Client.Advanced.Debugging.allowUnsafeValues.get(); } + - @Override - public void onUiModify() - { - - } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java index 3b52c2ec0..0e750128a 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/AbstractPresetConfigEventHandler.java @@ -19,13 +19,13 @@ package com.seibel.distanthorizons.core.config.eventHandlers.presets; -import com.seibel.distanthorizons.core.config.ConfigBase; -import com.seibel.distanthorizons.core.config.ConfigEntryWithPresetOptions; +import com.seibel.distanthorizons.core.config.ConfigHandler; +import com.seibel.distanthorizons.core.config.ConfigPresetOptions; import com.seibel.distanthorizons.core.config.listeners.IConfigListener; +import com.seibel.distanthorizons.core.config.types.AbstractConfigBase; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.util.TimerUtil; import com.seibel.distanthorizons.core.wrapperInterfaces.config.IConfigGui; -import com.seibel.distanthorizons.coreapi.interfaces.config.IConfigEntry; import com.seibel.distanthorizons.coreapi.util.StringUtil; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -42,7 +42,7 @@ public abstract class AbstractPresetConfigEventHandler> configList = new ArrayList<>(); + protected final ArrayList> configList = new ArrayList<>(); /** this timer is used so each preset isn't applied while a user is clicking through the config options */ protected Timer applyPresetTimer = null; /** the enum to apply after the timer expires or the UI screen changes. */ @@ -90,7 +90,7 @@ public abstract class AbstractPresetConfigEventHandler configEntry : this.configList) + for (ConfigPresetOptions configEntry : this.configList) { configEntry.updateConfigEntry(newPresetEnum); } @@ -200,7 +200,7 @@ public abstract class AbstractPresetConfigEventHandler configEntry : this.configList) + for (ConfigPresetOptions configEntry : this.configList) { HashSet optionPresetSet = configEntry.getPossibleQualitiesFromCurrentOptionValue(); possiblePresetSet.retainAll(optionPresetSet); @@ -230,7 +230,7 @@ public abstract class AbstractPresetConfigEventHandler getPresetConfigEntry(); + protected abstract AbstractConfigBase getPresetConfigEntry(); protected abstract List getPresetEnumList(); protected abstract TPresetEnum getCustomPresetEnum(); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/RenderQualityPresetConfigEventHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/RenderQualityPresetConfigEventHandler.java index f089fb96e..de2d3672e 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/RenderQualityPresetConfigEventHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/RenderQualityPresetConfigEventHandler.java @@ -26,9 +26,9 @@ import com.seibel.distanthorizons.api.enums.config.EDhApiVerticalQuality; import com.seibel.distanthorizons.api.enums.config.quickOptions.EDhApiQualityPreset; import com.seibel.distanthorizons.api.enums.rendering.EDhApiTransparency; import com.seibel.distanthorizons.core.config.Config; -import com.seibel.distanthorizons.core.config.ConfigEntryWithPresetOptions; +import com.seibel.distanthorizons.core.config.ConfigPresetOptions; import com.seibel.distanthorizons.core.config.listeners.ConfigChangeListener; -import com.seibel.distanthorizons.coreapi.interfaces.config.IConfigEntry; +import com.seibel.distanthorizons.core.config.types.AbstractConfigBase; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -42,7 +42,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE private static final Logger LOGGER = LogManager.getLogger(); - private final ConfigEntryWithPresetOptions drawResolution = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.maxHorizontalResolution, + private final ConfigPresetOptions drawResolution = new ConfigPresetOptions<>(Config.Client.Advanced.Graphics.Quality.maxHorizontalResolution, new HashMap() {{ this.put(EDhApiQualityPreset.MINIMUM, EDhApiMaxHorizontalResolution.TWO_BLOCKS); @@ -51,7 +51,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.HIGH, EDhApiMaxHorizontalResolution.BLOCK); this.put(EDhApiQualityPreset.EXTREME, EDhApiMaxHorizontalResolution.BLOCK); }}); - private final ConfigEntryWithPresetOptions verticalQuality = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.verticalQuality, + private final ConfigPresetOptions verticalQuality = new ConfigPresetOptions<>(Config.Client.Advanced.Graphics.Quality.verticalQuality, new HashMap() {{ this.put(EDhApiQualityPreset.MINIMUM, EDhApiVerticalQuality.HEIGHT_MAP); @@ -60,7 +60,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.HIGH, EDhApiVerticalQuality.HIGH); this.put(EDhApiQualityPreset.EXTREME, EDhApiVerticalQuality.EXTREME); }}); - private final ConfigEntryWithPresetOptions horizontalQuality = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.horizontalQuality, + private final ConfigPresetOptions horizontalQuality = new ConfigPresetOptions<>(Config.Client.Advanced.Graphics.Quality.horizontalQuality, new HashMap() {{ this.put(EDhApiQualityPreset.MINIMUM, EDhApiHorizontalQuality.LOWEST); @@ -69,7 +69,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.HIGH, EDhApiHorizontalQuality.HIGH); this.put(EDhApiQualityPreset.EXTREME, EDhApiHorizontalQuality.EXTREME); }}); - private final ConfigEntryWithPresetOptions transparency = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.transparency, + private final ConfigPresetOptions transparency = new ConfigPresetOptions<>(Config.Client.Advanced.Graphics.Quality.transparency, new HashMap() {{ this.put(EDhApiQualityPreset.MINIMUM, EDhApiTransparency.DISABLED); @@ -78,7 +78,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.HIGH, EDhApiTransparency.COMPLETE); this.put(EDhApiQualityPreset.EXTREME, EDhApiTransparency.COMPLETE); }}); - private final ConfigEntryWithPresetOptions ssaoEnabled = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Ssao.enableSsao, + private final ConfigPresetOptions ssaoEnabled = new ConfigPresetOptions<>(Config.Client.Advanced.Graphics.Ssao.enableSsao, new HashMap() {{ this.put(EDhApiQualityPreset.MINIMUM, false); @@ -87,7 +87,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.HIGH, true); this.put(EDhApiQualityPreset.EXTREME, true); }}); - private final ConfigEntryWithPresetOptions vanillaFade = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.vanillaFadeMode, + private final ConfigPresetOptions vanillaFade = new ConfigPresetOptions<>(Config.Client.Advanced.Graphics.Quality.vanillaFadeMode, new HashMap() {{ this.put(EDhApiQualityPreset.MINIMUM, EDhApiMcRenderingFadeMode.NONE); @@ -96,7 +96,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.HIGH, EDhApiMcRenderingFadeMode.DOUBLE_PASS); this.put(EDhApiQualityPreset.EXTREME, EDhApiMcRenderingFadeMode.DOUBLE_PASS); }}); - private final ConfigEntryWithPresetOptions dhDither = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.ditherDhFade, + private final ConfigPresetOptions dhDither = new ConfigPresetOptions<>(Config.Client.Advanced.Graphics.Quality.ditherDhFade, new HashMap() {{ this.put(EDhApiQualityPreset.MINIMUM, false); @@ -105,7 +105,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.HIGH, true); this.put(EDhApiQualityPreset.EXTREME, true); }}); - private final ConfigEntryWithPresetOptions caveCulling = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Culling.enableCaveCulling, + private final ConfigPresetOptions caveCulling = new ConfigPresetOptions<>(Config.Client.Advanced.Graphics.Culling.enableCaveCulling, new HashMap() {{ this.put(EDhApiQualityPreset.MINIMUM, true); @@ -114,7 +114,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.put(EDhApiQualityPreset.HIGH, false); this.put(EDhApiQualityPreset.EXTREME, false); }}); - private final ConfigEntryWithPresetOptions biomeBlending = new ConfigEntryWithPresetOptions<>(Config.Client.Advanced.Graphics.Quality.lodBiomeBlending, + private final ConfigPresetOptions biomeBlending = new ConfigPresetOptions<>(Config.Client.Advanced.Graphics.Quality.lodBiomeBlending, new HashMap() {{ this.put(EDhApiQualityPreset.MINIMUM, 0); @@ -145,7 +145,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE this.configList.add(this.biomeBlending); - for (ConfigEntryWithPresetOptions config : this.configList) + for (ConfigPresetOptions config : this.configList) { // ignore try-using, the listener should only ever be added once and should never be removed new ConfigChangeListener<>(config.configEntry, (val) -> { this.onConfigValueChanged(); }); @@ -159,7 +159,7 @@ public class RenderQualityPresetConfigEventHandler extends AbstractPresetConfigE //==============// @Override - protected IConfigEntry getPresetConfigEntry() { return Config.Client.qualityPresetSetting; } + protected AbstractConfigBase getPresetConfigEntry() { return Config.Client.qualityPresetSetting; } @Override protected List getPresetEnumList() { return Arrays.asList(EDhApiQualityPreset.values()); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/ThreadPresetConfigEventHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/ThreadPresetConfigEventHandler.java index b02b01ff7..9adee3d7b 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/ThreadPresetConfigEventHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/eventHandlers/presets/ThreadPresetConfigEventHandler.java @@ -22,8 +22,8 @@ package com.seibel.distanthorizons.core.config.eventHandlers.presets; import com.seibel.distanthorizons.api.enums.config.quickOptions.EDhApiThreadPreset; import com.seibel.distanthorizons.core.config.listeners.ConfigChangeListener; import com.seibel.distanthorizons.core.config.Config; -import com.seibel.distanthorizons.core.config.ConfigEntryWithPresetOptions; -import com.seibel.distanthorizons.coreapi.interfaces.config.IConfigEntry; +import com.seibel.distanthorizons.core.config.ConfigPresetOptions; +import com.seibel.distanthorizons.core.config.types.AbstractConfigBase; import com.seibel.distanthorizons.coreapi.util.MathUtil; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -41,7 +41,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan public static int getDefaultThreadCount() { return getThreadCountByPercent(0.5); } - private final ConfigEntryWithPresetOptions threadCount = new ConfigEntryWithPresetOptions<>(Config.Common.MultiThreading.numberOfThreads, + private final ConfigPresetOptions threadCount = new ConfigPresetOptions<>(Config.Common.MultiThreading.numberOfThreads, new HashMap() {{ this.put(EDhApiThreadPreset.MINIMAL_IMPACT, getThreadCountByPercent(0.1)); @@ -51,7 +51,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan this.put(EDhApiThreadPreset.I_PAID_FOR_THE_WHOLE_CPU, getThreadCountByPercent(1.0)); }}); public static double getDefaultRunTimeRatio() { return 1.0; } - private final ConfigEntryWithPresetOptions threadRunTime = new ConfigEntryWithPresetOptions<>(Config.Common.MultiThreading.threadRunTimeRatio, + private final ConfigPresetOptions threadRunTime = new ConfigPresetOptions<>(Config.Common.MultiThreading.threadRunTimeRatio, new HashMap() {{ this.put(EDhApiThreadPreset.MINIMAL_IMPACT, 0.5); @@ -74,7 +74,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan this.configList.add(this.threadCount); this.configList.add(this.threadRunTime); - for (ConfigEntryWithPresetOptions config : this.configList) + for (ConfigPresetOptions config : this.configList) { // ignore try-using, the listeners should only ever be added once and should never be removed new ConfigChangeListener<>(config.configEntry, (val) -> { this.onConfigValueChanged(); }); @@ -119,7 +119,7 @@ public class ThreadPresetConfigEventHandler extends AbstractPresetConfigEventHan //==============// @Override - protected IConfigEntry getPresetConfigEntry() { return Config.Client.threadPresetSetting; } + protected AbstractConfigBase getPresetConfigEntry() { return Config.Client.threadPresetSetting; } @Override protected List getPresetEnumList() { return Arrays.asList(EDhApiThreadPreset.values()); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandler.java index 948b0120d..b86c9fef1 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandler.java @@ -20,13 +20,12 @@ package com.seibel.distanthorizons.core.config.file; import com.electronwill.nightconfig.core.file.CommentedFileConfig; +import com.seibel.distanthorizons.core.config.ConfigHandler; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; -import com.seibel.distanthorizons.core.config.ConfigBase; -import com.seibel.distanthorizons.core.config.types.AbstractConfigType; +import com.seibel.distanthorizons.core.config.types.AbstractConfigBase; import com.seibel.distanthorizons.core.config.types.ConfigEntry; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; -import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper; import com.seibel.distanthorizons.coreapi.ModInfo; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -47,7 +46,6 @@ public class ConfigFileHandler private static final Logger LOGGER = DhLoggerBuilder.getLogger(); - public final ConfigBase configBase; public final Path configPath; private final Logger logger; @@ -64,10 +62,9 @@ public class ConfigFileHandler // constructor // //=============// - public ConfigFileHandler(ConfigBase configBase, Path configPath) + public ConfigFileHandler(Path configPath) { this.logger = LogManager.getLogger(this.getClass().getSimpleName() + ", " + ModInfo.ID); - this.configBase = configBase; this.configPath = configPath; this.nightConfig = CommentedFileConfig @@ -104,7 +101,7 @@ public class ConfigFileHandler this.loadNightConfig(nightConfig); - for (AbstractConfigType entry : this.configBase.entries) + for (AbstractConfigBase entry : ConfigHandler.INSTANCE.configEntryList) { if (ConfigEntry.class.isAssignableFrom(entry.getClass())) { @@ -142,7 +139,7 @@ public class ConfigFileHandler { this.readWriteLock.lock(); - int currentCfgVersion = this.configBase.configVersion; + int currentCfgVersion = ConfigHandler.INSTANCE.configVersion; try { // Dont load the real `this.nightConfig`, instead create a tempoary one @@ -154,13 +151,13 @@ public class ConfigFileHandler } catch (Exception ignored) { } - if (currentCfgVersion == this.configBase.configVersion) + if (currentCfgVersion == ConfigHandler.INSTANCE.configVersion) { // handle normally } - else if (currentCfgVersion > this.configBase.configVersion) + else if (currentCfgVersion > ConfigHandler.INSTANCE.configVersion) { - this.logger.warn("Found config version [" + currentCfgVersion + "] which is newer than current mods config version of [" + this.configBase.configVersion + "]. You may have downgraded the mod and items may have been moved, you have been warned"); + this.logger.warn("Found config version [" + currentCfgVersion + "] which is newer than current mods config version of [" + ConfigHandler.INSTANCE.configVersion + "]. You may have downgraded the mod and items may have been moved, you have been warned"); } else // if (currentCfgVersion < configBase.configVersion) { @@ -176,7 +173,7 @@ public class ConfigFileHandler } this.loadFromFile(this.nightConfig); - this.nightConfig.set("_version", this.configBase.configVersion); + this.nightConfig.set("_version", ConfigHandler.INSTANCE.configVersion); } finally { @@ -202,7 +199,7 @@ public class ConfigFileHandler // Load all the entries - for (AbstractConfigType entry : this.configBase.entries) + for (AbstractConfigBase entry : ConfigHandler.INSTANCE.configEntryList) { if (ConfigEntry.class.isAssignableFrom(entry.getClass()) && entry.getAppearance().showInFile) @@ -246,10 +243,10 @@ public class ConfigFileHandler else if (entry.getTrueValue() == null) { // TODO when can this happen? - throw new IllegalArgumentException("Entry [" + entry.getNameWCategory() + "] is null, this may be a problem with [" + ModInfo.NAME + "]. Please contact the authors."); + throw new IllegalArgumentException("Entry [" + entry.getNameAndCategory() + "] is null, this may be a problem with [" + ModInfo.NAME + "]. Please contact the authors."); } - workConfig.set(entry.getNameWCategory(), ConfigTypeConverters.attemptToConvertToString(entry.getType(), entry.getTrueValue())); + workConfig.set(entry.getNameAndCategory(), ConfigTypeConverters.attemptToConvertToString(entry.getType(), entry.getTrueValue())); } /** Loads an entry when only given the entry */ @@ -259,9 +256,11 @@ public class ConfigFileHandler public void loadEntry(ConfigEntry entry, CommentedFileConfig nightConfig) { if (!entry.getAppearance().showInFile) + { return; + } - if (!nightConfig.contains(entry.getNameWCategory())) + if (!nightConfig.contains(entry.getNameAndCategory())) { this.saveEntry(entry, nightConfig); return; @@ -272,13 +271,13 @@ public class ConfigFileHandler { if (entry.getType().isEnum()) { - entry.pureSet((T) (nightConfig.getEnum(entry.getNameWCategory(), (Class) entry.getType()))); + entry.setWithoutFiringEvents((T) (nightConfig.getEnum(entry.getNameAndCategory(), (Class) entry.getType()))); return; } // try converting the value if necessary Class expectedValueClass = entry.getType(); - Object value = nightConfig.get(entry.getNameWCategory()); + Object value = nightConfig.get(entry.getNameAndCategory()); Object convertedValue = ConfigTypeConverters.attemptToConvertFromString(expectedValueClass, value); if (!convertedValue.getClass().equals(expectedValueClass)) { @@ -287,19 +286,18 @@ public class ConfigFileHandler "Make sure a converter is defined in ["+ConfigTypeConverters.class.getSimpleName()+"]."); convertedValue = entry.getDefaultValue(); } - entry.pureSet((T) convertedValue); + entry.setWithoutFiringEvents((T) convertedValue); if (entry.getTrueValue() == null) { - this.logger.warn("Entry [" + entry.getNameWCategory() + "] returned as null from the config. Using default value."); - entry.pureSet(entry.getDefaultValue()); + this.logger.warn("Entry [" + entry.getNameAndCategory() + "] returned as null from the config. Using default value."); + entry.setWithoutFiringEvents(entry.getDefaultValue()); } } catch (Exception e) { -// e.printStackTrace(); - this.logger.warn("Entry [" + entry.getNameWCategory() + "] had an invalid value when loading the config. Using default value."); - entry.pureSet(entry.getDefaultValue()); + this.logger.warn("Entry [" + entry.getNameAndCategory() + "] had an invalid value when loading the config. Using default value."); + entry.setWithoutFiringEvents(entry.getDefaultValue()); } } @@ -320,7 +318,7 @@ public class ConfigFileHandler // the new line makes it easier to read and separate configs // the space makes sure the first word of a comment isn't directly in line with the "#" comment = "\n " + comment; - nightConfig.setComment(entry.getNameWCategory(), comment); + nightConfig.setComment(entry.getNameAndCategory(), comment); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/AbstractConfigType.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/AbstractConfigBase.java similarity index 86% rename from core/src/main/java/com/seibel/distanthorizons/core/config/types/AbstractConfigType.java rename to core/src/main/java/com/seibel/distanthorizons/core/config/types/AbstractConfigBase.java index 7b91e6c33..65e17e790 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/AbstractConfigType.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/AbstractConfigBase.java @@ -19,24 +19,22 @@ package com.seibel.distanthorizons.core.config.types; -import com.seibel.distanthorizons.core.config.ConfigBase; import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance; /** - * The class where all config options should extend + * The class all config options should extend * * @author coolGi */ -// Note for devs: The "S" is the class that is extending this -public abstract class AbstractConfigType +public abstract class AbstractConfigBase { public String category = ""; // This should only be set once in the init public String name; // This should only be set once in the init protected final T defaultValue; protected final boolean isFloatingPointNumber; protected T value; - public ConfigBase configBase; + @Deprecated public Object guiValue; // This is a storage variable something like the gui can use protected EConfigEntryAppearance appearance; @@ -47,7 +45,7 @@ public abstract class AbstractConfigType // constructor // //=============// - protected AbstractConfigType(EConfigEntryAppearance appearance, T defaultValue) + protected AbstractConfigBase(EConfigEntryAppearance appearance, T defaultValue) { this.defaultValue = defaultValue; this.value = defaultValue; @@ -74,7 +72,7 @@ public abstract class AbstractConfigType public String getCategory() { return this.category; } public String getName() { return this.name; } - public String getNameWCategory() { return (this.category.isEmpty() ? "" : this.category + ".") + this.name; } + public String getNameAndCategory() { return (this.category.isEmpty() ? "" : this.category + ".") + this.name; } /** Gets the class of T */ diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigCategory.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigCategory.java index cf8fa1c26..a295cf1f8 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigCategory.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigCategory.java @@ -27,10 +27,19 @@ import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance * * @author coolGi */ -public class ConfigCategory extends AbstractConfigType, ConfigCategory> +public class ConfigCategory extends AbstractConfigBase> { - /** This should not be set by anything other than the config system itself */ - public String destination; // Where the category goes to + /** + * Defines where this category points to.
+ * May be defined during config setup. + */ + public String destination; + + + + //=============// + // constructor // + //=============// private ConfigCategory(EConfigEntryAppearance appearance, Class value, String destination) { @@ -38,20 +47,26 @@ public class ConfigCategory extends AbstractConfigType, ConfigCategory> this.destination = destination; } - public String getDestination() - { - return this.destination; - } + + + //==================// + // property getters // + //==================// + + public String getDestination() { return this.destination; } /** Use get() instead for category */ @Override @Deprecated - public Class getType() - { - return value; - } + public Class getType() { return this.value; } - public static class Builder extends AbstractConfigType.Builder, Builder> + + + //=========// + // builder // + //=========// + + public static class Builder extends AbstractConfigBase.Builder, Builder> { private String tmpDestination = null; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java index 6e9b34588..01b876c82 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigEntry.java @@ -20,13 +20,14 @@ package com.seibel.distanthorizons.core.config.types; -import com.seibel.distanthorizons.core.config.NumberUtil; +import com.seibel.distanthorizons.core.config.ConfigHandler; +import com.seibel.distanthorizons.core.util.NumberUtil; import com.seibel.distanthorizons.core.config.file.ConfigFileHandler; import com.seibel.distanthorizons.core.config.listeners.ConfigChangeListener; import com.seibel.distanthorizons.core.config.listeners.IConfigListener; import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance; import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryPerformance; -import com.seibel.distanthorizons.coreapi.interfaces.config.IConfigEntry; +import com.seibel.distanthorizons.core.config.types.enums.EConfigValidity; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -34,15 +35,13 @@ import java.util.Arrays; import java.util.function.Consumer; /** - * Use for making the config variables - * for types that are not supported by it look in ConfigBase + * This config type allows for entering text, number, or enum values. * * @author coolGi - * @version 2023-7-16 */ -public class ConfigEntry extends AbstractConfigType> implements IConfigEntry +public class ConfigEntry extends AbstractConfigBase { - private String comment; + private final String comment; private T min; private T max; private final ArrayList listenerList; @@ -50,23 +49,26 @@ public class ConfigEntry extends AbstractConfigType> implem private final EConfigEntryPerformance performance; - // API control // /** * If true this config can be controlled by the API
* and any get() method calls will return the apiValue if it is set. */ - public final boolean allowApiOverride; + private final boolean allowApiOverride; /** Will be null if un-set */ @Nullable private T apiValue; - /** Creates the entry */ + //=============// + // constructor // + //=============// + private ConfigEntry( EConfigEntryAppearance appearance, - T value, String comment, T min, T max, - String chatCommandName, boolean allowApiOverride, + String comment, String chatCommandName, + T value, T min, T max, + boolean allowApiOverride, EConfigEntryPerformance performance, ArrayList listenerList) { @@ -83,34 +85,55 @@ public class ConfigEntry extends AbstractConfigType> implem - /** Gets the default value of the option */ - @Override - public T getDefaultValue() { return super.defaultValue; } + //==========================// + // property getters/setters // + //==========================// + + /** the string used when entering the config into the command line or chat */ + public String getChatCommandName() { return this.chatCommandName; } + + public String getComment() { return this.comment; } + + /** Gets the performance impact of an option */ + public EConfigEntryPerformance getPerformance() { return this.performance; } + + /** + * If true this config can be controlled by the API
+ * and any get() method calls will return the apiValue if it is set. + */ + public boolean getAllowApiOverride() { return this.allowApiOverride; } + + public T getMin() { return this.min; } + public void setMin(T newMin) { this.min = newMin; } + public T getMax() { return this.max; } + public void setMax(T newMax) { this.max = newMax; } + + + + //===============// + // value setters // + //===============// - @Override public void setApiValue(T newApiValue) { this.apiValue = newApiValue; this.listenerList.forEach(IConfigListener::onConfigValueSet); } - @Override - public T getApiValue() { return this.apiValue; } - @Override - public boolean apiIsOverriding() { return this.allowApiOverride && this.apiValue != null; } - @Override - public boolean getAllowApiOverride() { return this.allowApiOverride; } - /** - * DONT USE THIS IN YOUR CODE
- * Sets the value without informing the rest of the code (ie, doesnt call listeners, or saves the value).
- * Should only be used when loading the config from the file (in places like the {@link ConfigFileHandler} or {@link com.seibel.distanthorizons.core.config.ConfigBase}) - */ - public void pureSet(T newValue) { - super.set(newValue); + public boolean apiIsOverriding() + { + return this.allowApiOverride + && this.apiValue != null; } + + /** + * Should only be used when loading the config from file.
+ * Sets the value without informing the rest of the code (ie, it doesn't call listeners, or saving the value to file). + * @see ConfigFileHandler + */ + public void setWithoutFiringEvents(T newValue) { super.set(newValue); } /** Sets the value without saving */ - @Override public void setWithoutSaving(T newValue) { super.set(newValue); @@ -135,74 +158,35 @@ public class ConfigEntry extends AbstractConfigType> implem } + + //===============// + // value getters // + //===============// + @Override public T get() { - if (this.allowApiOverride && this.apiValue != null) + if (this.allowApiOverride + && this.apiValue != null) { return this.apiValue; } return super.get(); } - @Override - public T getTrueValue() - { - return super.get(); - } + /** Ignores the API value if set. */ + public T getTrueValue() { return super.get(); } + + public T getDefaultValue() { return super.defaultValue; } + + @Nullable + public T getApiValue() { return this.apiValue; } - /** Gets the min value */ - @Override - public T getMin() { return this.min; } - /** Sets the min value */ - @Override - public void setMin(T newMin) { this.min = newMin; } - /** Gets the max value */ - @Override - public T getMax() { return this.max; } - /** Sets the max value */ - @Override - public void setMax(T newMax) { this.max = newMax; } - /** Sets the min and max within a single setter */ - @Override - public void setMinMax(T newMin, T newMax) - { - this.setMin(newMin); - this.setMax(newMax); - } - /** - * Clamps the value within the set range - * - * @apiNote This does not save the value - */ - public void clampWithinRange() { this.clampWithinRange(this.min, this.max); } - /** - * Clamps the value within a set range - * - * @param min The minimum that the value can be - * @param max The maximum that the value can be - * @apiNote This does not save the value - */ - @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(this.value.getClass()); - if (validness == 1) this.value = (T) NumberUtil.getMaximum(this.value.getClass()); - } - - // TODO is this for command line use? - public String getChatCommandName() { return this.chatCommandName; } - - @Override - public String getComment() { return this.comment; } - @Override - public void setComment(String newComment) { this.comment = newComment; } - - /** Gets the performance impact of an option */ - public EConfigEntryPerformance getPerformance() { return this.performance; } + //===========// + // listeners // + //===========// /** Fired whenever the config value changes to a new value. */ public void addValueChangeListener(Consumer onValueChangeFunc) @@ -227,107 +211,104 @@ public class ConfigEntry extends AbstractConfigType> implem public void setListeners(IConfigListener... newListeners) { this.listenerList.addAll(Arrays.asList(newListeners)); } - /** - * Checks if the option is valid - * - * @return 0 == valid - *

2 == invalid - *

1 == number too high - *

-1 == number too low - */ - @Override - public byte isValid() { return isValid(this.value, this.min, this.max); } - /** - * Checks if a new value is valid - * - * @param value Value that is being checked whether valid - * @return 0 == valid - *

2 == invalid - *

1 == number too high - *

-1 == number too low - */ - @Override - public byte isValid(T value) { return this.isValid(value, this.min, this.max); } - /** - * Checks if a new value is valid - * - * @param min The minimum that the value can be - * @param max The maximum that the value can be - * @return 0 == valid - *

2 == invalid - *

1 == number too high - *

-1 == number too low - */ - public byte isValid(T min, T max) { return this.isValid(this.value, min, max); } - /** - * Checks if a new value is valid - * - * @param value Value that is being checked whether valid - * @param min The minimum that the value can be - * @param max The maximum that the value can be - * @return 0 == valid - *

2 == invalid - *

1 == number too high - *

-1 == number too low - */ - public byte isValid(T value, T min, T max) + + //====================// + // min/max validation // + //====================// + + /** Checks if this config's current value is valid */ + public EConfigValidity getValidity() { return this.getValidity(this.value, this.min, this.max); } + /** Checks if the given value is valid */ + public EConfigValidity getValidity(@Nullable T value) { return this.getValidity(value, this.min, this.max); } + /** Checks if the given value is valid */ + public EConfigValidity getValidity(@Nullable T value, @Nullable T min, @Nullable T max) { - if (this.configBase.disableMinMax) + if (ConfigHandler.INSTANCE.runMinMaxValidation) { - return 0; + return EConfigValidity.VALID; } - else if (min == null && max == null) + else if (min == null + && max == null) { // no validation is needed for this field - return 0; + return EConfigValidity.VALID; } - else if (value == null || this.value == null + else if (value == null + || this.value == null || value.getClass() != this.value.getClass()) { - // If the 2 variables aren't the same type then it will be invalid - return 2; + // If the 2 variables aren't the same type + // or the input is missing + // then it will be invalid + return EConfigValidity.INVALID; } - else if (Number.class.isAssignableFrom(value.getClass())) + else if (value instanceof Number) { - // Only check min max if it is a number - if (max != null && NumberUtil.greaterThan((Number) value, (Number) max)) + // Only check min/max if this config's type is a number + if (max != null + && NumberUtil.greaterThan((Number) value, (Number) max)) { - return 1; - } - if (min != null && NumberUtil.lessThan((Number) value, (Number) min)) - { - return -1; + return EConfigValidity.NUMBER_TOO_HIGH; } - return 0; + if (min != null + && NumberUtil.lessThan((Number) value, (Number) min)) + { + return EConfigValidity.NUMBER_TOO_LOW; + } + + return EConfigValidity.VALID; } else { - return 0; + return EConfigValidity.VALID; } } + + + //===============// + // file handling // + //===============// + /** This should normally not be called since set() automatically calls this */ - public void save() { configBase.configFileHandler.saveEntry(this); } + public void save() { ConfigHandler.INSTANCE.configFileHandler.saveEntry(this); } /** This should normally not be called except for special circumstances */ - public void load() { configBase.configFileHandler.loadEntry(this); } + public void load() { ConfigHandler.INSTANCE.configFileHandler.loadEntry(this); } - @Override - public boolean equals(IConfigEntry obj) { return obj.getClass() == ConfigEntry.class && equals((ConfigEntry) obj); } + + //================// + // base overrides // + //================// + + public boolean equals(AbstractConfigBase obj) + { + return obj.getClass() == ConfigEntry.class + && this.equals((ConfigEntry) obj); + } /** Is the value of this equal to another */ public boolean equals(ConfigEntry obj) { // Can all of this just be "return this.value.equals(obj.value)"? if (Number.class.isAssignableFrom(this.value.getClass())) + { return this.value == obj.value; + } else + { return this.value.equals(obj.value); + } } - public static class Builder extends AbstractConfigType.Builder> + + //=========// + // builder // + //=========// + + public static class Builder extends AbstractConfigBase.Builder> { private String tmpComment = null; private T tmpMin = null; @@ -337,6 +318,8 @@ public class ConfigEntry extends AbstractConfigType> implem private EConfigEntryPerformance tmpPerformance = EConfigEntryPerformance.DONT_SHOW; protected ArrayList tmpIConfigListener = new ArrayList<>(); + + public Builder comment(String newComment) { this.tmpComment = newComment; @@ -416,12 +399,14 @@ public class ConfigEntry extends AbstractConfigType> implem + // build // + public ConfigEntry build() { return new ConfigEntry<>( - this.tmpAppearance, - this.tmpValue, this.tmpComment, this.tmpMin, this.tmpMax, - this.tmpChatCommandName, this.tmpUseApiOverwrite, + this.tmpAppearance, + this.tmpComment, this.tmpChatCommandName, this.tmpValue, this.tmpMin, this.tmpMax, + this.tmpUseApiOverwrite, this.tmpPerformance, this.tmpIConfigListener); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIButton.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIButton.java index e23f3fa28..41a077793 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIButton.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIButton.java @@ -21,29 +21,42 @@ package com.seibel.distanthorizons.core.config.types; import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance; -public class ConfigUIButton extends AbstractConfigType +public class ConfigUIButton extends AbstractConfigBase { - public ConfigUIButton(Runnable runnable) - { - super(EConfigEntryAppearance.ONLY_IN_GUI, runnable); - } + //=============// + // constructor // + //=============// - /** Runs the action of the button. NOTE: Will run on the main thread (so can halt the main process if not offloaded to a different thread) */ + public ConfigUIButton(Runnable runnable) + { super(EConfigEntryAppearance.ONLY_IN_GUI, runnable); } + + + + //=========// + // actions // + //=========// + + /** + * Runs the action of the button. + * NOTE: This will run on the render thread + * (so it can halt the main process if it takes too long and isn't offloaded to another thread) + */ public void runAction() { this.value.run(); } - public static class Builder extends AbstractConfigType.Builder + + + //=========// + // builder // + //=========// + + public static class Builder extends AbstractConfigBase.Builder { /** Appearance shouldn't be changed */ @Override - public Builder setAppearance(EConfigEntryAppearance newAppearance) - { - return this; - } + public Builder setAppearance(EConfigEntryAppearance newAppearance) { return this; } public ConfigUIButton build() - { - return new ConfigUIButton(this.tmpValue); - } + { return new ConfigUIButton(this.tmpValue); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIComment.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIComment.java index 46dbb0e40..a34f97e94 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIComment.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUIComment.java @@ -32,7 +32,7 @@ import org.jetbrains.annotations.Nullable; * * @author coolGi */ -public class ConfigUIComment extends AbstractConfigType +public class ConfigUIComment extends AbstractConfigBase { private static final Logger LOGGER = DhLoggerBuilder.getLogger(); @@ -43,8 +43,11 @@ public class ConfigUIComment extends AbstractConfigType - public ConfigUIComment() { this(null, null); } - public ConfigUIComment(String parentConfigPath, EConfigCommentTextPosition textPosition) + //=============// + // constructor // + //=============// + + public ConfigUIComment(String parentConfigPath, @Nullable EConfigCommentTextPosition textPosition) { super(EConfigEntryAppearance.ONLY_IN_GUI, ""); this.parentConfigPath = parentConfigPath; @@ -53,6 +56,10 @@ public class ConfigUIComment extends AbstractConfigType + //=========// + // setters // + //=========// + /** Appearance shouldn't be changed */ @Override public void setAppearance(EConfigEntryAppearance newAppearance) { } @@ -63,9 +70,14 @@ public class ConfigUIComment extends AbstractConfigType - public static class Builder extends AbstractConfigType.Builder + //=========// + // builder // + //=========// + + public static class Builder extends AbstractConfigBase.Builder { public String tempParentConfigPath = null; + @Nullable public EConfigCommentTextPosition tempTextPosition = null; @@ -155,9 +167,13 @@ public class ConfigUIComment extends AbstractConfigType + // build // + public ConfigUIComment build() { return new ConfigUIComment(this.tempParentConfigPath, this.tempTextPosition); } } + + } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUISpacer.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUISpacer.java index 43d870cdf..4f8ce4267 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUISpacer.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUISpacer.java @@ -25,13 +25,21 @@ import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance * Adds empty space the height of a button. * Useful for separating different categories. */ -public class ConfigUISpacer extends AbstractConfigType +public class ConfigUISpacer extends AbstractConfigBase { + //=============// + // constructor // + //=============// + public ConfigUISpacer() { super(EConfigEntryAppearance.ONLY_IN_GUI, ""); } + //=========// + // setters // + //=========// + /** Appearance shouldn't be changed */ @Override public void setAppearance(EConfigEntryAppearance newAppearance) { } @@ -42,7 +50,11 @@ public class ConfigUISpacer extends AbstractConfigType - public static class Builder extends AbstractConfigType.Builder + //=========// + // builder // + //=========// + + public static class Builder extends AbstractConfigBase.Builder { /** Appearance shouldn't be changed */ @Override diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUiLinkedEntry.java b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUiLinkedEntry.java index 2e515951f..ff164c82e 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUiLinkedEntry.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/types/ConfigUiLinkedEntry.java @@ -23,16 +23,24 @@ import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance /** * Creates a UI element that copies everything from another element. - * This only effects the UI + * This element is only visible in the GUI. * * @author coolGi */ -public class ConfigUiLinkedEntry extends AbstractConfigType, ConfigUiLinkedEntry> +public class ConfigUiLinkedEntry extends AbstractConfigBase> { - public ConfigUiLinkedEntry(AbstractConfigType value) - { - super(EConfigEntryAppearance.ONLY_IN_GUI, value); - } + //=============// + // constructor // + //=============// + + public ConfigUiLinkedEntry(AbstractConfigBase value) + { super(EConfigEntryAppearance.ONLY_IN_GUI, value); } + + + + //=========// + // setters // + //=========// /** Appearance shouldn't be changed */ @Override @@ -40,10 +48,15 @@ public class ConfigUiLinkedEntry extends AbstractConfigType newValue) { } + public void set(AbstractConfigBase newValue) { } - public static class Builder extends AbstractConfigType.Builder, Builder> + + //=========// + // builder // + //=========// + + public static class Builder extends AbstractConfigBase.Builder, Builder> { /** Appearance shouldn't be changed */ @Override @@ -59,4 +72,6 @@ public class ConfigUiLinkedEntry extends AbstractConfigType worldGeneratorEnabledConfig; @Nullable private final SyncOnLoadRequestQueue syncOnLoadRequestQueue; @@ -134,7 +132,6 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel } this.dataFileHandler = new RemoteFullDataSourceProvider(this, saveStructure, fullDataSaveDirOverride, this.syncOnLoadRequestQueue); - this.worldGeneratorEnabledConfig = new AppliedConfigState<>(Config.Common.WorldGenerator.enableDistantGeneration); this.worldGenModule = new WorldGenModule(this, this.dataFileHandler, () -> new WorldGenState(this, networkState)); this.clientside = new ClientLevelModule(this); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/NumberUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/NumberUtil.java similarity index 74% rename from core/src/main/java/com/seibel/distanthorizons/core/config/NumberUtil.java rename to core/src/main/java/com/seibel/distanthorizons/core/util/NumberUtil.java index a6e4b9cb5..08aec38f6 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/NumberUtil.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/NumberUtil.java @@ -17,54 +17,50 @@ * along with this program. If not, see . */ -package com.seibel.distanthorizons.core.config; +package com.seibel.distanthorizons.core.util; import java.util.HashMap; import java.util.Map; /** - * Helps with working with numbers that the value of which is unknown + * Helps when working with numbers where the type is unknown. * * @author coolGi - * @version 2023-7-16 */ -// TODO: Should this be moved out of here into somewhere like the util section public class NumberUtil { // Is there no better way of doing this? public static Map, Number> minValues = new HashMap, Number>() {{ - put(Byte.class, Byte.MIN_VALUE); - put(Short.class, Short.MIN_VALUE); - put(Integer.class, Integer.MIN_VALUE); - put(Long.class, Long.MIN_VALUE); - put(Double.class, Double.MIN_VALUE); - put(Float.class, Float.MIN_VALUE); + this.put(Byte.class, Byte.MIN_VALUE); + this.put(Short.class, Short.MIN_VALUE); + this.put(Integer.class, Integer.MIN_VALUE); + this.put(Long.class, Long.MIN_VALUE); + this.put(Double.class, Double.MIN_VALUE); + this. put(Float.class, Float.MIN_VALUE); }}; public static Map, Number> maxValues = new HashMap, Number>() {{ - put(Byte.class, Byte.MAX_VALUE); - put(Short.class, Short.MAX_VALUE); - put(Integer.class, Integer.MAX_VALUE); - put(Long.class, Long.MAX_VALUE); - put(Double.class, Double.MAX_VALUE); - put(Float.class, Float.MAX_VALUE); + this.put(Byte.class, Byte.MAX_VALUE); + this.put(Short.class, Short.MAX_VALUE); + this.put(Integer.class, Integer.MAX_VALUE); + this.put(Long.class, Long.MAX_VALUE); + this.put(Double.class, Double.MAX_VALUE); + this.put(Float.class, Float.MAX_VALUE); }}; - public static Number getMinimum(Class c) - { - return minValues.get(c); - } - public static Number getMaximum(Class c) - { - return maxValues.get(c); - } + + + public static Number getMinimum(Class c) { return minValues.get(c); } + public static Number getMaximum(Class c) { return maxValues.get(c); } /** Does a greater than (>) operator on any number */ public static boolean greaterThan(Number a, Number b) { if (a.getClass() != b.getClass()) + { return false; + } Class typeClass = a.getClass(); if (typeClass == Byte.class) return a.byteValue() > b.byteValue(); @@ -73,6 +69,7 @@ public class NumberUtil if (typeClass == Long.class) return a.longValue() > b.longValue(); if (typeClass == Double.class) return a.doubleValue() > b.doubleValue(); if (typeClass == Float.class) return a.floatValue() > b.floatValue(); + return false; } @@ -80,7 +77,9 @@ public class NumberUtil public static boolean lessThan(Number a, Number b) { if (a.getClass() != b.getClass()) + { return false; + } Class typeClass = a.getClass(); if (typeClass == Byte.class) return a.byteValue() < b.byteValue(); @@ -89,6 +88,7 @@ public class NumberUtil if (typeClass == Long.class) return a.longValue() < b.longValue(); if (typeClass == Double.class) return a.doubleValue() < b.doubleValue(); if (typeClass == Float.class) return a.floatValue() < b.floatValue(); + return false; }