Set up the API config

This commit is contained in:
James Seibel
2022-09-15 20:31:41 -05:00
parent 541fbbb36b
commit 690dd319cb
6 changed files with 134 additions and 47 deletions
@@ -1,49 +1,25 @@
package com.seibel.lod.api.items.interfaces.config;
import com.seibel.lod.api.items.interfaces.config.both.IDhApiWorldGenerationConfig;
import com.seibel.lod.api.items.interfaces.config.client.IDhApiBuffersConfig;
import com.seibel.lod.api.items.interfaces.config.client.IDhApiGraphicsConfig;
import com.seibel.lod.api.items.interfaces.config.client.IDhApiMultiplayerConfig;
import com.seibel.lod.api.items.interfaces.config.client.IDhApiThreadingConfig;
/**
* An interface for Distant Horizon's Config.
*
* @param <T> The internal data type of this config.
* This interfaces holds all of the config groups
* the API has access to for easy access to all config values.
*
* @author James Seibel
* @version 2022-6-13
* @version 9-15-2022
*/
public interface IDhApiConfig<T>
public interface IDhApiConfig
{
/**
* 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();
IDhApiWorldGenerationConfig getWorldGeneratorConfig();
IDhApiBuffersConfig getBufferConfig();
IDhApiGraphicsConfig getGraphicsConfig();
IDhApiMultiplayerConfig getMultiplayerConfig();
IDhApiThreadingConfig getThreadingConfig();
}
@@ -0,0 +1,51 @@
package com.seibel.lod.api.items.interfaces.config;
/**
* An interface for Distant Horizon's Config.
*
* @param <T> The data type of this config.
*
* @author James Seibel
* @version 2022-9-15
*/
public interface IDhApiConfigValue<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,6 @@
package com.seibel.lod.api.items.objects.config;
import com.seibel.lod.api.items.interfaces.config.IDhApiConfig;
import com.seibel.lod.api.items.interfaces.config.IDhApiConfigValue;
import com.seibel.lod.core.interfaces.config.IConfigEntry;
import com.seibel.lod.core.interfaces.config.IConverter;
import com.seibel.lod.core.interfaces.config.converters.DefaultConverter;
@@ -18,7 +18,7 @@ import com.seibel.lod.core.interfaces.config.converters.DefaultConverter;
* @author James Seibel
* @version 2022-6-30
*/
public class DhApiConfig<coreType, apiType> implements IDhApiConfig<apiType>
public class DhApiConfigValue<coreType, apiType> implements IDhApiConfigValue<apiType>
{
private final IConfigEntry<coreType> configEntry;
@@ -32,7 +32,7 @@ public class DhApiConfig<coreType, apiType> implements IDhApiConfig<apiType>
* Uses the default object converter, this requires coreType and apiType to be the same.
*/
@SuppressWarnings("unchecked") // DefaultConverter's cast is safe
public DhApiConfig(IConfigEntry<coreType> newConfigEntry)
public DhApiConfigValue(IConfigEntry<coreType> newConfigEntry)
{
this.configEntry = newConfigEntry;
this.configConverter = (IConverter<coreType, apiType>) new DefaultConverter<coreType>();
@@ -42,7 +42,7 @@ public class DhApiConfig<coreType, apiType> implements IDhApiConfig<apiType>
* This constructor should only be called internally. <br>
* There is no reason for API users to create this object. <br><br>
*/
public DhApiConfig(IConfigEntry<coreType> newConfigEntry, IConverter<coreType, apiType> newConverter)
public DhApiConfigValue(IConfigEntry<coreType> newConfigEntry, IConverter<coreType, apiType> newConverter)
{
this.configEntry = newConfigEntry;
this.configConverter = newConverter;
@@ -13,7 +13,7 @@ import com.seibel.lod.core.interfaces.dependencyInjection.IDhApiEventInjector;
*/
public class DhApiEventRegister
{
private static final IDhApiEventInjector EVENT_INJECTOR = ApiCoreInjectors.getInstance().eventInjector;
private static final IDhApiEventInjector EVENT_INJECTOR = ApiCoreInjectors.getInstance().events;
/**
* Registers the given event handler. <Br>
@@ -1,13 +1,34 @@
package com.seibel.lod.core;
import com.seibel.lod.api.items.interfaces.config.IDhApiConfigGroup;
import com.seibel.lod.api.items.interfaces.config.both.IDhApiWorldGenerationConfig;
import com.seibel.lod.api.items.interfaces.config.client.*;
import com.seibel.lod.core.api.external.coreImplementations.methods.config.DhApiConfig;
import com.seibel.lod.core.api.external.coreImplementations.methods.config.both.DhApiWorldGenerationConfig;
import com.seibel.lod.core.api.external.coreImplementations.methods.config.client.*;
import com.seibel.lod.core.datatype.column.ColumnRenderLoader;
import com.seibel.lod.core.datatype.full.FullDataLoader;
import com.seibel.lod.core.datatype.full.SparseDataLoader;
import com.seibel.lod.core.interfaces.dependencyInjection.ApiCoreInjectors;
import com.seibel.lod.core.interfaces.dependencyInjection.IDependencyInjector;
public class Initializer {
public static void init() {
/**
* Handles first time Core setup.
*
* @author Leetom
* @version 2022-9-15
*/
public class Initializer
{
public static void init()
{
ColumnRenderLoader unused = new ColumnRenderLoader(); // Auto register into the loader system
FullDataLoader unused2 = new FullDataLoader(); // Auto register into the loader system
SparseDataLoader unused3 = new SparseDataLoader(); // Auto register
// link Core's config to the API
ApiCoreInjectors.getInstance().configs = DhApiConfig.INSTANCE;
}
}
@@ -0,0 +1,39 @@
package com.seibel.lod.core.api.external.coreImplementations.methods.config;
import com.seibel.lod.api.items.interfaces.config.IDhApiConfig;
import com.seibel.lod.api.items.interfaces.config.both.IDhApiWorldGenerationConfig;
import com.seibel.lod.api.items.interfaces.config.client.IDhApiBuffersConfig;
import com.seibel.lod.api.items.interfaces.config.client.IDhApiGraphicsConfig;
import com.seibel.lod.api.items.interfaces.config.client.IDhApiMultiplayerConfig;
import com.seibel.lod.api.items.interfaces.config.client.IDhApiThreadingConfig;
import com.seibel.lod.core.api.external.coreImplementations.methods.config.both.DhApiWorldGenerationConfig;
import com.seibel.lod.core.api.external.coreImplementations.methods.config.client.DhApiBuffersConfig;
import com.seibel.lod.core.api.external.coreImplementations.methods.config.client.DhApiGraphicsConfig;
import com.seibel.lod.core.api.external.coreImplementations.methods.config.client.DhApiMultiplayerConfig;
import com.seibel.lod.core.api.external.coreImplementations.methods.config.client.DhApiThreadingConfig;
/**
* A singleton that holds all of the config groups for the API.
*
* @author James Seibel
* @version 9-15-2022
*/
public class DhApiConfig implements IDhApiConfig
{
public static final DhApiConfig INSTANCE = new DhApiConfig();
private DhApiConfig() { }
@Override
public IDhApiWorldGenerationConfig getWorldGeneratorConfig() { return DhApiWorldGenerationConfig.INSTANCE; }
@Override
public IDhApiBuffersConfig getBufferConfig() { return DhApiBuffersConfig.INSTANCE; }
@Override
public IDhApiGraphicsConfig getGraphicsConfig() { return DhApiGraphicsConfig.INSTANCE; }
@Override
public IDhApiMultiplayerConfig getMultiplayerConfig() { return DhApiMultiplayerConfig.INSTANCE; }
@Override
public IDhApiThreadingConfig getThreadingConfig() { return DhApiThreadingConfig.INSTANCE; }
}