diff --git a/XPlat/src/main/java/de/wonejo/wuidebook/WuidebookCommonMod.java b/XPlat/src/main/java/de/wonejo/wuidebook/WuidebookCommonMod.java index f6b6d77..f7f5421 100644 --- a/XPlat/src/main/java/de/wonejo/wuidebook/WuidebookCommonMod.java +++ b/XPlat/src/main/java/de/wonejo/wuidebook/WuidebookCommonMod.java @@ -1,6 +1,12 @@ package de.wonejo.wuidebook; import de.wonejo.wuidebook.api.compat.WuidebookImplementation; +import de.wonejo.wuidebook.api.config.ConfigFile; +import de.wonejo.wuidebook.api.config.ConfigManager; +import de.wonejo.wuidebook.api.util.Constants; +import de.wonejo.wuidebook.api.util.McEnvironment; +import de.wonejo.wuidebook.impl.config.serializer.*; +import de.wonejo.wuidebook.impl.config.serializer.color.ColorConfigSerializer; import de.wonejo.wuidebook.impl.service.ModServices; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -15,7 +21,7 @@ public class WuidebookCommonMod { private static final Logger LOGGER = LogManager.getLogger(); private static final WuidebookCommonMod INSTANCE = new WuidebookCommonMod(); private static Path CONFIG_DIRECTORY = ModServices.ABSTRACTION.getConfigPath(); - + private final ConfigManager configManager = ConfigManager.get(); private WuidebookCommonMod () {} @@ -34,6 +40,20 @@ public void setup () { } private void setupConfigAPI (@NotNull List pImplementation) { + this.configManager.registerSerializer(Constants.CFG_STR_SERIALIZER, new StringCfgSerializer()); + this.configManager.registerSerializer(Constants.CFG_INT_SERIALIZER, new IntCfgSerializer()); + this.configManager.registerSerializer(Constants.CFG_FLOAT_SERIALIZER, new FloatCfgSerializer()); + this.configManager.registerSerializer(Constants.CFG_DOUBLE_SERIALIZER, new DoubleCfgSerializer()); + this.configManager.registerSerializer(Constants.CFG_BOOL_SERIALIZER, new BooleanCfgSerializer()); + this.configManager.registerSerializer(Constants.CFG_LIST_SERIALIZER, new ListCfgSerializer<>()); + this.configManager.registerSerializer(Constants.CFG_COLOR_SERIALIZER, new ColorConfigSerializer()); + + for ( WuidebookImplementation impl : pImplementation ) { + impl.onRegisterConfigSerializer(this.configManager); + impl.onRegisterConfigFiles(this.configManager); + } + + this.configManager.getFileList(McEnvironment.COMMON).forEach(ConfigFile::loadFile); } public static Path getConfigDirectory() { diff --git a/XPlat/src/main/java/de/wonejo/wuidebook/api/util/Constants.java b/XPlat/src/main/java/de/wonejo/wuidebook/api/util/Constants.java index 8f9ee4b..61d5841 100644 --- a/XPlat/src/main/java/de/wonejo/wuidebook/api/util/Constants.java +++ b/XPlat/src/main/java/de/wonejo/wuidebook/api/util/Constants.java @@ -1,5 +1,16 @@ package de.wonejo.wuidebook.api.util; +import net.minecraft.resources.ResourceLocation; + public class Constants { public static final String MOD_ID = "wuidebook"; + + public static final ResourceLocation CFG_STR_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_str_cfg"); + public static final ResourceLocation CFG_INT_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_int_cfg"); + public static final ResourceLocation CFG_FLOAT_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_float_cfg"); + public static final ResourceLocation CFG_DOUBLE_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_double_cfg"); + public static final ResourceLocation CFG_BOOL_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_bool_cfg"); + public static final ResourceLocation CFG_LIST_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_list_cfg"); + public static final ResourceLocation CFG_COLOR_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_color_cfg"); + } diff --git a/XPlat/src/main/java/de/wonejo/wuidebook/api/util/ResourceLocationUtils.java b/XPlat/src/main/java/de/wonejo/wuidebook/api/util/ResourceLocationUtils.java new file mode 100644 index 0000000..c98fa1b --- /dev/null +++ b/XPlat/src/main/java/de/wonejo/wuidebook/api/util/ResourceLocationUtils.java @@ -0,0 +1,23 @@ +package de.wonejo.wuidebook.api.util; + +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.NotNull; + +public class ResourceLocationUtils { + + @NotNull + public static ResourceLocation minecraft (String pPath) { + return ResourceLocation.withDefaultNamespace(pPath); + } + + @NotNull + public static ResourceLocation wuidebook ( String pPath ) { + return ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, pPath); + } + + @NotNull + public static ResourceLocation common ( String pPath ) { + return ResourceLocation.fromNamespaceAndPath("c", pPath); + } + +}