Extract a interface for DhApiConfig

DhApiConfig (and objects like it) should use interface wrapper combos so to prevent issues for implementing devs.
This commit is contained in:
James Seibel
2022-06-09 21:32:19 -05:00
parent 6a15705b51
commit c880d80925
5 changed files with 70 additions and 42 deletions
@@ -0,0 +1,49 @@
package com.seibel.lod.core.api.external.apiObjects.wrapperInterfaces;
/**
* An interface for Distant Horizon's Config.
*
* @param <T>
* @author James Seibel
* @version 2022-6-9
*/
public interface IDhApiConfig_v1<T>
{
/**
* Returns the active value for this config. <br>
* Returns the True value if either the config cannot be overridden by
* the API or if it hasn't been set by the API.
*/
public T getValue();
/**
* Returns the value held by this config. <br>
* This is the value stored in the config file.
*/
public T getTrueValue();
/**
* Returns the value of the config if it was set by the API.
* Returns null if the config wasn't set by the API.
*/
public T getApiValue();
/**
* Sets the config's value. <br>
* If the newValue is set to null then the config
* will revert to using the True Value.<br>
* If the config cannot be set via the API this method will return false.
*
* @return true if the value was set, false otherwise.
*/
public boolean setValue(T newValue);
/** Returns true if this config can be set via the API, false otherwise. */
public boolean getCanBeOverrodeByApi();
/** Returns the default value for this config. */
public T getDefaultValue();
/** Returns the max value for this config, null if there is no max. */
public T getMaxValue();
/** Returns the min value for this config, null if there is no min. */
public T getMinValue();
}
@@ -1,6 +1,7 @@
package com.seibel.lod.core.api.external.config.client;
import com.seibel.lod.core.api.external.apiObjects.objects.DhApiConfig_v1;
import com.seibel.lod.core.api.external.apiObjects.wrapperInterfaces.IDhApiConfig_v1;
import com.seibel.lod.core.api.externalImplementation.apiObjects.wrappers.DhApiConfig_v1;
import com.seibel.lod.core.config.Config.Client.Advanced.Threading;
@@ -8,7 +9,7 @@ import com.seibel.lod.core.config.Config.Client.Advanced.Threading;
* General Threading settings.
*
* @author James Seibel
* @version 2022-6-2
* @version 2022-6-9
*/
public class DhApiThreading
{
@@ -25,12 +26,12 @@ public class DhApiThreading
* 1.5 = 2 threads active 100% of the time (partial values are rounded up) <br>
* 2.0 = 2 threads active 100% of the time <br>
*/
public static DhApiConfig_v1<Double> getWorldGeneratorThreadConfig_v1()
public static IDhApiConfig_v1<Double> getWorldGeneratorThreadConfig_v1()
{ return new DhApiConfig_v1<>(Threading.numberOfWorldGenerationThreads); }
/** Returns the config related to the buffer (GPU Terrain data) builder threads. */
public static DhApiConfig_v1<Integer> getBufferBuilderThreadConfig_v1()
public static IDhApiConfig_v1<Integer> getBufferBuilderThreadConfig_v1()
{ return new DhApiConfig_v1<>(Threading.numberOfBufferBuilderThreads); }
}
@@ -1,8 +1,9 @@
package com.seibel.lod.core.api.external.config.client.graphics;
import com.seibel.lod.core.api.external.apiObjects.wrapperInterfaces.IDhApiConfig_v1;
import com.seibel.lod.core.enums.rendering.EFogColorMode;
import com.seibel.lod.core.enums.rendering.EFogDistance;
import com.seibel.lod.core.api.external.apiObjects.objects.DhApiConfig_v1;
import com.seibel.lod.core.api.externalImplementation.apiObjects.wrappers.DhApiConfig_v1;
import com.seibel.lod.core.config.Config.Client.Graphics.FogQuality;
import com.seibel.lod.core.enums.rendering.EFogDrawMode;
@@ -10,25 +11,25 @@ import com.seibel.lod.core.enums.rendering.EFogDrawMode;
* Any graphics settings related to fog.
*
* @author James Seibel
* @version 2022-6-2
* @version 2022-6-9
*/
public class DhApiGraphicsFog
{
/** Returns the config related to when fog is rendered. */
public static DhApiConfig_v1<EFogDistance> getFogDistanceConfig_v1()
public static IDhApiConfig_v1<EFogDistance> getFogDistanceConfig_v1()
{ return new DhApiConfig_v1<>(FogQuality.fogDistance); }
/** Returns the config related to when fog is rendered. */
public static DhApiConfig_v1<EFogDrawMode> getFogRenderConfig_v1()
public static IDhApiConfig_v1<EFogDrawMode> getFogRenderConfig_v1()
{ return new DhApiConfig_v1<>(FogQuality.fogDrawMode); }
/** Returns the config related to the fog draw type. */
public static DhApiConfig_v1<EFogColorMode> getFogColorConfig_v1()
public static IDhApiConfig_v1<EFogColorMode> getFogColorConfig_v1()
{ return new DhApiConfig_v1<>(FogQuality.fogColorMode); }
/** Returns the config related to disabling vanilla fog. */
public static DhApiConfig_v1<Boolean> getDisableVanillaFogConfig_v1()
public static IDhApiConfig_v1<Boolean> getDisableVanillaFogConfig_v1()
{ return new DhApiConfig_v1<>(FogQuality.disableVanillaFog); }
@@ -1,6 +1,7 @@
package com.seibel.lod.core.api.external.config.client.graphics;
import com.seibel.lod.core.api.external.apiObjects.objects.DhApiConfig_v1;
import com.seibel.lod.core.api.external.apiObjects.wrapperInterfaces.IDhApiConfig_v1;
import com.seibel.lod.core.api.externalImplementation.apiObjects.wrappers.DhApiConfig_v1;
import com.seibel.lod.core.enums.rendering.ERendererType;
import com.seibel.lod.core.config.Config.Client.Graphics.Quality;
import com.seibel.lod.core.config.Config.Client.Advanced.Debugging;
@@ -9,7 +10,7 @@ import com.seibel.lod.core.config.Config.Client.Advanced.Debugging;
* General graphics settings.
*
* @author James Seibel
* @version 2022-6-2
* @version 2022-6-9
*/
public class DhApiGraphicsGeneral
{
@@ -18,11 +19,11 @@ public class DhApiGraphicsGeneral
* Returns the config related to Distant Horizons render distance. <br>
* The distance is a radius in measured in chunks.
*/
public static DhApiConfig_v1<Integer> getDhChunkRenderDistanceConfig_v1()
public static IDhApiConfig_v1<Integer> getDhChunkRenderDistanceConfig_v1()
{ return new DhApiConfig_v1<>(Quality.lodChunkRenderDistance); }
/** Returns the config related to how Distant Horizons is set to render. */
public static DhApiConfig_v1<ERendererType> getRenderingTypeConfig_v1()
public static IDhApiConfig_v1<ERendererType> getRenderingTypeConfig_v1()
{ return new DhApiConfig_v1<>(Debugging.rendererType); }
}
@@ -1,5 +1,6 @@
package com.seibel.lod.core.api.external.apiObjects.objects;
package com.seibel.lod.core.api.externalImplementation.apiObjects.wrappers;
import com.seibel.lod.core.api.external.apiObjects.wrapperInterfaces.IDhApiConfig_v1;
import com.seibel.lod.core.config.types.ConfigEntry;
/**
@@ -7,9 +8,9 @@ import com.seibel.lod.core.config.types.ConfigEntry;
*
* @param <T>
* @author James Seibel
* @version 2022-6-2
* @version 2022-6-9
*/
public class DhApiConfig_v1<T>
public class DhApiConfig_v1<T> implements IDhApiConfig_v1<T>
{
private final ConfigEntry<T> configEntry;
@@ -24,31 +25,10 @@ public class DhApiConfig_v1<T>
}
/**
* Returns the active value for this config. <br>
* Returns the True value if either the config cannot be overridden by
* the API or if it hasn't been set by the API.
*/
public T getValue() { return this.configEntry.get(); }
/**
* Returns the value held by this config. <br>
* This is the value stored in the config file.
*/
public T getTrueValue() { return this.configEntry.getTrueValue(); }
/**
* Returns the value of the config if it was set by the API.
* Returns null if the config wasn't set by the API.
*/
public T getApiValue() { return this.configEntry.getApiValue(); }
/**
* Sets the config's value. <br>
* If the newValue is set to null then the config
* will revert to using the True Value.<br>
* If the config cannot be set via the API this method will return false.
*
* @return true if the value was set, false otherwise.
*/
public boolean setValue(T newValue)
{
if (this.configEntry.allowApiOverride)
@@ -62,14 +42,10 @@ public class DhApiConfig_v1<T>
}
}
/** Returns true if this config can be set via the API, false otherwise. */
public boolean getCanBeOverrodeByApi() { return this.configEntry.allowApiOverride; }
/** Returns the default value for this config. */
public T getDefaultValue() { return this.configEntry.getDefaultValue(); }
/** Returns the max value for this config, null if there is no max. */
public T getMaxValue() { return this.configEntry.getMax(); }
/** Returns the min value for this config, null if there is no min. */
public T getMinValue() { return this.configEntry.getMin(); }
}