Add IDhApiConfigValue.addChangeListener()
This commit is contained in:
+6
@@ -1,5 +1,7 @@
|
||||
package com.seibel.distanthorizons.api.interfaces.config;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* An interface for Distant Horizon's Config.
|
||||
*
|
||||
@@ -48,4 +50,8 @@ public interface IDhApiConfigValue<T>
|
||||
/** Returns the min value for this config, null if there is no min. */
|
||||
T getMinValue();
|
||||
|
||||
/** Adds a {@link Consumer} that will be called whenever the config changes to a new value. */
|
||||
void addChangeListener(Consumer<T> onValueChangeFunc);
|
||||
//void removeListener(Consumer<T> onValueChangeFunc); // not currently implemented
|
||||
|
||||
}
|
||||
|
||||
+13
-1
@@ -5,6 +5,8 @@ import com.seibel.distanthorizons.coreapi.interfaces.config.IConfigEntry;
|
||||
import com.seibel.distanthorizons.coreapi.interfaces.config.IConverter;
|
||||
import com.seibel.distanthorizons.coreapi.util.converters.DefaultConverter;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* A wrapper used to interface with Distant Horizon's Config. <br> <br>
|
||||
*
|
||||
@@ -68,8 +70,18 @@ public class DhApiConfigValue<coreType, apiType> implements IDhApiConfigValue<ap
|
||||
|
||||
public boolean getCanBeOverrodeByApi() { return this.configEntry.getAllowApiOverride(); }
|
||||
|
||||
public apiType getDefaultValue() { return this.configConverter.convertToApiType(configEntry.getDefaultValue()); }
|
||||
public apiType getDefaultValue() { return this.configConverter.convertToApiType(this.configEntry.getDefaultValue()); }
|
||||
public apiType getMaxValue() { return this.configConverter.convertToApiType(this.configEntry.getMax()); }
|
||||
public apiType getMinValue() { return this.configConverter.convertToApiType(this.configEntry.getMin()); }
|
||||
|
||||
|
||||
public void addChangeListener(Consumer<apiType> onValueChangeFunc)
|
||||
{
|
||||
this.configEntry.addValueChangeListener((coreValue) ->
|
||||
{
|
||||
apiType apiValue = this.configConverter.convertToApiType(coreValue);
|
||||
onValueChangeFunc.accept(apiValue);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -1,6 +1,8 @@
|
||||
package com.seibel.distanthorizons.coreapi.interfaces.config;
|
||||
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Use for making the config variables
|
||||
*
|
||||
@@ -56,4 +58,6 @@ public interface IConfigEntry<T>
|
||||
/** Is the value of this equal to another */
|
||||
boolean equals(IConfigEntry<?> obj);
|
||||
|
||||
void addValueChangeListener(Consumer<T> onValueChangeFunc);
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,9 +3,9 @@ package com.seibel.distanthorizons.core.config.listeners;
|
||||
public interface IConfigListener
|
||||
{
|
||||
/** Called whenever the value is set (including in core DH code) */
|
||||
default void onConfigValueSet() {};
|
||||
default void onConfigValueSet() {}
|
||||
|
||||
/** Called whenever the value is changed through the UI */
|
||||
default void onUiModify() {};
|
||||
default void onUiModify() {}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.seibel.distanthorizons.core.config.types;
|
||||
|
||||
|
||||
import com.seibel.distanthorizons.core.config.NumberUtil;
|
||||
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;
|
||||
@@ -9,6 +10,7 @@ import com.seibel.distanthorizons.coreapi.interfaces.config.IConfigEntry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Use for making the config variables
|
||||
@@ -166,7 +168,16 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
|
||||
/** Gets the performance impact of an option */
|
||||
public EConfigEntryPerformance getPerformance() { return this.performance; }
|
||||
|
||||
/** Fired whenever the config value changes to a new value. */
|
||||
public void addValueChangeListener(Consumer<T> onValueChangeFunc)
|
||||
{
|
||||
ConfigChangeListener<T> changeListener = new ConfigChangeListener<>(this, onValueChangeFunc);
|
||||
this.addListener(changeListener);
|
||||
}
|
||||
/** Fired whenever the config value is updated, including when the value doesn't change (IE when the UI changes state or the config is reloaded). */
|
||||
public void addListener(IConfigListener newListener) { this.listenerList.add(newListener); }
|
||||
|
||||
//public void removeValueChangeListener(Consumer<T> onValueChangeFunc) { } // not currently implemented
|
||||
public void removeListener(IConfigListener oldListener) { this.listenerList.remove(oldListener); }
|
||||
|
||||
public void clearListeners() { this.listenerList.clear(); }
|
||||
|
||||
Reference in New Issue
Block a user