diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/CharacterUtils.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/CharacterUtils.java index dc6b153ee..dc5fee8fb 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/CharacterUtils.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/CharacterUtils.java @@ -1,9 +1,9 @@ package net.modificationstation.stationapi.api.config; import com.google.common.base.CharMatcher; -import net.modificationstation.stationapi.impl.config.DrawContextAccessor; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.screen.Screen; +import net.modificationstation.stationapi.impl.config.DrawContextAccessor; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/Comment.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/Comment.java deleted file mode 100644 index 76d129a24..000000000 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/Comment.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.modificationstation.stationapi.api.config; - -import java.lang.annotation.*; - -@Retention(RetentionPolicy.RUNTIME) -public @interface Comment { - String value(); -} diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigCategory.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigCategory.java index 342c7ad78..2a00f5394 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigCategory.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigCategory.java @@ -9,6 +9,30 @@ /** * The name you want to have on the button to access your category and at the top while it's open. + * @return a string, supports colour codes. */ - String value(); + String name(); + + /** + * The description shown to users in the scroll menu. ~30 chars max is recommended. + * @return a string, supports colour codes. + */ + String description() default ""; + + /** + * The comment shown inside config files. Can be as long as you want, and supports newlines. Does NOT support colour codes. + * If blank, description is shown instead. + */ + String comment() default ""; + + /** + * Unimplemented. Will be attached to a "?" button for users to show a fullscreen and scrollable description. + */ + String longDescription() default ""; + + /** + * Syncs the config entry with the server upon join, and server config change. + * Will also be able to be edited by ops in-game at a later date. + */ + boolean multiplayerSynced() default false; } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigEntry.java new file mode 100644 index 000000000..726612ff1 --- /dev/null +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigEntry.java @@ -0,0 +1,61 @@ +package net.modificationstation.stationapi.api.config; + +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@Documented +public @interface ConfigEntry { + + /** + * This should be the visible name that you want users to see in the config GUI. + * @return a string, supports colour codes. + */ + String name(); + + /** + * The description shown to users in the scroll menu. ~30 chars max is recommended. + * @return a string, supports colour codes. + */ + String description() default ""; + + /** + * The comment shown inside config files. Can be as long as you want, and supports newlines. Does NOT support colour codes. + * If blank, description is shown instead. + */ + String comment() default ""; + + /** + * Unimplemented. Will be attached to a "?" button for users to show a fullscreen and scrollable description. + */ + String longDescription() default ""; + + /** + * Syncs the config entry with the server upon join, and server config change. + * Will also be able to be edited by ops in-game. + */ + boolean multiplayerSynced() default false; + + /** + * The maximum length of this value. + * Default 32. + * Numeric values: the actual number value. + * Strings: how many characters. + * Applies to the contents of arrays, not the arrays themselves. See max and minArrayLength. + */ + long maxLength() default 32; + + /** + * The minimum length of this value. + * Default 0. + * Numeric values: the actual number value. + * Strings: how many characters. + * Applies to the contents of arrays, not the arrays themselves. See max and minArrayLength. + */ + long minLength() default 0; + + long maxArrayLength() default Short.MAX_VALUE; + long minArrayLength() default 0; + + +} diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigFactoryProvider.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigFactoryProvider.java index cdf5de5f1..c8869ab0e 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigFactoryProvider.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigFactoryProvider.java @@ -2,7 +2,9 @@ import com.google.common.collect.ImmutableMap; import net.modificationstation.stationapi.impl.config.NonFunction; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; +import uk.co.benjiweber.expressions.function.SeptFunction; +import uk.co.benjiweber.expressions.function.SexFunction; import java.lang.reflect.*; import java.util.function.*; @@ -14,7 +16,7 @@ public interface ConfigFactoryProvider { * @param immutableBuilder Arguments for the OctFunction are: id, name, description, field, parentObject, value, multiplayerSynced, maxLength. * Should return a class returning a config entry for your custom config type. */ - void provideLoadFactories(ImmutableMap.Builder>> immutableBuilder); + void provideLoadFactories(ImmutableMap.Builder>> immutableBuilder); /** * Return custom factories for certain config class types. diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigName.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigName.java deleted file mode 100644 index c42e64c35..000000000 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigName.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.modificationstation.stationapi.api.config; - -import java.lang.annotation.*; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@Documented -public @interface ConfigName { - - /** - * This should be the visible name that you want users to see in the config GUI. - * @return a string, supports colour codes. - */ - String value(); -} diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/GConfig.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigRoot.java similarity index 69% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/GConfig.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigRoot.java index 370843ac0..82a8626b1 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/GConfig.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/ConfigRoot.java @@ -5,7 +5,7 @@ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @Documented -public @interface GConfig { +public @interface ConfigRoot { /** * The identifier of this config entrypoint. !!!MUST BE UNIQUE FROM OTHER CONFIGS IN YOUR MOD!!! @@ -18,7 +18,10 @@ String visibleName(); /** - * Make the config screen attached to the annotation the one that shows by default. + * The index this page uses. Those without a specified index will be added last. */ - boolean primary() default false; + int index() default Integer.MAX_VALUE; + + + boolean multiplayerSynced() default false; } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/FieldModifiedListener.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/FieldModifiedListener.java new file mode 100644 index 000000000..438cb507e --- /dev/null +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/FieldModifiedListener.java @@ -0,0 +1,18 @@ +package net.modificationstation.stationapi.api.config; + +import net.modificationstation.stationapi.impl.config.GlassYamlWrapper; + +import java.lang.reflect.*; + +/** + * Implement in custom types. This listener does not support java builtins because I value what little remains of my sanity. + */ +public interface FieldModifiedListener { + + /** + * @param field The field. Use the field name as the yaml key if setting values in there. + * @param glassYamlWrapper The config file at the level the field is at. + * @param eventSource {@link net.modificationstation.stationapi.impl.config.EventStorage.EventSource} + */ + void fieldModified(Field field, GlassYamlWrapper glassYamlWrapper, int eventSource); +} diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/GCAPI.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/GCAPI.java index 6f9bd39c9..172e291c6 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/GCAPI.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/GCAPI.java @@ -1,13 +1,17 @@ package net.modificationstation.stationapi.api.config; +import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; +import net.modificationstation.stationapi.api.util.Identifier; +import net.modificationstation.stationapi.impl.config.ConfigRootEntry; import net.modificationstation.stationapi.impl.config.EventStorage; import net.modificationstation.stationapi.impl.config.GCCore; -import net.modificationstation.stationapi.api.util.Identifier; import net.modificationstation.stationapi.impl.config.GlassYamlFile; -import net.modificationstation.stationapi.impl.config.object.ConfigCategory; +import net.modificationstation.stationapi.impl.config.object.ConfigCategoryHandler; import org.jetbrains.annotations.Nullable; import uk.co.benjiweber.expressions.tuple.BiTuple; +import uk.co.benjiweber.expressions.tuple.QuadTuple; +import uk.co.benjiweber.expressions.tuple.TriTuple; import java.io.*; import java.util.concurrent.atomic.*; @@ -35,15 +39,12 @@ public static void reloadConfig(Identifier configID, @Nullable String overrideCo public static void reloadConfig(Identifier configID, @Nullable GlassYamlFile overrideConfigJson) { AtomicReference mod = new AtomicReference<>(); GCCore.MOD_CONFIGS.keySet().forEach(modContainer -> { - if (modContainer.toString().equals(configID.toString())) { - mod.set(modContainer); + if (modContainer.equals(configID)) { + ConfigRootEntry category = GCCore.MOD_CONFIGS.get(mod.get()); + GCCore.loadModConfig(category.configRoot(), category.modContainer(), category.configCategoryHandler().parentField, mod.get(), overrideConfigJson); + GCCore.saveConfig(category.modContainer(), category.configCategoryHandler(), EventStorage.EventSource.MOD_SAVE); } }); - if (mod.get() != null) { - BiTuple, ConfigCategory> category = GCCore.MOD_CONFIGS.get(mod.get()); - GCCore.loadModConfig(category.one().getEntrypoint(), category.one().getProvider(), category.two().parentField, mod.get(), overrideConfigJson); - GCCore.saveConfig(category.one(), category.two(), EventStorage.EventSource.MOD_SAVE); - } } /** diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/LongDescription.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/LongDescription.java deleted file mode 100644 index 2ffe47d84..000000000 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/LongDescription.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.modificationstation.stationapi.api.config; - -import java.lang.annotation.*; - -// TODO: Actually implement -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@Documented -public @interface LongDescription { - - /** - * !!!Unimplemented!!! - * To be used in the future for a scrollable full-screen explanation of your config entry or category. - * @return TBD. - */ - String value(); -} diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/MaxLength.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/MaxLength.java deleted file mode 100644 index 1b8eb4d04..000000000 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/MaxLength.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.modificationstation.stationapi.api.config; - -import java.lang.annotation.*; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@Documented -public @interface MaxLength { - - /** - * The maximum length of the value(s) of your entry. - * Defaults to 32 if the annotation is not set. - * Numerical values ignore this. - * @return int value deciding the max character length of your value. - */ - int value(); - - /** - * The maximum array length of your entry. Ignored if entry is not an array or list. - * @return int value deciding the maximum length of your array. - */ - int arrayValue() default -1; - - /** - * If the array should be fixed size. !!DOES NOT PROTECT AGAINST DIRECT CODE CHANGES!! - * @return boolean value. - */ - boolean fixedArray() default false; -} diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/MultiplayerSynced.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/MultiplayerSynced.java deleted file mode 100644 index 93173b735..000000000 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/api/config/MultiplayerSynced.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.modificationstation.stationapi.api.config; - -import java.lang.annotation.*; - -/** - * Syncs the config entry with the server upon join, and server config change. - * Will also be able to be edited by ops in-game at a later date. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@Documented -public @interface MultiplayerSynced { -} diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/ConfigFactories.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/ConfigFactories.java index a3af2c76a..8678daaba 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/ConfigFactories.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/ConfigFactories.java @@ -1,15 +1,16 @@ package net.modificationstation.stationapi.impl.config; import com.google.common.collect.ImmutableMap; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; +import uk.co.benjiweber.expressions.function.SeptFunction; import java.lang.reflect.*; import java.util.function.*; public class ConfigFactories { - public static ImmutableMap>> loadFactories = null; + public static ImmutableMap>> loadFactories = null; public static ImmutableMap> saveFactories = null; @SuppressWarnings("rawtypes") diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/ConfigRootEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/ConfigRootEntry.java new file mode 100644 index 000000000..e8933ac70 --- /dev/null +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/ConfigRootEntry.java @@ -0,0 +1,12 @@ +package net.modificationstation.stationapi.impl.config; + +import net.fabricmc.loader.api.ModContainer; +import net.modificationstation.stationapi.api.config.ConfigRoot; +import net.modificationstation.stationapi.impl.config.object.ConfigCategoryHandler; + +public record ConfigRootEntry( + ModContainer modContainer, + ConfigRoot configRoot, + Object configObject, + ConfigCategoryHandler configCategoryHandler +) {} diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/GCCore.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/GCCore.java index 4f41a18c7..a0e909726 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/GCCore.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/GCCore.java @@ -8,30 +8,28 @@ import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; -import net.modificationstation.stationapi.api.config.Comment; +import net.minecraft.client.Minecraft; +import net.minecraft.nbt.NbtCompound; import net.modificationstation.stationapi.api.config.ConfigCategory; +import net.modificationstation.stationapi.api.config.ConfigEntry; import net.modificationstation.stationapi.api.config.ConfigFactoryProvider; -import net.modificationstation.stationapi.api.config.ConfigName; -import net.modificationstation.stationapi.api.config.GConfig; +import net.modificationstation.stationapi.api.config.ConfigRoot; import net.modificationstation.stationapi.api.config.GeneratedConfig; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.minecraft.client.Minecraft; -import net.minecraft.nbt.NbtCompound; -import net.modificationstation.stationapi.api.config.MultiplayerSynced; import net.modificationstation.stationapi.api.util.Identifier; import net.modificationstation.stationapi.api.util.ReflectionHelper; -import net.modificationstation.stationapi.impl.config.object.ConfigBase; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigHandlerBase; +import net.modificationstation.stationapi.impl.config.object.ConfigCategoryHandler; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.config.Configurator; import org.simpleyaml.configuration.file.YamlFileWrapper; -import org.simpleyaml.configuration.implementation.api.QuoteStyle; +import uk.co.benjiweber.expressions.function.SeptFunction; import uk.co.benjiweber.expressions.tuple.BiTuple; +import uk.co.benjiweber.expressions.tuple.QuadTuple; import java.io.*; -import java.lang.annotation.*; import java.lang.reflect.*; import java.util.*; import java.util.concurrent.atomic.*; @@ -45,35 +43,13 @@ @Deprecated public class GCCore implements PreLaunchEntrypoint { public static final ModContainer NAMESPACE = FabricLoader.getInstance().getModContainer("gcapi").orElseThrow(RuntimeException::new); - public static final HashMap, net.modificationstation.stationapi.impl.config.object.ConfigCategory>> MOD_CONFIGS = new HashMap<>(); + public static final HashMap MOD_CONFIGS = new HashMap<>(); public static final HashMap> DEFAULT_MOD_CONFIGS = new HashMap<>(); private static boolean loaded = false; public static boolean isMultiplayer = false; private static final Logger LOGGER = LogManager.getFormatterLogger("GCAPI"); - private static final Supplier MAX_LENGTH_SUPPLIER = () -> new MaxLength() { - @Override - public Class annotationType() { - return MaxLength.class; - } - - @Override - public int value() { - return 32; - } - - @Override - public int arrayValue() { - return -1; - } - - @Override - public boolean fixedArray() { - return false; - } - }; - static { Configurator.setLevel("GCAPI", Level.INFO); } @@ -86,10 +62,10 @@ public static void loadServerConfig(String modID, String string) { } }); if (mod.get() != null) { - BiTuple, net.modificationstation.stationapi.impl.config.object.ConfigCategory> category = MOD_CONFIGS.get(mod.get()); - saveConfig(category.one(), category.two(), EventStorage.EventSource.SERVER_JOIN | EventStorage.EventSource.MODDED_SERVER_JOIN); + ConfigRootEntry rootEntry = MOD_CONFIGS.get(mod.get()); + saveConfig(rootEntry.modContainer(), rootEntry.configCategoryHandler(), EventStorage.EventSource.SERVER_JOIN | EventStorage.EventSource.MODDED_SERVER_JOIN); try { - loadModConfig(category.one().getEntrypoint(), category.one().getProvider(), category.two().parentField, mod.get(), new GlassYamlFile(string)); + loadModConfig(rootEntry.configRoot(), rootEntry.modContainer(), rootEntry.configCategoryHandler().parentField, mod.get(), new GlassYamlFile(string)); } catch (Exception e) { e.printStackTrace(); } @@ -98,8 +74,8 @@ public static void loadServerConfig(String modID, String string) { public static void exportConfigsForServer(NbtCompound nbtCompound) { for (Identifier modContainer : MOD_CONFIGS.keySet()) { - BiTuple, net.modificationstation.stationapi.impl.config.object.ConfigCategory> entry = MOD_CONFIGS.get(modContainer); - nbtCompound.putString(modContainer.toString(), saveConfig(entry.one(), entry.two(), EventStorage.EventSource.SERVER_EXPORT)); + ConfigRootEntry entry = MOD_CONFIGS.get(modContainer); + nbtCompound.putString(modContainer.toString(), saveConfig(entry.modContainer(), entry.configCategoryHandler(), EventStorage.EventSource.SERVER_EXPORT)); } } @@ -126,7 +102,7 @@ private static void loadConfigs() { List> containers = FabricLoader.getInstance().getEntrypointContainers("gcapi:factory_provider", ConfigFactoryProvider.class); - ImmutableMap.Builder>> loadImmutableBuilder = ImmutableMap.builder(); + ImmutableMap.Builder>> loadImmutableBuilder = ImmutableMap.builder(); containers.forEach((customConfigFactoryProviderEntrypointContainer -> customConfigFactoryProviderEntrypointContainer.getEntrypoint().provideLoadFactories(loadImmutableBuilder))); ConfigFactories.loadFactories = loadImmutableBuilder.build(); log(ConfigFactories.loadFactories.size() + " config load factories loaded."); @@ -148,11 +124,11 @@ private static void loadConfigs() { FabricLoader.getInstance().getEntrypointContainers(NAMESPACE.getMetadata().getId(), Object.class).forEach((entrypointContainer -> { try { - for (Field field : ReflectionHelper.getFieldsWithAnnotation(entrypointContainer.getEntrypoint().getClass(), GConfig.class)) { - Identifier configID = Identifier.of(entrypointContainer.getProvider().getMetadata().getId() + ":" + field.getAnnotation(GConfig.class).value()); - MOD_CONFIGS.put(configID, BiTuple.of(entrypointContainer, null)); + for (Field field : ReflectionHelper.getFieldsWithAnnotation(entrypointContainer.getEntrypoint().getClass(), ConfigRoot.class)) { + Identifier configID = Identifier.of(entrypointContainer.getProvider().getMetadata().getId() + ":" + field.getAnnotation(ConfigRoot.class).value()); + MOD_CONFIGS.put(configID, new ConfigRootEntry(entrypointContainer.getProvider(), field.getAnnotation(ConfigRoot.class), entrypointContainer.getEntrypoint(), null)); loadModConfig(entrypointContainer.getEntrypoint(), entrypointContainer.getProvider(), field, configID, null); - saveConfig(entrypointContainer, MOD_CONFIGS.get(configID).two(), EventStorage.EventSource.GAME_LOAD); + saveConfig(entrypointContainer.getProvider(), MOD_CONFIGS.get(configID).configCategoryHandler(), EventStorage.EventSource.GAME_LOAD); } } catch (Exception e) { throw new RuntimeException(e); @@ -175,7 +151,7 @@ public static void loadModConfig(Object rootConfigObject, ModContainer modContai return; } } - GlassYamlFile modConfigFile = new GlassYamlFile(new File(FabricLoader.getInstance().getConfigDir().toFile(), modContainer.getMetadata().getId() + "/" + configField.getAnnotation(GConfig.class).value() + ".yml")); + GlassYamlFile modConfigFile = new GlassYamlFile(new File(FabricLoader.getInstance().getConfigDir().toFile(), modContainer.getMetadata().getId() + "/" + configField.getAnnotation(ConfigRoot.class).value() + ".yml")); if (jsonOverride == null) { modConfigFile.createOrLoad(); } @@ -201,12 +177,14 @@ public static void loadModConfig(Object rootConfigObject, ModContainer modContai else { defaultEntry = DEFAULT_MOD_CONFIGS.get(configID); } - net.modificationstation.stationapi.impl.config.object.ConfigCategory configCategory = new net.modificationstation.stationapi.impl.config.object.ConfigCategory(modContainer.getMetadata().getId(), configField.getAnnotation(GConfig.class).visibleName(), null, configField, objField, configField.isAnnotationPresent(MultiplayerSynced.class), HashMultimap.create(), true); + ConfigRoot rootConfigAnnotation = configField.getAnnotation(ConfigRoot.class); + ConfigCategoryHandler configCategory = new ConfigCategoryHandler(modContainer.getMetadata().getId(), rootConfigAnnotation.visibleName(), null, configField, objField, rootConfigAnnotation.multiplayerSynced(), HashMultimap.create(), true); readDeeper(rootConfigObject, configField, modConfigFile.path(), configCategory, totalReadFields, totalReadCategories, isMultiplayer, defaultEntry); if (!loaded) { - MOD_CONFIGS.put(configID, BiTuple.of(MOD_CONFIGS.remove(configID).one(), configCategory)); + ConfigRootEntry oldEntry = MOD_CONFIGS.remove(configID); + MOD_CONFIGS.put(configID, new ConfigRootEntry(oldEntry.modContainer(), oldEntry.configRoot(), oldEntry.configObject(), configCategory)); } else { - MOD_CONFIGS.get(configID).two().values = configCategory.values; + MOD_CONFIGS.get(configID).configCategoryHandler().values = configCategory.values; } log("Successfully read \"" + configID + "\"'s mod configs, reading " + totalReadCategories.get() + " categories, and " + totalReadFields.get() + " values."); @@ -215,7 +193,7 @@ public static void loadModConfig(Object rootConfigObject, ModContainer modContai } } - private static void readDeeper(Object rootConfigObject, Field configField, GlassYamlWrapper rootJsonObject, net.modificationstation.stationapi.impl.config.object.ConfigCategory category, AtomicInteger totalReadFields, AtomicInteger totalReadCategories, boolean isMultiplayer, HashMap defaultConfig) throws IllegalAccessException { + private static void readDeeper(Object rootConfigObject, Field configField, GlassYamlWrapper rootJsonObject, ConfigCategoryHandler category, AtomicInteger totalReadFields, AtomicInteger totalReadCategories, boolean isMultiplayer, HashMap defaultConfig) throws IllegalAccessException { totalReadCategories.getAndIncrement(); configField.setAccessible(true); Object objField = configField.get(rootConfigObject); @@ -236,14 +214,15 @@ private static void readDeeper(Object rootConfigObject, Field configField, Glass } } if (field.isAnnotationPresent(ConfigCategory.class)) { + ConfigCategory configCategoryAnnotation = field.getAnnotation(ConfigCategory.class); GlassYamlWrapper jsonCategory = rootJsonObject.path(field.getName()); - net.modificationstation.stationapi.impl.config.object.ConfigCategory childCategory = new net.modificationstation.stationapi.impl.config.object.ConfigCategory( + ConfigCategoryHandler childCategory = new ConfigCategoryHandler( field.getName(), - field.getAnnotation(ConfigCategory.class).value(), - field.isAnnotationPresent(Comment.class)? field.getAnnotation(Comment.class).value() : null, + configCategoryAnnotation.name(), + configCategoryAnnotation.description(), field, objField, - category.multiplayerSynced || field.isAnnotationPresent(MultiplayerSynced.class), + category.multiplayerSynced || configCategoryAnnotation.multiplayerSynced(), HashMultimap.create(), false ); @@ -260,13 +239,13 @@ private static void readDeeper(Object rootConfigObject, Field configField, Glass readDeeper(objField, field, jsonCategory, childCategory, totalReadFields, totalReadCategories, isMultiplayer, childDefaultConfig); } else { - if (!field.isAnnotationPresent(ConfigName.class)) { + if (!field.isAnnotationPresent(ConfigEntry.class)) { throw new RuntimeException("Config value \"" + field.getType().getName() + ";" + field.getName() + "\" has no ConfigName annotation!"); } if (field.getType() == HashMap.class) { throw new RuntimeException("Config value \"" + field.getType().getName() + ";" + field.getName() + "\" is a HashMap! Create a new HashMap subclass, as the basic type is used in GCAPI internals!"); } - NonFunction> function = ConfigFactories.loadFactories.get(field.getType()); + SeptFunction> function = ConfigFactories.loadFactories.get(field.getType()); if (function == null) { throw new RuntimeException("Config value \"" + field.getType().getName() + ";" + field.getName() + "\" has no config loader for it's type!"); } @@ -280,18 +259,17 @@ private static void readDeeper(Object rootConfigObject, Field configField, Glass if(!loaded) { defaultConfig.put(field.getName(), field.get(objField)); } + ConfigEntry configEntryAnnotation = field.getAnnotation(ConfigEntry.class); Class fieldType = ConfigFactories.loadTypeAdapterFactories.get(field.getType()); fieldType = fieldType != null ? fieldType : field.getType(); - ConfigEntry configEntry = function.apply( + ConfigEntryHandler configEntry = function.apply( field.getName(), - field.getAnnotation(ConfigName.class).value(), - field.isAnnotationPresent(Comment.class)? field.getAnnotation(Comment.class).value() : null, + configEntryAnnotation, field, objField, - category.multiplayerSynced || field.isAnnotationPresent(MultiplayerSynced.class), + category.multiplayerSynced || configEntryAnnotation.multiplayerSynced(), rootJsonObject.getChild(field.getName(), fieldType) != null? rootJsonObject.getChild(field.getName(), fieldType) : childObjField, - defaultConfig.get(field.getName()), - field.isAnnotationPresent(MaxLength.class)? field.getAnnotation(MaxLength.class) : MAX_LENGTH_SUPPLIER.get() + defaultConfig.get(field.getName()) ); configEntry.multiplayerLoaded = isMultiplayer && configEntry.multiplayerSynced; category.values.put(field.getType(), configEntry); @@ -301,21 +279,21 @@ private static void readDeeper(Object rootConfigObject, Field configField, Glass } } - public static String saveConfig(EntrypointContainer container, net.modificationstation.stationapi.impl.config.object.ConfigCategory category, int source) { + public static String saveConfig(ModContainer mod, ConfigCategoryHandler category, int source) { try { AtomicInteger readValues = new AtomicInteger(); AtomicInteger readCategories = new AtomicInteger(); - GlassYamlFile configFile = new GlassYamlFile(new File(FabricLoader.getInstance().getConfigDir().toFile(), container.getProvider().getMetadata().getId() + "/" + category.parentField.getAnnotation(GConfig.class).value() + ".yml")); + GlassYamlFile configFile = new GlassYamlFile(new File(FabricLoader.getInstance().getConfigDir().toFile(), mod.getMetadata().getId() + "/" + category.parentField.getAnnotation(ConfigRoot.class).value() + ".yml")); configFile.createNewFile(); GlassYamlFile serverExported = new GlassYamlFile(); saveDeeper(configFile.path(), serverExported.path(), category, category.parentField, readValues, readCategories); - if (EventStorage.PRE_SAVE_LISTENERS.containsKey(container.getProvider().getMetadata().getId())) { - EventStorage.PRE_SAVE_LISTENERS.get(container.getProvider().getMetadata().getId()).getEntrypoint().onPreConfigSaved(source, new GlassYamlFile(configFile.getConfigurationFile()), configFile); + if (EventStorage.PRE_SAVE_LISTENERS.containsKey(mod.getMetadata().getId())) { + EventStorage.PRE_SAVE_LISTENERS.get(mod.getMetadata().getId()).getEntrypoint().onPreConfigSaved(source, new GlassYamlFile(configFile.getConfigurationFile()), configFile); } configFile.save(); - log("Successfully saved " + readCategories + " categories, containing " + readValues.get() + " values for " + container.getProvider().getMetadata().getName() + "(" + container.getProvider().getMetadata().getId() + ")."); + log("Successfully saved " + readCategories + " categories, containing " + readValues.get() + " values for " + mod.getMetadata().getName() + "(" + mod.getMetadata().getId() + ")."); return serverExported.saveToString(); } catch (Exception e) { @@ -323,23 +301,25 @@ public static String saveConfig(EntrypointContainer container, net.modif } } - private static void saveDeeper(YamlFileWrapper newValues, YamlFileWrapper serverExported, net.modificationstation.stationapi.impl.config.object.ConfigCategory category, Field childField, AtomicInteger readValues, AtomicInteger readCategories) throws IllegalAccessException { - for (ConfigBase entry : category.values.values()) { + private static void saveDeeper(YamlFileWrapper newValues, YamlFileWrapper serverExported, ConfigCategoryHandler category, Field childField, AtomicInteger readValues, AtomicInteger readCategories) throws IllegalAccessException { + for (ConfigHandlerBase entry : category.values.values()) { childField.setAccessible(true); - if (entry instanceof net.modificationstation.stationapi.impl.config.object.ConfigCategory) { - saveDeeper(newValues.path(entry.id), serverExported.path(entry.id), (net.modificationstation.stationapi.impl.config.object.ConfigCategory) entry, entry.parentField, readValues, readCategories); + if (entry instanceof ConfigCategoryHandler) { + ConfigCategory configEntryAnnotation = entry.parentField.getAnnotation(ConfigCategory.class); + saveDeeper(newValues.path(entry.id), serverExported.path(entry.id), (ConfigCategoryHandler) entry, entry.parentField, readValues, readCategories); readCategories.getAndIncrement(); - if (entry.parentField.getAnnotation(Comment.class) != null) { - newValues.path(entry.id).comment(entry.parentField.getAnnotation(Comment.class).value()); + if (!configEntryAnnotation.comment().isEmpty()) { + newValues.path(entry.id).comment(configEntryAnnotation.comment()); } } - else if (entry instanceof ConfigEntry) { + else if (entry instanceof ConfigEntryHandler) { + ConfigEntry configCategoryAnnotation = entry.parentField.getAnnotation(ConfigEntry.class); Function configFactory = ConfigFactories.saveFactories.get(entry.parentField.getType()); if (configFactory == null) { throw new RuntimeException("Config value \"" + entry.parentObject.getClass().getName() + ";" + entry.id + "\" has no config saver for it's type!"); } - Object jsonElement = configFactory.apply(((ConfigEntry) entry).value); - if (!((ConfigEntry) entry).multiplayerLoaded) { + Object jsonElement = configFactory.apply(((ConfigEntryHandler) entry).value); + if (!((ConfigEntryHandler) entry).multiplayerLoaded) { newValues.setChild(entry.id, jsonElement); if (entry.description != null && !entry.description.isEmpty()) { newValues.path(entry.id).comment(entry.description); @@ -348,9 +328,9 @@ else if (entry instanceof ConfigEntry) { if (entry.multiplayerSynced) { serverExported.setChild(entry.id, jsonElement); } - ((ConfigEntry) entry).saveToField(); - if (entry.parentField.getAnnotation(Comment.class) != null) { - newValues.path(entry.id).comment(entry.parentField.getAnnotation(Comment.class).value()); + ((ConfigEntryHandler) entry).saveToField(); + if (!configCategoryAnnotation.comment().isEmpty()) { + newValues.path(entry.id).comment(configCategoryAnnotation.comment()); } readValues.getAndIncrement(); } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/GlassYamlWrapper.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/GlassYamlWrapper.java index 1186aa4ce..e6f3eee12 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/GlassYamlWrapper.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/GlassYamlWrapper.java @@ -2,7 +2,6 @@ import org.simpleyaml.configuration.file.YamlFile; import org.simpleyaml.configuration.file.YamlFileWrapper; -import org.simpleyaml.configuration.implementation.api.YamlImplementation; import java.util.*; diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/events/InitClientNetworking.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/event/InitClientNetworking.java similarity index 81% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/events/InitClientNetworking.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/event/InitClientNetworking.java index 07773fff6..ff33aae6b 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/events/InitClientNetworking.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/event/InitClientNetworking.java @@ -1,26 +1,24 @@ -package net.modificationstation.stationapi.impl.config.events; +package net.modificationstation.stationapi.impl.config.event; import net.fabricmc.loader.api.FabricLoader; -import net.modificationstation.stationapi.api.client.event.network.MultiplayerLogoutEvent; -import net.modificationstation.stationapi.api.client.event.network.ServerLoginSuccessEvent; -import net.modificationstation.stationapi.api.config.GConfig; -import net.modificationstation.stationapi.api.network.ModdedPacketHandler; -import net.modificationstation.stationapi.api.registry.Registry; -import net.modificationstation.stationapi.impl.config.EventStorage; -import net.modificationstation.stationapi.impl.config.GCCore; -import net.modificationstation.stationapi.impl.config.object.ConfigCategory; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; import net.mine_diver.unsafeevents.listener.EventListener; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtIo; +import net.modificationstation.stationapi.api.client.event.network.MultiplayerLogoutEvent; +import net.modificationstation.stationapi.api.client.event.network.ServerLoginSuccessEvent; +import net.modificationstation.stationapi.api.config.ConfigRoot; import net.modificationstation.stationapi.api.event.registry.MessageListenerRegistryEvent; import net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint; -import net.modificationstation.stationapi.api.network.packet.MessagePacket; -import net.modificationstation.stationapi.api.network.packet.PacketHelper; +import net.modificationstation.stationapi.api.network.ModdedPacketHandler; +import net.modificationstation.stationapi.api.registry.Registry; import net.modificationstation.stationapi.api.util.Identifier; import net.modificationstation.stationapi.api.util.Namespace; import net.modificationstation.stationapi.api.util.Null; import net.modificationstation.stationapi.api.util.ReflectionHelper; +import net.modificationstation.stationapi.impl.config.EventStorage; +import net.modificationstation.stationapi.impl.config.GCCore; +import net.modificationstation.stationapi.impl.config.object.ConfigCategoryHandler; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import java.io.*; import java.lang.reflect.*; @@ -52,8 +50,8 @@ private void onClientDisconnect(MultiplayerLogoutEvent event) { GCCore.log("Unloading server synced config!"); FabricLoader.getInstance().getEntrypointContainers(GCCore.NAMESPACE.getMetadata().getId(), Object.class).forEach((entrypointContainer -> { try { - for (Field field : ReflectionHelper.getFieldsWithAnnotation(entrypointContainer.getEntrypoint().getClass(), GConfig.class)) { - Identifier configID = Identifier.of(entrypointContainer.getProvider().getMetadata().getId() + ":" + field.getAnnotation(GConfig.class).value()); + for (Field field : ReflectionHelper.getFieldsWithAnnotation(entrypointContainer.getEntrypoint().getClass(), ConfigRoot.class)) { + Identifier configID = Identifier.of(entrypointContainer.getProvider().getMetadata().getId() + ":" + field.getAnnotation(ConfigRoot.class).value()); GCCore.loadModConfig(entrypointContainer.getEntrypoint(), entrypointContainer.getProvider(), field, configID, null); } } catch (Exception e) { @@ -66,17 +64,17 @@ private void onClientDisconnect(MultiplayerLogoutEvent event) { @EventListener private void onClientJoin(ServerLoginSuccessEvent event) { if(!((ModdedPacketHandler) event.clientNetworkHandler).isModded()) { - GCCore.MOD_CONFIGS.forEach((identifier, entrypointContainerConfigCategoryBiTuple) -> recursiveTriggerVanillaBehavior(entrypointContainerConfigCategoryBiTuple.two())); + GCCore.MOD_CONFIGS.forEach((identifier, configRootEntry) -> recursiveTriggerVanillaBehavior(configRootEntry.configCategoryHandler())); } } - private void recursiveTriggerVanillaBehavior(ConfigCategory configCategory) { + private void recursiveTriggerVanillaBehavior(ConfigCategoryHandler configCategory) { configCategory.values.forEach((aClass, configBase) -> { - if(configBase.getClass().isAssignableFrom(ConfigCategory.class)) { - recursiveTriggerVanillaBehavior((ConfigCategory) configBase); + if(configBase.getClass().isAssignableFrom(ConfigCategoryHandler.class)) { + recursiveTriggerVanillaBehavior((ConfigCategoryHandler) configBase); } else { - ((ConfigEntry) configBase).vanillaServerBehavior(); + ((ConfigEntryHandler) configBase).vanillaServerBehavior(); } }); } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/events/InitServerNetworking.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/event/InitServerNetworking.java similarity index 87% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/events/InitServerNetworking.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/event/InitServerNetworking.java index 3abedb4f6..890024c76 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/events/InitServerNetworking.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/event/InitServerNetworking.java @@ -1,21 +1,18 @@ -package net.modificationstation.stationapi.impl.config.events; +package net.modificationstation.stationapi.impl.config.event; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.modificationstation.stationapi.impl.config.GCCore; import net.mine_diver.unsafeevents.listener.EventListener; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtIo; -import net.modificationstation.stationapi.api.event.registry.MessageListenerRegistryEvent; import net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint; import net.modificationstation.stationapi.api.network.ModdedPacketHandler; import net.modificationstation.stationapi.api.network.packet.MessagePacket; import net.modificationstation.stationapi.api.network.packet.PacketHelper; -import net.modificationstation.stationapi.api.registry.Registry; import net.modificationstation.stationapi.api.server.event.network.PlayerLoginEvent; import net.modificationstation.stationapi.api.util.Identifier; import net.modificationstation.stationapi.api.util.Namespace; import net.modificationstation.stationapi.api.util.Null; +import net.modificationstation.stationapi.impl.config.GCCore; import java.io.*; import java.util.*; diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfig.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfig.java index 98c2f1870..a882c17c0 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfig.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfig.java @@ -1,18 +1,18 @@ package net.modificationstation.stationapi.impl.config.example; -import net.modificationstation.stationapi.api.config.GConfig; +import net.modificationstation.stationapi.api.config.ConfigRoot; /** * An example parent config class. You can put @GConfig configs inside classes with other non-config related functionality without issue. */ public class ExampleConfig { - @GConfig(value = "config", visibleName = "Config stuff", primary = true) + @ConfigRoot(value = "config", visibleName = "Config stuff", index = 1) public static final ExampleConfigClass exampleConfigClass = new ExampleConfigClass(); - @GConfig(value = "second", visibleName = "Second Config") + @ConfigRoot(value = "second", visibleName = "Second Config") public static final SecondConfigClass secondConfigClass = new SecondConfigClass(); - @GConfig(value = "third", visibleName = "Third Config") + @ConfigRoot(value = "third", visibleName = "Third Config") public static final ThirdConfigClass thirdConfigClass = new ThirdConfigClass(); } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigCategory.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigCategory.java index 22219ccce..8c7017de7 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigCategory.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigCategory.java @@ -1,8 +1,7 @@ package net.modificationstation.stationapi.impl.config.example; -import net.modificationstation.stationapi.api.config.Comment; import net.modificationstation.stationapi.api.config.ConfigCategory; -import net.modificationstation.stationapi.api.config.ConfigName; +import net.modificationstation.stationapi.api.config.ConfigEntry; /** * An example config category. Note the use of @ConfigCategory for defining a category. @@ -11,14 +10,13 @@ public class ExampleConfigCategory { // Same deal as before, this time it's inside a category. - @ConfigName("Oh No!") + @ConfigEntry(name = "Oh No!") public String ohNo = "reee"; // And functioning integer config! MUST be the class, not the primitive! - @ConfigName("Example Integer!") + @ConfigEntry(name = "Example Integer!") public Integer ohYes = 0; - @Comment("Fancy values ahead!") - @ConfigCategory("Fancy Config Category") + @ConfigCategory(name = "Fancy Config Category", description = "Fancy values ahead!") public ExampleConfigCategoryTwo secondCategory = new ExampleConfigCategoryTwo(); } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigCategoryTwo.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigCategoryTwo.java index a5df9fc20..9413a4dd4 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigCategoryTwo.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigCategoryTwo.java @@ -1,28 +1,24 @@ package net.modificationstation.stationapi.impl.config.example; -import net.modificationstation.stationapi.api.config.Comment; -import net.modificationstation.stationapi.api.config.ConfigName; -import net.modificationstation.stationapi.api.config.MaxLength; +import net.modificationstation.stationapi.api.config.ConfigEntry; public class ExampleConfigCategoryTwo { - @ConfigName("Floating Point Value!") - @Comment("Floats are cool.") + @ConfigEntry(name = "Floating Point Value!", description = "Floats are cool.") public Float yayFloatingPoint = 1.0f; - @ConfigName("Boolean?!") + @ConfigEntry(name = "Boolean?!") public Boolean aBoolean = false; - @ConfigName("A LIST??!!") + @ConfigEntry(name = "A LIST??!!") public String[] aList = new String[0]; - @ConfigName("AN INTEGER LIST??!!") + @ConfigEntry(name = "AN INTEGER LIST??!!") public Integer[] aIList = new Integer[0]; - @ConfigName("A FLOAT LIST??!!") + @ConfigEntry(name = "A FLOAT LIST??!!") public Float[] aFList = new Float[0]; - @ConfigName("A FIXED LIST?!") - @MaxLength(value = 10, arrayValue = 3) + @ConfigEntry(name = "A FIXED LIST?!", maxLength = 10, maxArrayLength = 3, minArrayLength = 3) public Integer[] aFIList = new Integer[0]; } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigClass.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigClass.java index 0f5ff7e66..55d5d3374 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigClass.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigClass.java @@ -1,9 +1,7 @@ package net.modificationstation.stationapi.impl.config.example; -import net.modificationstation.stationapi.api.config.Comment; import net.modificationstation.stationapi.api.config.ConfigCategory; -import net.modificationstation.stationapi.api.config.ConfigName; -import net.modificationstation.stationapi.api.config.MultiplayerSynced; +import net.modificationstation.stationapi.api.config.ConfigEntry; import net.modificationstation.stationapi.api.config.TriBoolean; import net.modificationstation.stationapi.api.config.ValueOnVanillaServer; @@ -12,34 +10,36 @@ */ public class ExampleConfigClass { - @ConfigName("Tested Config") // Shows up above the config entry in white, unless you use colour codes, then it will use those. - @Comment("Used to translate nerd") // Shows up in grey under the config entry. + @ConfigEntry( + name = "Tested Config", // Shows up above the config entry in white, unless you use colour codes, then it will use those. + description = "Used to translate nerd" // Shows up in grey under the config entry. + ) public String testedConfig = "nerd"; - @ConfigName("Tested Config 1") - @MultiplayerSynced // Marks this entry to be synced with the server on join, and when server config changes. Do not use for client-side configs, you will annoy your users. + @ConfigEntry( + name = "Tested Config 1", + multiplayerSynced = true // Marks this entry to be synced with the server on join, and when server config changes. Do not use for client-side configs, you will annoy your users. + ) public String testConfig1 = "wow"; - @ConfigName("ASD 2") + @ConfigEntry(name = "ASD 2") public String asd2 = "hmmm"; - @ConfigName("ASD 3") + @ConfigEntry(name = "ASD 3") public String asd3 = "hmmm"; - @ConfigName("MP Synced Boolean") - @MultiplayerSynced + @ConfigEntry(name = "MP Synced Boolean", multiplayerSynced = true) @ValueOnVanillaServer(booleanValue = TriBoolean.TRUE) public Boolean mpBool = false; - @ConfigName("Test Enum") + @ConfigEntry(name = "Test Enum") public ExampleConfigEnum enumTest = ExampleConfigEnum.YAY; /** * A config category, you can put other categories inside a category too. * See the ExampleConfigCategory class for more details. */ - @Comment("My config category") - @ConfigCategory("§6Oh Noes") + @ConfigCategory(name = "§6Oh Noes", description = "My config category") public ExampleConfigCategory configCategory = new ExampleConfigCategory(); } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigEnumFactories.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigEnumFactories.java index 41029ea47..aeb429fa4 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigEnumFactories.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ExampleConfigEnumFactories.java @@ -2,18 +2,20 @@ import com.google.common.collect.ImmutableMap; import net.modificationstation.stationapi.api.config.ConfigFactoryProvider; -import net.modificationstation.stationapi.api.config.MaxLength; +import net.modificationstation.stationapi.api.config.ConfigEntry; import net.modificationstation.stationapi.impl.config.NonFunction; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; -import net.modificationstation.stationapi.impl.config.object.entry.EnumConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; +import net.modificationstation.stationapi.impl.config.object.entry.EnumConfigEntryHandler; +import uk.co.benjiweber.expressions.function.SeptFunction; +import uk.co.benjiweber.expressions.function.SexFunction; import java.lang.reflect.*; import java.util.function.*; public class ExampleConfigEnumFactories implements ConfigFactoryProvider { @Override - public void provideLoadFactories(ImmutableMap.Builder>> immutableBuilder) { - immutableBuilder.put(ExampleConfigEnum.class, ((id, name, description, parentField, parentObject, isMultiplayerSynced, enumOrOrdinal, defaultEnum, maxLength) -> + public void provideLoadFactories(ImmutableMap.Builder>> immutableBuilder) { + immutableBuilder.put(ExampleConfigEnum.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, enumOrOrdinal, defaultEnum) -> { int enumOrdinal; if(enumOrOrdinal instanceof Integer ordinal) { @@ -22,7 +24,7 @@ public void provideLoadFactories(ImmutableMap.Builder(id, name, description, parentField, parentObject, isMultiplayerSynced, enumOrdinal, ((ExampleConfigEnum) defaultEnum).ordinal(), ExampleConfigEnum.class); + return new EnumConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, enumOrdinal, ((ExampleConfigEnum) defaultEnum).ordinal(), ExampleConfigEnum.class); })); } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/SecondConfigClass.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/SecondConfigClass.java index 988b2a27e..5a298a20f 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/SecondConfigClass.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/SecondConfigClass.java @@ -1,12 +1,12 @@ package net.modificationstation.stationapi.impl.config.example; -import net.modificationstation.stationapi.api.config.ConfigName; +import net.modificationstation.stationapi.api.config.ConfigEntry; public class SecondConfigClass { - @ConfigName("Test Boolean") + @ConfigEntry(name = "Test Boolean") public Boolean test1 = false; - @ConfigName("Test String") + @ConfigEntry(name = "Test String") public String test2 = "Hmmmm"; } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ThirdConfigClass.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ThirdConfigClass.java index baf135396..e85e7f4d5 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ThirdConfigClass.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/example/ThirdConfigClass.java @@ -1,11 +1,9 @@ package net.modificationstation.stationapi.impl.config.example; -import net.modificationstation.stationapi.api.config.ConfigName; -import net.modificationstation.stationapi.api.config.MultiplayerSynced; +import net.modificationstation.stationapi.api.config.ConfigEntry; public class ThirdConfigClass { - @MultiplayerSynced - @ConfigName("Reeee") + @ConfigEntry(name = "Reeee", multiplayerSynced = true) public String ohdeargod = ""; } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/factory/DefaultFactoryProvider.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/factory/DefaultFactoryProvider.java index abadf71da..e546fd994 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/factory/DefaultFactoryProvider.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/factory/DefaultFactoryProvider.java @@ -2,16 +2,18 @@ import com.google.common.collect.ImmutableMap; import net.modificationstation.stationapi.api.config.ConfigFactoryProvider; -import net.modificationstation.stationapi.api.config.MaxLength; +import net.modificationstation.stationapi.api.config.ConfigEntry; import net.modificationstation.stationapi.impl.config.NonFunction; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; -import net.modificationstation.stationapi.impl.config.object.entry.BooleanConfigEntry; -import net.modificationstation.stationapi.impl.config.object.entry.FloatConfigEntry; -import net.modificationstation.stationapi.impl.config.object.entry.FloatListConfigEntry; -import net.modificationstation.stationapi.impl.config.object.entry.IntegerConfigEntry; -import net.modificationstation.stationapi.impl.config.object.entry.IntegerListConfigEntry; -import net.modificationstation.stationapi.impl.config.object.entry.StringConfigEntry; -import net.modificationstation.stationapi.impl.config.object.entry.StringListConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; +import net.modificationstation.stationapi.impl.config.object.entry.BooleanConfigEntryHandler; +import net.modificationstation.stationapi.impl.config.object.entry.FloatConfigEntryHandler; +import net.modificationstation.stationapi.impl.config.object.entry.FloatListConfigEntryHandler; +import net.modificationstation.stationapi.impl.config.object.entry.IntegerConfigEntryHandler; +import net.modificationstation.stationapi.impl.config.object.entry.IntegerListConfigEntryHandler; +import net.modificationstation.stationapi.impl.config.object.entry.StringConfigEntryHandler; +import net.modificationstation.stationapi.impl.config.object.entry.StringListConfigEntryHandler; +import uk.co.benjiweber.expressions.function.OctFunction; +import uk.co.benjiweber.expressions.function.SeptFunction; import java.lang.reflect.*; import java.util.*; @@ -21,14 +23,14 @@ public class DefaultFactoryProvider implements ConfigFactoryProvider { @SuppressWarnings("unchecked") @Override - public void provideLoadFactories(ImmutableMap.Builder>> immutableBuilder) { - immutableBuilder.put(String.class, ((id, name, description, parentField, parentObject, isMultiplayerSynced, value, defaultValue, maxLength) -> new StringConfigEntry(id, name, description, parentField, parentObject, isMultiplayerSynced, String.valueOf(value), String.valueOf(defaultValue), maxLength))); - immutableBuilder.put(Integer.class, ((id, name, description, parentField, parentObject, isMultiplayerSynced, value, defaultValue, maxLength) -> new IntegerConfigEntry(id, name, description, parentField, parentObject, isMultiplayerSynced, Integer.valueOf(String.valueOf(value)), Integer.valueOf(String.valueOf(defaultValue)), maxLength))); - immutableBuilder.put(Float.class, ((id, name, description, parentField, parentObject, isMultiplayerSynced, value, defaultValue, maxLength) -> new FloatConfigEntry(id, name, description, parentField, parentObject, isMultiplayerSynced, Float.valueOf(String.valueOf(value)), Float.valueOf(String.valueOf(defaultValue)), maxLength))); - immutableBuilder.put(Boolean.class, ((id, name, description, parentField, parentObject, isMultiplayerSynced, value, defaultValue, maxLength) -> new BooleanConfigEntry(id, name, description, parentField, parentObject, isMultiplayerSynced, (boolean) value, (boolean) defaultValue))); - immutableBuilder.put(String[].class, ((id, name, description, parentField, parentObject, isMultiplayerSynced, value, defaultValue, maxLength) -> new StringListConfigEntry(id, name, description, parentField, parentObject, isMultiplayerSynced, ((ArrayList) value).toArray(new String[0]), (String[]) defaultValue, maxLength))); // the new ArrayList is required or it returns java.util.Arrays.ArrayList, which is fucking dumb. - immutableBuilder.put(Integer[].class, ((id, name, description, parentField, parentObject, isMultiplayerSynced, value, defaultValue, maxLength) -> new IntegerListConfigEntry(id, name, description, parentField, parentObject, isMultiplayerSynced, ((ArrayList) value).toArray(new Integer[0]), (Integer[]) defaultValue, maxLength))); - immutableBuilder.put(Float[].class, ((id, name, description, parentField, parentObject, isMultiplayerSynced, value, defaultValue, maxLength) -> new FloatListConfigEntry(id, name, description, parentField, parentObject, isMultiplayerSynced, ((ArrayList) value).toArray(new Float[0]), (Float[]) defaultValue, maxLength))); + public void provideLoadFactories(ImmutableMap.Builder>> immutableBuilder) { + immutableBuilder.put(String.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new StringConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, String.valueOf(value), String.valueOf(defaultValue)))); + immutableBuilder.put(Integer.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new IntegerConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, Integer.valueOf(String.valueOf(value)), Integer.valueOf(String.valueOf(defaultValue))))); + immutableBuilder.put(Float.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new FloatConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, Float.valueOf(String.valueOf(value)), Float.valueOf(String.valueOf(defaultValue))))); + immutableBuilder.put(Boolean.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new BooleanConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, (boolean) value, (boolean) defaultValue))); + immutableBuilder.put(String[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new StringListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList) value).toArray(new String[0]), (String[]) defaultValue))); // the new ArrayList is required or it returns java.util.Arrays.ArrayList, which is fucking dumb. + immutableBuilder.put(Integer[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new IntegerListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList) value).toArray(new Integer[0]), (Integer[]) defaultValue))); + immutableBuilder.put(Float[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new FloatListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList) value).toArray(new Float[0]), (Float[]) defaultValue))); } @Override diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigCategory.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigCategoryHandler.java similarity index 78% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigCategory.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigCategoryHandler.java index 9de5d77e1..b87a98d8f 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigCategory.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigCategoryHandler.java @@ -3,9 +3,10 @@ import com.google.common.collect.Multimap; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; -import net.modificationstation.stationapi.api.config.HasDrawable; import net.minecraft.client.gui.screen.Screen; +import net.modificationstation.stationapi.api.config.HasDrawable; import net.modificationstation.stationapi.impl.config.screen.RootScreenBuilder; import net.modificationstation.stationapi.impl.config.screen.ScreenBuilder; import net.modificationstation.stationapi.impl.config.screen.widget.FancyButtonWidget; @@ -14,14 +15,14 @@ import java.lang.reflect.*; import java.util.*; -public class ConfigCategory extends ConfigBase { +public class ConfigCategoryHandler extends ConfigHandlerBase { public final boolean isRoot; - public Multimap, ConfigBase> values; + public Multimap, ConfigHandlerBase> values; private List button; - public ConfigCategory(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, Multimap, ConfigBase> values, boolean isRoot) { + public ConfigCategoryHandler(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, Multimap, ConfigHandlerBase> values, boolean isRoot) { super(id, name, description, parentField, parentObject, multiplayerSynced); this.values = values; this.isRoot = isRoot; @@ -32,7 +33,7 @@ public ConfigCategory(String id, String name, String description, Field parentFi * @return ScreenBuilder */ @Environment(EnvType.CLIENT) - public @NotNull ScreenBuilder getConfigScreen(Screen parent, EntrypointContainer mod) { + public @NotNull ScreenBuilder getConfigScreen(Screen parent, ModContainer mod) { return isRoot ? new RootScreenBuilder(parent, mod, this) : new ScreenBuilder(parent, mod, this); } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigEntryHandler.java similarity index 86% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigEntry.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigEntryHandler.java index cd74ebd7e..011164e55 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigEntry.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigEntryHandler.java @@ -2,31 +2,31 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.screen.Screen; import net.modificationstation.stationapi.api.config.DefaultOnVanillaServer; import net.modificationstation.stationapi.api.config.HasDrawable; -import net.modificationstation.stationapi.api.config.MaxLength; +import net.modificationstation.stationapi.api.config.ConfigEntry; import net.modificationstation.stationapi.api.config.TriBoolean; import net.modificationstation.stationapi.api.config.ValueOnVanillaServer; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.screen.Screen; import net.modificationstation.stationapi.impl.config.screen.widget.IconWidget; import net.modificationstation.stationapi.impl.config.screen.widget.ResetConfigWidget; import java.lang.reflect.*; import java.util.*; -public abstract class ConfigEntry extends ConfigBase { +public abstract class ConfigEntryHandler extends ConfigHandlerBase { public T value; public final T defaultValue; @Environment(EnvType.CLIENT) protected Screen parent; public boolean multiplayerLoaded = false; - protected MaxLength maxLength; + protected ConfigEntry configEntry; protected List drawableList = new ArrayList<>(){};; - public ConfigEntry(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, T value, T defaultValue, MaxLength maxLength) { - super(id, name, description, parentField, parentObject, multiplayerSynced); - this.maxLength = maxLength; + public ConfigEntryHandler(String id, ConfigEntry configEntry, Field parentField, Object parentObject, boolean multiplayerSynced, T value, T defaultValue) { + super(id, configEntry.name(), configEntry.description(), parentField, parentObject, multiplayerSynced); + this.configEntry = configEntry; this.value = value; this.defaultValue = defaultValue; } @@ -49,8 +49,8 @@ public void saveToField() throws IllegalAccessException { parentField.set(parentObject, value); } - public MaxLength getMaxLength() { - return maxLength; + public ConfigEntry getMaxLength() { + return configEntry; } /** diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigBase.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigHandlerBase.java similarity index 84% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigBase.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigHandlerBase.java index 7c5daf310..35d60f1f4 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigBase.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/ConfigHandlerBase.java @@ -7,7 +7,7 @@ import java.lang.reflect.*; import java.util.*; -public abstract class ConfigBase { +public abstract class ConfigHandlerBase { public final String id; @@ -29,7 +29,7 @@ public abstract class ConfigBase { public final boolean multiplayerSynced; - public ConfigBase(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced) { + public ConfigHandlerBase(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced) { this.id = id; this.name = name; this.description = description; diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BaseListConfigEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BaseListConfigEntryHandler.java similarity index 80% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BaseListConfigEntry.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BaseListConfigEntryHandler.java index aaa6fbbca..a70a9dad6 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BaseListConfigEntry.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BaseListConfigEntryHandler.java @@ -3,12 +3,12 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.loader.api.FabricLoader; -import net.modificationstation.stationapi.api.config.ConfigEntryWithButton; -import net.modificationstation.stationapi.api.config.HasDrawable; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.screen.Screen; +import net.modificationstation.stationapi.api.config.ConfigEntryWithButton; +import net.modificationstation.stationapi.api.config.HasDrawable; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import net.modificationstation.stationapi.impl.config.screen.BaseListScreenBuilder; import net.modificationstation.stationapi.impl.config.screen.widget.FancyButtonWidget; import org.jetbrains.annotations.NotNull; @@ -16,14 +16,14 @@ import java.lang.reflect.*; import java.util.*; -public abstract class BaseListConfigEntry extends ConfigEntry implements ConfigEntryWithButton { +public abstract class BaseListConfigEntryHandler extends ConfigEntryHandler implements ConfigEntryWithButton { @Environment(EnvType.CLIENT) private BaseListScreenBuilder listScreen; @Environment(EnvType.CLIENT) private FancyButtonWidget button; - public BaseListConfigEntry(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, T[] value, T[] defaultValue, MaxLength maxLength) { - super(id, name, description, parentField, parentObject, multiplayerSynced, value, defaultValue, maxLength); + public BaseListConfigEntryHandler(String id, ConfigEntry configEntry, Field parentField, Object parentObject, boolean multiplayerSynced, T[] value, T[] defaultValue) { + super(id, configEntry, parentField, parentObject, multiplayerSynced, value, defaultValue); } @Override @@ -55,6 +55,11 @@ public T[] getDrawableValue() { return (T[]) list.toArray(new Object[0]); } + @Override + public boolean isValueValid() { + return value.length < configEntry.maxArrayLength() && value.length > configEntry.minArrayLength(); + } + @Override public void setDrawableValue(T[] value) { listScreen.setValues(value); diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BooleanConfigEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BooleanConfigEntryHandler.java similarity index 80% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BooleanConfigEntry.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BooleanConfigEntryHandler.java index 92ffbc257..7a459d545 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BooleanConfigEntry.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/BooleanConfigEntryHandler.java @@ -2,12 +2,13 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.screen.Screen; import net.modificationstation.stationapi.api.config.CharacterUtils; +import net.modificationstation.stationapi.api.config.ConfigEntry; import net.modificationstation.stationapi.api.config.ConfigEntryWithButton; import net.modificationstation.stationapi.api.config.HasDrawable; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.screen.Screen; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import net.modificationstation.stationapi.impl.config.screen.widget.FancyButtonWidget; import org.jetbrains.annotations.NotNull; @@ -15,11 +16,11 @@ import java.lang.reflect.*; import java.util.List; -public class BooleanConfigEntry extends ConfigEntry implements ConfigEntryWithButton { +public class BooleanConfigEntryHandler extends ConfigEntryHandler implements ConfigEntryWithButton { private FancyButtonWidget button; - public BooleanConfigEntry(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, Boolean value, Boolean defaultValue) { - super(id, name, description, parentField, parentObject, multiplayerSynced, value, defaultValue, null); + public BooleanConfigEntryHandler(String id, ConfigEntry configEntry, Field parentField, Object parentObject, boolean multiplayerSynced, Boolean value, Boolean defaultValue) { + super(id, configEntry, parentField, parentObject, multiplayerSynced, value, defaultValue); } @Override diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/EnumConfigEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/EnumConfigEntryHandler.java similarity index 83% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/EnumConfigEntry.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/EnumConfigEntryHandler.java index 50929822d..68f774067 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/EnumConfigEntry.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/EnumConfigEntryHandler.java @@ -3,12 +3,13 @@ import com.google.common.collect.Iterables; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.screen.Screen; import net.modificationstation.stationapi.api.config.CharacterUtils; +import net.modificationstation.stationapi.api.config.ConfigEntry; import net.modificationstation.stationapi.api.config.ConfigEntryWithButton; import net.modificationstation.stationapi.api.config.HasDrawable; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.screen.Screen; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import net.modificationstation.stationapi.impl.config.screen.widget.FancyButtonWidget; import org.jetbrains.annotations.NotNull; @@ -21,12 +22,12 @@ * This class is a bit of a crapshoot cause java's generic type handling is pitifully bad. * @param The enum you want to use. Must have toString implemented. Also must be passed into the constructor. */ -public class EnumConfigEntry> extends ConfigEntry implements ConfigEntryWithButton { +public class EnumConfigEntryHandler> extends ConfigEntryHandler implements ConfigEntryWithButton { private FancyButtonWidget button; public final Enum[] parentEnumArray; - public EnumConfigEntry(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, Integer value, Integer defaultValue, @SuppressWarnings("rawtypes") Class parentEnum) { - super(id, name, description, parentField, parentObject, multiplayerSynced, value, defaultValue, null); + public EnumConfigEntryHandler(String id, ConfigEntry configEntry, Field parentField, Object parentObject, boolean multiplayerSynced, Integer value, Integer defaultValue, @SuppressWarnings("rawtypes") Class parentEnum) { + super(id, configEntry, parentField, parentObject, multiplayerSynced, value, defaultValue); //noinspection unchecked Fuck off parentEnumArray = (Enum[]) Iterables.toArray(EnumSet.allOf(parentEnum), parentEnum); } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatConfigEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatConfigEntryHandler.java similarity index 57% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatConfigEntry.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatConfigEntryHandler.java index 76d54f964..47e10922e 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatConfigEntry.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatConfigEntryHandler.java @@ -1,31 +1,30 @@ package net.modificationstation.stationapi.impl.config.object.entry; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.screen.Screen; import net.modificationstation.stationapi.api.config.CharacterUtils; import net.modificationstation.stationapi.api.config.HasDrawable; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import net.modificationstation.stationapi.impl.config.screen.widget.ExtensibleTextFieldWidget; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.screen.Screen; import org.jetbrains.annotations.NotNull; import uk.co.benjiweber.expressions.tuple.BiTuple; import java.lang.reflect.*; import java.util.*; -public class FloatConfigEntry extends ConfigEntry { +public class FloatConfigEntryHandler extends ConfigEntryHandler { private ExtensibleTextFieldWidget textbox; - public FloatConfigEntry(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, Float value, Float defaultValue, MaxLength maxLength) { - super(id, name, description, parentField, parentObject, multiplayerSynced, value, defaultValue, maxLength); + public FloatConfigEntryHandler(String id, ConfigEntry configEntry, Field parentField, Object parentObject, boolean multiplayerSynced, Float value, Float defaultValue) { + super(id, configEntry, parentField, parentObject, multiplayerSynced, value, defaultValue); } @Override public void init(Screen parent, TextRenderer textRenderer) { super.init(parent, textRenderer); textbox = new ExtensibleTextFieldWidget(textRenderer); - textbox.setValidator(str -> BiTuple.of(CharacterUtils.isFloat(str) && Float.parseFloat(str) <= maxLength.value(), multiplayerLoaded? Collections.singletonList("Server synced, you cannot change this value") : CharacterUtils.isFloat(str)? Float.parseFloat(str) > maxLength.value()? Collections.singletonList("Value is too high") : null : Collections.singletonList("Value is not a decimal number"))); - textbox.setMaxLength(maxLength.value()); + textbox.setValidator(str -> floatValidator(configEntry, multiplayerLoaded, str)); textbox.setText(value.toString()); textbox.setEnabled(!multiplayerLoaded); drawableList.add(textbox); @@ -57,4 +56,20 @@ public void reset(Object defaultValue) throws IllegalAccessException { setDrawableValue((Float) defaultValue); saveToField(); } + + public static List floatValidator(ConfigEntry configEntry, boolean multiplayerLoaded, String str) { + if (multiplayerLoaded) { + return Collections.singletonList("Server synced, you cannot change this value"); + } + if (!CharacterUtils.isInteger(str)) { + return Collections.singletonList("Value is not a floating point number"); + } + if (Integer.parseInt(str) > configEntry.maxLength()) { + return Collections.singletonList("Value is too high"); + } + if (Integer.parseInt(str) < configEntry.minLength()) { + return Collections.singletonList("Value is too low"); + } + return null; + } } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatListConfigEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatListConfigEntry.java deleted file mode 100644 index fecacc246..000000000 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatListConfigEntry.java +++ /dev/null @@ -1,37 +0,0 @@ -package net.modificationstation.stationapi.impl.config.object.entry; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.modificationstation.stationapi.api.config.CharacterUtils; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.modificationstation.stationapi.impl.config.screen.BaseListScreenBuilder; -import net.modificationstation.stationapi.impl.config.screen.FloatListScreenBuilder; -import uk.co.benjiweber.expressions.tuple.BiTuple; - -import java.lang.reflect.*; -import java.util.*; - -public class FloatListConfigEntry extends BaseListConfigEntry { - public FloatListConfigEntry(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, Float[] value, Float[] defaultValue, MaxLength maxLength) { - super(id, name, description, parentField, parentObject, multiplayerSynced, value, defaultValue, maxLength); - } - - @Override - public boolean isValueValid() { - return false; - } - - @Override - @Environment(EnvType.CLIENT) - public BaseListScreenBuilder createListScreen() { - BaseListScreenBuilder listScreen = new FloatListScreenBuilder(parent, maxLength, this, str -> BiTuple.of(CharacterUtils.isFloat(str) && Float.parseFloat(str) <= maxLength.value(), multiplayerLoaded? Collections.singletonList("Server synced, you cannot change this value") : CharacterUtils.isFloat(str)? Float.parseFloat(str) > maxLength.value()? Collections.singletonList("Value is too high") : null : Collections.singletonList("Value is not a decimal number"))); - listScreen.setValues(value); - return listScreen; - } - - @Override - public Float strToVal(String str) { - return Float.parseFloat(str); - } -} - diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatListConfigEntryHandler.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatListConfigEntryHandler.java new file mode 100644 index 000000000..63d522213 --- /dev/null +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/FloatListConfigEntryHandler.java @@ -0,0 +1,39 @@ +package net.modificationstation.stationapi.impl.config.object.entry; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.modificationstation.stationapi.api.config.CharacterUtils; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.screen.BaseListScreenBuilder; +import net.modificationstation.stationapi.impl.config.screen.FloatListScreenBuilder; +import net.modificationstation.stationapi.impl.config.screen.IntegerListScreenBuilder; +import uk.co.benjiweber.expressions.tuple.BiTuple; + +import java.lang.reflect.*; +import java.util.*; + +public class FloatListConfigEntryHandler extends BaseListConfigEntryHandler { + + public FloatListConfigEntryHandler(String id, ConfigEntry configEntry, Field parentField, Object parentObject, boolean multiplayerSynced, Float[] value, Float[] defaultValue) { + super(id, configEntry, parentField, parentObject, multiplayerSynced, value, defaultValue); + } + + @Override + @Environment(EnvType.CLIENT) + public BaseListScreenBuilder createListScreen() { + BaseListScreenBuilder listScreen = new FloatListScreenBuilder(parent, + configEntry, + this, + str -> FloatConfigEntryHandler.floatValidator(configEntry, multiplayerLoaded, str) + ); + + listScreen.setValues(value); + return listScreen; + } + + @Override + public Float strToVal(String str) { + return Float.parseFloat(str); + } +} + diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerConfigEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerConfigEntryHandler.java similarity index 55% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerConfigEntry.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerConfigEntryHandler.java index 9c1c62169..016501c82 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerConfigEntry.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerConfigEntryHandler.java @@ -1,31 +1,31 @@ package net.modificationstation.stationapi.impl.config.object.entry; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.screen.Screen; import net.modificationstation.stationapi.api.config.CharacterUtils; import net.modificationstation.stationapi.api.config.HasDrawable; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import net.modificationstation.stationapi.impl.config.screen.widget.ExtensibleTextFieldWidget; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.screen.Screen; import org.jetbrains.annotations.NotNull; import uk.co.benjiweber.expressions.tuple.BiTuple; import java.lang.reflect.*; import java.util.*; -public class IntegerConfigEntry extends ConfigEntry { +public class IntegerConfigEntryHandler extends ConfigEntryHandler { private ExtensibleTextFieldWidget textbox; - public IntegerConfigEntry(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, Integer value, Integer defaultValue, MaxLength maxLength) { - super(id, name, description, parentField, parentObject, multiplayerSynced, value, defaultValue, maxLength); + public IntegerConfigEntryHandler(String id, ConfigEntry configEntry, Field parentField, Object parentObject, boolean multiplayerSynced, Integer value, Integer defaultValue) { + super(id, configEntry, parentField, parentObject, multiplayerSynced, value, defaultValue); } @Override public void init(Screen parent, TextRenderer textRenderer) { super.init(parent, textRenderer); textbox = new ExtensibleTextFieldWidget(textRenderer); - textbox.setValidator(str -> BiTuple.of(CharacterUtils.isInteger(str) && Integer.parseInt(str) <= maxLength.value(), multiplayerLoaded? Collections.singletonList("Server synced, you cannot change this value") : CharacterUtils.isFloat(str)? Float.parseFloat(str) > maxLength.value()? Collections.singletonList("Value is too high") : null : Collections.singletonList("Value is not a whole number"))); - textbox.setMaxLength(maxLength.value()); + textbox.setValidator((str) -> integerValidator(configEntry, multiplayerLoaded, str)); + textbox.setMaxLength(Math.toIntExact(configEntry.maxLength())); textbox.setText(value.toString()); textbox.setEnabled(!multiplayerLoaded); drawableList.add(textbox); @@ -57,4 +57,20 @@ public void reset(Object defaultValue) throws IllegalAccessException { setDrawableValue((Integer) defaultValue); saveToField(); } + + public static List integerValidator(ConfigEntry configEntry, boolean multiplayerLoaded, String str) { + if (multiplayerLoaded) { + return Collections.singletonList("Server synced, you cannot change this value"); + } + if (!CharacterUtils.isInteger(str)) { + return Collections.singletonList("Value is not a whole number"); + } + if (Integer.parseInt(str) > configEntry.maxLength()) { + return Collections.singletonList("Value is too high"); + } + if (Integer.parseInt(str) < configEntry.minLength()) { + return Collections.singletonList("Value is too low"); + } + return null; + } } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerListConfigEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerListConfigEntry.java deleted file mode 100644 index 2c73a5c4c..000000000 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerListConfigEntry.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.modificationstation.stationapi.impl.config.object.entry; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.modificationstation.stationapi.api.config.CharacterUtils; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.modificationstation.stationapi.impl.config.screen.BaseListScreenBuilder; -import net.modificationstation.stationapi.impl.config.screen.IntegerListScreenBuilder; -import uk.co.benjiweber.expressions.tuple.BiTuple; - -import java.lang.reflect.*; -import java.util.*; - -public class IntegerListConfigEntry extends BaseListConfigEntry { - public IntegerListConfigEntry(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, Integer[] value, Integer[] defaultValue, MaxLength maxLength) { - super(id, name, description, parentField, parentObject, multiplayerSynced, value, defaultValue, maxLength); - } - - @Override - public boolean isValueValid() { - return false; - } - - @Override - @Environment(EnvType.CLIENT) - public BaseListScreenBuilder createListScreen() { - BaseListScreenBuilder listScreen = new IntegerListScreenBuilder(parent, maxLength, this, str -> BiTuple.of(CharacterUtils.isInteger(str) && Integer.parseInt(str) <= maxLength.value(), multiplayerLoaded? Collections.singletonList("Server synced, you cannot change this value") : CharacterUtils.isFloat(str)? Float.parseFloat(str) > maxLength.value()? Collections.singletonList("Value is too high") : null : Collections.singletonList("Value is not a whole number"))); - listScreen.setValues(value); - return listScreen; - } - - @Override - public Integer strToVal(String str) { - return Integer.parseInt(str); - } -} diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerListConfigEntryHandler.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerListConfigEntryHandler.java new file mode 100644 index 000000000..7b5e98a9b --- /dev/null +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/IntegerListConfigEntryHandler.java @@ -0,0 +1,36 @@ +package net.modificationstation.stationapi.impl.config.object.entry; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.modificationstation.stationapi.api.config.CharacterUtils; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.screen.BaseListScreenBuilder; +import net.modificationstation.stationapi.impl.config.screen.IntegerListScreenBuilder; +import uk.co.benjiweber.expressions.tuple.BiTuple; + +import java.lang.reflect.*; +import java.util.*; + +public class IntegerListConfigEntryHandler extends BaseListConfigEntryHandler { + + public IntegerListConfigEntryHandler(String id, ConfigEntry configEntry, Field parentField, Object parentObject, boolean multiplayerSynced, Integer[] value, Integer[] defaultValue) { + super(id, configEntry, parentField, parentObject, multiplayerSynced, value, defaultValue); + } + + @Override + @Environment(EnvType.CLIENT) + public BaseListScreenBuilder createListScreen() { + BaseListScreenBuilder listScreen = new IntegerListScreenBuilder(parent, + configEntry, + this, + str -> IntegerConfigEntryHandler.integerValidator(configEntry, multiplayerLoaded, str) + ); + listScreen.setValues(value); + return listScreen; + } + + @Override + public Integer strToVal(String str) { + return Integer.parseInt(str); + } +} diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringConfigEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringConfigEntryHandler.java similarity index 73% rename from glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringConfigEntry.java rename to glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringConfigEntryHandler.java index 505827e9f..4658b02e0 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringConfigEntry.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringConfigEntryHandler.java @@ -1,29 +1,28 @@ package net.modificationstation.stationapi.impl.config.object.entry; -import net.modificationstation.stationapi.api.config.HasDrawable; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.screen.Screen; +import net.modificationstation.stationapi.api.config.HasDrawable; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import net.modificationstation.stationapi.impl.config.screen.widget.ExtensibleTextFieldWidget; import org.jetbrains.annotations.NotNull; import java.lang.reflect.*; import java.util.*; -public class StringConfigEntry extends ConfigEntry { +public class StringConfigEntryHandler extends ConfigEntryHandler { private ExtensibleTextFieldWidget textbox; - public StringConfigEntry(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, String value, String defaultValue, MaxLength maxLength) { - super(id, name, description, parentField, parentObject, multiplayerSynced, value, defaultValue, maxLength); - this.maxLength = maxLength; + public StringConfigEntryHandler(String id, ConfigEntry configEntry, Field parentField, Object parentObject, boolean multiplayerSynced, String value, String defaultValue) { + super(id, configEntry, parentField, parentObject, multiplayerSynced, value, defaultValue); } @Override public void init(Screen parent, TextRenderer textRenderer) { super.init(parent, textRenderer); textbox = new ExtensibleTextFieldWidget(textRenderer); - textbox.setMaxLength(maxLength.value()); + textbox.setMaxLength(Math.toIntExact(configEntry.maxLength())); textbox.setText(value); textbox.setEnabled(!multiplayerLoaded); drawableList.add(textbox); diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringListConfigEntry.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringListConfigEntry.java deleted file mode 100644 index 86694b159..000000000 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringListConfigEntry.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.modificationstation.stationapi.impl.config.object.entry; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.modificationstation.stationapi.impl.config.screen.BaseListScreenBuilder; -import net.modificationstation.stationapi.impl.config.screen.StringListScreenBuilder; -import uk.co.benjiweber.expressions.tuple.BiTuple; - -import java.lang.reflect.*; - -public class StringListConfigEntry extends BaseListConfigEntry { - public StringListConfigEntry(String id, String name, String description, Field parentField, Object parentObject, boolean multiplayerSynced, String[] value, String[] defaultValue, MaxLength maxLength) { - super(id, name, description, parentField, parentObject, multiplayerSynced, value, defaultValue, maxLength); - } - - @Override - public boolean isValueValid() { - return value.length < maxLength.arrayValue(); - } - - @Override - @Environment(EnvType.CLIENT) - public BaseListScreenBuilder createListScreen() { - BaseListScreenBuilder listScreen = new StringListScreenBuilder(parent, maxLength, this, str -> BiTuple.of(true, null)); - listScreen.setValues(value); - return listScreen; - } - - @Override - public String strToVal(String str) { - return null; - } -} - diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringListConfigEntryHandler.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringListConfigEntryHandler.java new file mode 100644 index 000000000..56f1bd67d --- /dev/null +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/object/entry/StringListConfigEntryHandler.java @@ -0,0 +1,46 @@ +package net.modificationstation.stationapi.impl.config.object.entry; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.modificationstation.stationapi.api.config.CharacterUtils; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.screen.BaseListScreenBuilder; +import net.modificationstation.stationapi.impl.config.screen.StringListScreenBuilder; +import uk.co.benjiweber.expressions.tuple.BiTuple; + +import java.lang.reflect.*; +import java.util.*; + +public class StringListConfigEntryHandler extends BaseListConfigEntryHandler { + + public StringListConfigEntryHandler(String id, ConfigEntry configEntry, Field parentField, Object parentObject, boolean multiplayerSynced, String[] value, String[] defaultValue) { + super(id, configEntry, parentField, parentObject, multiplayerSynced, value, defaultValue); + } + + @Override + @Environment(EnvType.CLIENT) + public BaseListScreenBuilder createListScreen() { + BaseListScreenBuilder listScreen = new StringListScreenBuilder(parent, configEntry, this, str -> stringValidator(configEntry, multiplayerLoaded, str)); + listScreen.setValues(value); + return listScreen; + } + + @Override + public String strToVal(String str) { + return null; + } + + public static List stringValidator(ConfigEntry configEntry, boolean multiplayerLoaded, String str) { + if (multiplayerLoaded) { + return Collections.singletonList("Server synced, you cannot change this value"); + } + if (str.length() > configEntry.maxLength()) { + return Collections.singletonList("Too long"); + } + if (str.length() < configEntry.minLength()) { + return Collections.singletonList("Too short"); + } + return null; + } +} + diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/BaseListScreenBuilder.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/BaseListScreenBuilder.java index 005b5fbbd..6b36f567a 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/BaseListScreenBuilder.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/BaseListScreenBuilder.java @@ -1,14 +1,14 @@ package net.modificationstation.stationapi.impl.config.screen; -import net.modificationstation.stationapi.api.config.CharacterUtils; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; import net.minecraft.class_35; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.EntryListWidget; import net.minecraft.client.resource.language.TranslationStorage; +import net.modificationstation.stationapi.api.config.CharacterUtils; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import net.modificationstation.stationapi.impl.config.screen.widget.ExtensibleTextFieldWidget; import net.modificationstation.stationapi.impl.config.screen.widget.TexturedButtonWidget; import net.modificationstation.stationapi.mixin.config.client.EntryListWidgetAccessor; @@ -27,15 +27,15 @@ public abstract class BaseListScreenBuilder extends Screen { protected final Screen parent; protected int mouseX = -1; protected int mouseY = -1; - protected ConfigEntry configEntry; + protected ConfigEntryHandler configEntry; public final List textFieldWidgets = new ArrayList<>(); - protected Function>> validator; - protected final MaxLength maxLength; + protected Function> validator; + protected final ConfigEntry configAnnotation; private boolean isInUse = false; - protected BaseListScreenBuilder(Screen parent, MaxLength maxLength, ConfigEntry configEntry, Function>> validator) { + protected BaseListScreenBuilder(Screen parent, ConfigEntry configAnnotation, ConfigEntryHandler configEntry, Function> validator) { this.parent = parent; - this.maxLength = maxLength; + this.configAnnotation = configAnnotation; this.configEntry = configEntry; this.validator = validator; } @@ -45,7 +45,7 @@ public void setValues(List list) { list.forEach((value) -> { ExtensibleTextFieldWidget textbox = new ExtensibleTextFieldWidget(textRenderer); textbox.setValidator(validator); - textbox.setMaxLength(maxLength.value()); + textbox.setMaxLength(Math.toIntExact(configAnnotation.maxLength())); // This helper throws an exception if the number is too high for an int. Handy! textbox.setText(String.valueOf(value)); textFieldWidgets.add(textbox); }); @@ -120,12 +120,10 @@ public void render(int mouseX, int mouseY, float delta) { textRenderer.drawWithShadow(configEntry.name, (width / 2) - (textRenderer.getWidth(configEntry.name) / 2), 4, 16777215); textRenderer.drawWithShadow(configEntry.description, (width / 2) - (textRenderer.getWidth(configEntry.description) / 2), 18, 8421504); - if (configEntry.parentField.isAnnotationPresent(MaxLength.class)) { - MaxLength maxLength = configEntry.parentField.getAnnotation(MaxLength.class); - if ((!maxLength.fixedArray() && maxLength.arrayValue() < textFieldWidgets.size()) || (maxLength.fixedArray() && maxLength.arrayValue() != textFieldWidgets.size())) { - String text = "Array is not the right size!"; - textRenderer.drawWithShadow(text, (width / 2) - (textRenderer.getWidth(text) / 2), 34, CharacterUtils.getIntFromColour(Color.RED)); - } + ConfigEntry maxLength = configEntry.parentField.getAnnotation(ConfigEntry.class); + if (maxLength.minArrayLength() < textFieldWidgets.size() || maxLength.maxArrayLength() > textFieldWidgets.size()) { + String text = "Array is not the right size! (" + textFieldWidgets.size() + " outside of " + maxLength.minArrayLength() + " / " + maxLength.maxArrayLength() + ")"; + textRenderer.drawWithShadow(text, (width / 2) - (textRenderer.getWidth(text) / 2), 34, CharacterUtils.getIntFromColour(Color.RED)); } List tooltip = ((ScreenAccessor) this).getMouseTooltip(mouseX, mouseY, textFieldWidgets); diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/FloatListScreenBuilder.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/FloatListScreenBuilder.java index c13c80bd4..73e8c082d 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/FloatListScreenBuilder.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/FloatListScreenBuilder.java @@ -1,8 +1,8 @@ package net.modificationstation.stationapi.impl.config.screen; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; import net.minecraft.client.gui.screen.Screen; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import uk.co.benjiweber.expressions.tuple.BiTuple; import java.util.*; @@ -10,8 +10,8 @@ public class FloatListScreenBuilder extends BaseListScreenBuilder { - public FloatListScreenBuilder(Screen parent, MaxLength maxLength, ConfigEntry configEntry, Function>> validator) { - super(parent, maxLength, configEntry, validator); + public FloatListScreenBuilder(Screen parent, ConfigEntry configAnnotation, ConfigEntryHandler configEntry, Function> validator) { + super(parent, configAnnotation, configEntry, validator); } @Override diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/IntegerListScreenBuilder.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/IntegerListScreenBuilder.java index 58376655f..2f9a95b1b 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/IntegerListScreenBuilder.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/IntegerListScreenBuilder.java @@ -1,8 +1,8 @@ package net.modificationstation.stationapi.impl.config.screen; -import net.modificationstation.stationapi.api.config.MaxLength; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; import net.minecraft.client.gui.screen.Screen; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import uk.co.benjiweber.expressions.tuple.BiTuple; import java.util.*; @@ -10,7 +10,7 @@ public class IntegerListScreenBuilder extends BaseListScreenBuilder { - public IntegerListScreenBuilder(Screen parent, MaxLength maxLength, ConfigEntry configEntry, Function>> validator) { + public IntegerListScreenBuilder(Screen parent, ConfigEntry maxLength, ConfigEntryHandler configEntry, Function> validator) { super(parent, maxLength, configEntry, validator); } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/RootScreenBuilder.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/RootScreenBuilder.java index b68d8ae70..17889ba0f 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/RootScreenBuilder.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/RootScreenBuilder.java @@ -1,31 +1,38 @@ package net.modificationstation.stationapi.impl.config.screen; import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; -import net.modificationstation.stationapi.impl.config.EventStorage; -import net.modificationstation.stationapi.impl.config.GCCore; -import net.modificationstation.stationapi.impl.config.object.ConfigCategory; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; +import net.modificationstation.stationapi.api.config.ConfigRoot; +import net.modificationstation.stationapi.impl.config.ConfigRootEntry; +import net.modificationstation.stationapi.impl.config.EventStorage; +import net.modificationstation.stationapi.impl.config.GCCore; +import net.modificationstation.stationapi.impl.config.object.ConfigCategoryHandler; import uk.co.benjiweber.expressions.tuple.BiTuple; import java.util.*; +import java.util.function.*; public class RootScreenBuilder extends ScreenBuilder { - private final ArrayList, ConfigCategory>> allRoots = new ArrayList<>(); + private final ArrayList allRoots = new ArrayList<>(); private final List switchButtons = new ArrayList<>(); public int currentIndex = 1; // Arrays start at 1 :fatlaugh: - public RootScreenBuilder(Screen parent, EntrypointContainer mod, ConfigCategory baseCategory) { + public RootScreenBuilder(Screen parent, ModContainer mod, ConfigCategoryHandler baseCategory) { super(parent, mod, baseCategory); //noinspection deprecation GCCore.MOD_CONFIGS.forEach((key, value) -> { - if (key.namespace.toString().equals(mod.getProvider().getMetadata().getId())) { + if (key.namespace.toString().equals(mod.getMetadata().getId())) { allRoots.add(value); } }); + +// allRoots.sort(Collections.reverseOrder(Comparator.comparingInt(entry -> entry.configRoot().index()))); + allRoots.sort(Comparator.comparingInt(entry -> entry.configRoot().index())); } @Override @@ -37,7 +44,7 @@ public void init() { if (prevRoot < 0) { prevRoot = allRoots.size()-1; } - ButtonWidget button = new ButtonWidget(buttons.size(), 2, 0, 160, 20, "< " + allRoots.get(prevRoot).two().name); + ButtonWidget button = new ButtonWidget(buttons.size(), 2, 0, 160, 20, "< " + allRoots.get(prevRoot).configRoot().visibleName()); //noinspection unchecked buttons.add(button); screenButtons.add(button); @@ -47,7 +54,7 @@ public void init() { if (nextRoot > allRoots.size()-1) { nextRoot = 0; } - button = new ButtonWidget(buttons.size(), width - 162, 0, 160, 20, allRoots.get(nextRoot).two().name + " >"); + button = new ButtonWidget(buttons.size(), width - 162, 0, 160, 20, allRoots.get(nextRoot).configRoot().visibleName() + " >"); //noinspection unchecked buttons.add(button); screenButtons.add(button); @@ -71,7 +78,7 @@ protected void buttonClicked(ButtonWidget button) { else if (index < 0) { index = allRoots.size()-1; } - RootScreenBuilder builder = (RootScreenBuilder) allRoots.get(index).two().getConfigScreen(parent, mod); + RootScreenBuilder builder = (RootScreenBuilder) allRoots.get(index).configCategoryHandler().getConfigScreen(parent, mod); builder.currentIndex = index; //noinspection deprecation ((Minecraft) FabricLoader.getInstance().getGameInstance()).setScreen(builder); diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/ScreenBuilder.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/ScreenBuilder.java index 61b7499cb..6b11b2623 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/ScreenBuilder.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/ScreenBuilder.java @@ -1,19 +1,20 @@ package net.modificationstation.stationapi.impl.config.screen; import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.entrypoint.EntrypointContainer; -import net.modificationstation.stationapi.api.config.CharacterUtils; -import net.modificationstation.stationapi.api.config.ConfigEntryWithButton; -import net.modificationstation.stationapi.api.config.HasDrawable; -import net.modificationstation.stationapi.impl.config.object.ConfigBase; -import net.modificationstation.stationapi.impl.config.object.ConfigCategory; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.EntryListWidget; import net.minecraft.client.render.Tessellator; import net.minecraft.client.resource.language.TranslationStorage; +import net.modificationstation.stationapi.api.config.CharacterUtils; +import net.modificationstation.stationapi.api.config.ConfigEntryWithButton; +import net.modificationstation.stationapi.api.config.HasDrawable; +import net.modificationstation.stationapi.impl.config.object.ConfigHandlerBase; +import net.modificationstation.stationapi.impl.config.object.ConfigCategoryHandler; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import net.modificationstation.stationapi.mixin.config.client.EntryListWidgetAccessor; import org.lwjgl.input.Mouse; @@ -22,36 +23,36 @@ public class ScreenBuilder extends Screen { protected ScreenScrollList scrollList; - protected HashMap buttonToEntry; - protected final ConfigCategory baseCategory; + protected HashMap buttonToEntry; + protected final ConfigCategoryHandler baseCategory; protected int selectedIndex = -1; protected final Screen parent; - protected final EntrypointContainer mod; + protected final ModContainer mod; protected int mouseX = -1; protected int mouseY = -1; - protected List configBases = new ArrayList<>(); + protected List configHandlerBases = new ArrayList<>(); protected int backButtonID; protected List screenButtons = new ArrayList<>(); - public ScreenBuilder(Screen parent, EntrypointContainer mod, ConfigCategory baseCategory) { + public ScreenBuilder(Screen parent, ModContainer mod, ConfigCategoryHandler baseCategory) { this.parent = parent; this.mod = mod; this.baseCategory = baseCategory; - configBases.addAll(baseCategory.values.values()); - configBases.sort((self, other) -> { - if (other instanceof ConfigCategory) { + configHandlerBases.addAll(baseCategory.values.values()); + configHandlerBases.sort((self, other) -> { + if (other instanceof ConfigCategoryHandler) { return 1; } - return self instanceof ConfigCategory? -1 : self.name.compareTo(other.name); + return self instanceof ConfigCategoryHandler ? -1 : self.name.compareTo(other.name); }); } @Override public void init() { baseCategory.values.values().forEach((value) -> { - if (value instanceof ConfigEntry) { + if (value instanceof ConfigEntryHandler) { //noinspection rawtypes - ConfigEntry configEntry = (ConfigEntry) value; + ConfigEntryHandler configEntry = (ConfigEntryHandler) value; if (configEntry.getDrawableValue() != null) { configEntry.value = configEntry.getDrawableValue(); } @@ -66,8 +67,8 @@ public void init() { buttons.add(button); screenButtons.add(button); baseCategory.values.values().forEach((value) -> { - if (value instanceof ConfigEntry) { - ((ConfigEntry) value).init(this, textRenderer); + if (value instanceof ConfigEntryHandler) { + ((ConfigEntryHandler) value).init(this, textRenderer); } value.getDrawables().forEach(val -> { if (val instanceof ButtonWidget) { @@ -83,9 +84,9 @@ public void init() { @Override public void tick() { super.tick(); - for (ConfigBase configBase : baseCategory.values.values()) { - if (configBase instanceof ConfigEntry) { - configBase.getDrawables().forEach(HasDrawable::tick); + for (ConfigHandlerBase configHandlerBase : baseCategory.values.values()) { + if (configHandlerBase instanceof ConfigEntryHandler) { + configHandlerBase.getDrawables().forEach(HasDrawable::tick); } } } @@ -93,9 +94,9 @@ public void tick() { @Override protected void keyPressed(char character, int key) { super.keyPressed(character, key); - for (ConfigBase configBase : baseCategory.values.values()) { - if (configBase instanceof ConfigEntry) { - configBase.getDrawables().forEach(val -> val.keyPressed(character, key)); + for (ConfigHandlerBase configHandlerBase : baseCategory.values.values()) { + if (configHandlerBase instanceof ConfigEntryHandler) { + configHandlerBase.getDrawables().forEach(val -> val.keyPressed(character, key)); } } } @@ -113,7 +114,7 @@ public void render(int mouseX, int mouseY, float delta) { textRenderer.drawWithShadow(baseCategory.name, (width/2) - (textRenderer.getWidth(baseCategory.name)/2), 4, 16777215); textRenderer.drawWithShadow(baseCategory.description, (width/2) - (textRenderer.getWidth(baseCategory.description)/2), 18, 8421504); ArrayList drawables = new ArrayList<>(); - configBases.forEach((configBase -> drawables.addAll(configBase.getDrawables()))); + configHandlerBases.forEach((configHandlerBase -> drawables.addAll(configHandlerBase.getDrawables()))); if(mouseY > 32 && mouseY < height - 33) { List tooltip = ((ScreenAccessor) this).getMouseTooltip(mouseX, mouseY, drawables); if (tooltip != null) { @@ -154,9 +155,9 @@ public void onMouseEvent() { super.onMouseEvent(); float dWheel = Mouse.getDWheel(); if (Mouse.isButtonDown(0) && mouseY > 32 && mouseY < height - 33) { - for (ConfigBase configBase : baseCategory.values.values()) { - if (configBase instanceof ConfigEntry) { - configBase.getDrawables().forEach(val -> val.mouseClicked(mouseX, mouseY, 0)); + for (ConfigHandlerBase configHandlerBase : baseCategory.values.values()) { + if (configHandlerBase instanceof ConfigEntryHandler) { + configHandlerBase.getDrawables().forEach(val -> val.mouseClicked(mouseX, mouseY, 0)); } } } @@ -175,18 +176,18 @@ else if (mouseY >= 32 && mouseY <= height - 33) { if (buttonToEntry.get(button.id) instanceof ConfigEntryWithButton) { ((ConfigEntryWithButton) buttonToEntry.get(button.id)).onClick(); } - else if (buttonToEntry.get(button.id) instanceof ConfigCategory) { + else if (buttonToEntry.get(button.id) instanceof ConfigCategoryHandler) { //noinspection deprecation - ((Minecraft) FabricLoader.getInstance().getGameInstance()).setScreen(((ConfigCategory) buttonToEntry.get(button.id)).getConfigScreen(this, mod)); + ((Minecraft) FabricLoader.getInstance().getGameInstance()).setScreen(((ConfigCategoryHandler) buttonToEntry.get(button.id)).getConfigScreen(this, mod)); } } } public void saveToEntries() { baseCategory.values.values().forEach((value) -> { - if (value instanceof ConfigEntry) { + if (value instanceof ConfigEntryHandler) { //noinspection rawtypes - ConfigEntry configEntry = (ConfigEntry) value; + ConfigEntryHandler configEntry = (ConfigEntryHandler) value; if (configEntry.isValueValid()) { configEntry.value = configEntry.getDrawableValue(); } @@ -211,7 +212,7 @@ public void scroll(float value) { @Override protected int getEntryCount() { - return configBases.size(); + return configHandlerBases.size(); } @Override @@ -231,11 +232,11 @@ protected void renderBackground() { @Override protected void renderEntry(int itemId, int x, int y, int i1, Tessellator arg) { - ConfigBase configBase = configBases.get(itemId); - ScreenBuilder.this.drawTextWithShadow(ScreenBuilder.this.textRenderer, configBase.name, x + 2, y + 1, 16777215); - configBase.getDrawables().forEach(val -> val.setXYWH(x + 2, y + 12, 212, 20)); - configBase.getDrawables().forEach(val -> val.draw(mouseX, mouseY)); - ScreenBuilder.this.drawTextWithShadow(ScreenBuilder.this.textRenderer, configBase.description, x + 2, y + 34, 8421504); + ConfigHandlerBase configHandlerBase = configHandlerBases.get(itemId); + ScreenBuilder.this.drawTextWithShadow(ScreenBuilder.this.textRenderer, configHandlerBase.name, x + 2, y + 1, 16777215); + configHandlerBase.getDrawables().forEach(val -> val.setXYWH(x + 2, y + 12, 212, 20)); + configHandlerBase.getDrawables().forEach(val -> val.draw(mouseX, mouseY)); + ScreenBuilder.this.drawTextWithShadow(ScreenBuilder.this.textRenderer, configHandlerBase.description, x + 2, y + 34, 8421504); } } } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/StringListScreenBuilder.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/StringListScreenBuilder.java index 13cf3125f..1913a4cff 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/StringListScreenBuilder.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/StringListScreenBuilder.java @@ -1,8 +1,8 @@ package net.modificationstation.stationapi.impl.config.screen; -import net.modificationstation.stationapi.api.config.MaxLength; import net.minecraft.client.gui.screen.Screen; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; +import net.modificationstation.stationapi.api.config.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import uk.co.benjiweber.expressions.tuple.BiTuple; import java.util.*; @@ -10,8 +10,8 @@ public class StringListScreenBuilder extends BaseListScreenBuilder { - public StringListScreenBuilder(Screen parent, MaxLength maxLength, ConfigEntry configEntry, Function>> validator) { - super(parent, maxLength, configEntry, validator); + public StringListScreenBuilder(Screen parent, ConfigEntry configAnnotation, ConfigEntryHandler configEntry, Function> validator) { + super(parent, configAnnotation, configEntry, validator); } @Override diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/ExtensibleTextFieldWidget.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/ExtensibleTextFieldWidget.java index 806ea7639..9a5b5c5ca 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/ExtensibleTextFieldWidget.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/ExtensibleTextFieldWidget.java @@ -1,11 +1,11 @@ package net.modificationstation.stationapi.impl.config.screen.widget; -import net.modificationstation.stationapi.api.config.CharacterUtils; -import net.modificationstation.stationapi.api.config.HasDrawable; -import net.modificationstation.stationapi.api.config.HasToolTip; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.render.Tessellator; +import net.modificationstation.stationapi.api.config.CharacterUtils; +import net.modificationstation.stationapi.api.config.HasDrawable; +import net.modificationstation.stationapi.api.config.HasToolTip; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; import uk.co.benjiweber.expressions.tuple.BiTuple; @@ -42,7 +42,7 @@ public class ExtensibleTextFieldWidget extends DrawContext implements HasDrawabl public int errorBorderColour = CharacterUtils.getIntFromColour(new Color(200, 50, 50)); private boolean doRenderUpdate = true; - private Function>> contentsValidator; + private Function> contentsValidator; public ExtensibleTextFieldWidget(TextRenderer textRenderer) { this.textRenderer = textRenderer; @@ -54,7 +54,7 @@ public ExtensibleTextFieldWidget(TextRenderer textRenderer) { public boolean isValueValid() { if (contentsValidator != null) { - return contentsValidator.apply(getText()).one(); + return contentsValidator.apply(getText()) == null; } return true; } @@ -331,7 +331,7 @@ public void setXYWH(int x, int y, int width, int height) { @Override public List getTooltip() { if (contentsValidator != null) { - return contentsValidator.apply(getText()).two(); + return contentsValidator.apply(getText()); } return null; } @@ -522,7 +522,7 @@ public boolean isEnabled() { return enabled; } - public void setValidator(Function>> contentsValidator) { + public void setValidator(Function> contentsValidator) { this.contentsValidator = contentsValidator; } } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/FancyButtonWidget.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/FancyButtonWidget.java index eb2538f15..77cf4792b 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/FancyButtonWidget.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/FancyButtonWidget.java @@ -1,11 +1,11 @@ package net.modificationstation.stationapi.impl.config.screen.widget; import net.fabricmc.loader.api.FabricLoader; -import net.modificationstation.stationapi.api.config.HasDrawable; -import net.modificationstation.stationapi.api.config.HasToolTip; import net.minecraft.client.Minecraft; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.widget.ButtonWidget; +import net.modificationstation.stationapi.api.config.HasDrawable; +import net.modificationstation.stationapi.api.config.HasToolTip; import org.lwjgl.opengl.GL11; import java.util.*; diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/IconWidget.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/IconWidget.java index f21aca459..cba9d1265 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/IconWidget.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/IconWidget.java @@ -1,10 +1,10 @@ package net.modificationstation.stationapi.impl.config.screen.widget; import net.fabricmc.loader.api.FabricLoader; -import net.modificationstation.stationapi.api.config.HasDrawable; -import net.modificationstation.stationapi.api.config.HasToolTip; import net.minecraft.client.Minecraft; import net.minecraft.client.render.Tessellator; +import net.modificationstation.stationapi.api.config.HasDrawable; +import net.modificationstation.stationapi.api.config.HasToolTip; import org.lwjgl.opengl.GL11; import java.util.*; diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/ResetConfigWidget.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/ResetConfigWidget.java index 56cda6744..9e6977286 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/ResetConfigWidget.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/ResetConfigWidget.java @@ -1,13 +1,13 @@ package net.modificationstation.stationapi.impl.config.screen.widget; -import net.modificationstation.stationapi.impl.config.object.ConfigEntry; +import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import java.util.*; public class ResetConfigWidget extends IconWidget { - private final ConfigEntry configEntry; + private final ConfigEntryHandler configEntry; - public ResetConfigWidget(int x, int y, int width, int height, ConfigEntry configEntry) { + public ResetConfigWidget(int x, int y, int width, int height, ConfigEntryHandler configEntry) { super(x, y, width, height, "/assets/gcapi/reset.png"); this.configEntry = configEntry; } diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/TexturedButtonWidget.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/TexturedButtonWidget.java index 3e50e3b86..87c1a294e 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/TexturedButtonWidget.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/screen/widget/TexturedButtonWidget.java @@ -1,9 +1,9 @@ package net.modificationstation.stationapi.impl.config.screen.widget; -import net.modificationstation.stationapi.api.config.HasToolTip; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.render.Tessellator; +import net.modificationstation.stationapi.api.config.HasToolTip; import org.lwjgl.opengl.GL11; import java.util.*; diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/DrawContextMixin.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/DrawContextMixin.java index b4618ab9f..02be24944 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/DrawContextMixin.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/DrawContextMixin.java @@ -1,7 +1,7 @@ package net.modificationstation.stationapi.mixin.config.client; -import net.modificationstation.stationapi.impl.config.DrawContextAccessor; import net.minecraft.client.gui.DrawContext; +import net.modificationstation.stationapi.impl.config.DrawContextAccessor; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/ModMenuMixin.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/ModMenuMixin.java index 09ece821b..1d7efa7fb 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/ModMenuMixin.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/ModMenuMixin.java @@ -2,9 +2,10 @@ import com.google.common.collect.ImmutableMap; import io.github.prospector.modmenu.ModMenu; -import net.modificationstation.stationapi.api.config.GConfig; -import net.modificationstation.stationapi.impl.config.GCCore; import net.minecraft.client.gui.screen.Screen; +import net.modificationstation.stationapi.api.config.ConfigRoot; +import net.modificationstation.stationapi.api.util.Identifier; +import net.modificationstation.stationapi.impl.config.GCCore; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -24,9 +25,9 @@ private void hijackConfigScreens(CallbackInfo ci, ImmutableMap.Builder> map = new HashMap<>(); //noinspection deprecation GCCore.MOD_CONFIGS.forEach((key, value) -> { - if (!map.containsKey(key.namespace.toString()) || value.two().parentField.getAnnotation(GConfig.class).primary()) { + if (!map.containsKey(key.namespace.toString())) { map.remove(key.namespace.toString()); - map.put(key.namespace.toString(), (parent) -> value.two().getConfigScreen(parent, value.one())); + map.put(key.namespace.toString(), (parent) -> value.configCategoryHandler().getConfigScreen(parent, value.modContainer())); } }); builder.putAll(map); diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/ScreenMixin.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/ScreenMixin.java index 39ca3cc4a..8c7e1e52c 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/ScreenMixin.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/ScreenMixin.java @@ -1,11 +1,11 @@ package net.modificationstation.stationapi.mixin.config.client; -import net.modificationstation.stationapi.api.config.CharacterUtils; -import net.modificationstation.stationapi.api.config.HasToolTip; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; +import net.modificationstation.stationapi.api.config.CharacterUtils; +import net.modificationstation.stationapi.api.config.HasToolTip; import net.modificationstation.stationapi.impl.config.screen.ScreenAccessor; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/TextFieldWidgetMixin.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/TextFieldWidgetMixin.java index 8ca02c6db..93db85bbe 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/TextFieldWidgetMixin.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/mixin/config/client/TextFieldWidgetMixin.java @@ -1,8 +1,8 @@ package net.modificationstation.stationapi.mixin.config.client; -import net.modificationstation.stationapi.api.config.HasDrawable; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.widget.TextFieldWidget; +import net.modificationstation.stationapi.api.config.HasDrawable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mutable; diff --git a/glass-config-api-v3/src/main/resources/fabric.mod.json b/glass-config-api-v3/src/main/resources/fabric.mod.json index f7c5097e3..a98db2e02 100644 --- a/glass-config-api-v3/src/main/resources/fabric.mod.json +++ b/glass-config-api-v3/src/main/resources/fabric.mod.json @@ -36,10 +36,10 @@ "net.modificationstation.stationapi.impl.config.example.ExampleEntryPointListeners" ], "stationapi:event_bus_server": [ - "net.modificationstation.stationapi.impl.config.events.InitServerNetworking" + "net.modificationstation.stationapi.impl.config.event.InitServerNetworking" ], "stationapi:event_bus_client": [ - "net.modificationstation.stationapi.impl.config.events.InitClientNetworking" + "net.modificationstation.stationapi.impl.config.event.InitClientNetworking" ] }, "custom": {