From 627125b82152b4a8e18923b27d1a33ff57b26452 Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Fri, 6 Dec 2024 20:44:47 +0100 Subject: [PATCH] added config sync logging settings --- .../lib/internal/FalsePatternLib.java | 2 + .../internal/config/ConfigEngineConfig.java | 68 +++++++++++++++++++ .../internal/config/InGameModOptionsFix.java | 2 +- .../lib/internal/config/LibraryGuiConfig.java | 2 +- .../{LibraryConfig.java => MiscConfig.java} | 21 +----- .../config/event/ClientEventHandlerPre.java | 43 +++++++----- .../config/event/CommonEventHandlerPre.java | 28 +++++++- .../assets/falsepatternlib/lang/en_US.lang | 11 ++- 8 files changed, 135 insertions(+), 42 deletions(-) create mode 100644 src/main/java/com/falsepattern/lib/internal/config/ConfigEngineConfig.java rename src/main/java/com/falsepattern/lib/internal/config/{LibraryConfig.java => MiscConfig.java} (73%) diff --git a/src/main/java/com/falsepattern/lib/internal/FalsePatternLib.java b/src/main/java/com/falsepattern/lib/internal/FalsePatternLib.java index 56a8cce..bbd5561 100644 --- a/src/main/java/com/falsepattern/lib/internal/FalsePatternLib.java +++ b/src/main/java/com/falsepattern/lib/internal/FalsePatternLib.java @@ -23,6 +23,7 @@ package com.falsepattern.lib.internal; import com.falsepattern.lib.internal.asm.CoreLoadingPlugin; +import com.falsepattern.lib.internal.config.ConfigEngineConfig; import com.falsepattern.lib.internal.proxy.CommonProxy; import cpw.mods.fml.common.Loader; @@ -61,6 +62,7 @@ public class FalsePatternLib { @Mod.EventHandler public void construct(FMLConstructionEvent e) { + ConfigEngineConfig.poke(); proxy.construct(e); Share.EARLY_INIT_DONE = true; } diff --git a/src/main/java/com/falsepattern/lib/internal/config/ConfigEngineConfig.java b/src/main/java/com/falsepattern/lib/internal/config/ConfigEngineConfig.java new file mode 100644 index 0000000..fcc1cc2 --- /dev/null +++ b/src/main/java/com/falsepattern/lib/internal/config/ConfigEngineConfig.java @@ -0,0 +1,68 @@ +/* + * This file is part of FalsePatternLib. + * + * Copyright (C) 2022-2024 FalsePattern + * All Rights Reserved + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * FalsePatternLib is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * FalsePatternLib is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with FalsePatternLib. If not, see . + */ + +package com.falsepattern.lib.internal.config; + +import com.falsepattern.lib.StableAPI; +import com.falsepattern.lib.config.Config; +import com.falsepattern.lib.config.ConfigurationManager; +import com.falsepattern.lib.internal.Tags; + +@Config.Comment("Settings for the FPLib config system (also used by other mods)") +@Config.LangKey +@Config(modid = Tags.MODID, + category = "config_engine") +public class ConfigEngineConfig { + + @Config.Comment("How the config error logging should be set up.") + @Config.LangKey + @Config.DefaultEnum("Log") + @Config.Name(value = "configErrorLogging") + public static LoggingLevel CONFIG_ERROR_LOGGING; + + @Config.Comment("How successful config synchronizations should be logged.") + @Config.LangKey + @Config.DefaultEnum("Log") + @Config.Name(value = "configSyncSuccessLogging") + public static LoggingLevel CONFIG_SYNC_SUCCESS_LOGGING; + + @Config.Comment("How failed config synchronizations should be logged.") + @Config.LangKey + @Config.DefaultEnum("LogAndToast") + @Config.Name(value = "configSyncFailureLogging") + public static LoggingLevel CONFIG_SYNC_FAILURE_LOGGING; + + static { + ConfigurationManager.selfInit(); + } + + public static void poke() { + + } + + public enum LoggingLevel { + @StableAPI.Expose(since = "__INTERNAL__") None, + @StableAPI.Expose(since = "__INTERNAL__") Log, + @StableAPI.Expose(since = "__INTERNAL__") LogAndToast + } +} diff --git a/src/main/java/com/falsepattern/lib/internal/config/InGameModOptionsFix.java b/src/main/java/com/falsepattern/lib/internal/config/InGameModOptionsFix.java index c0e62ce..6978e7a 100644 --- a/src/main/java/com/falsepattern/lib/internal/config/InGameModOptionsFix.java +++ b/src/main/java/com/falsepattern/lib/internal/config/InGameModOptionsFix.java @@ -71,7 +71,7 @@ public final class InGameModOptionsFix { public void onGuiOpen(final GuiOpenEvent event) { if (!isInitialized) return; - if (!LibraryConfig.IN_GAME_MOD_OPTIONS_FIX) + if (!MiscConfig.IN_GAME_MOD_OPTIONS_FIX) return; if (event.gui instanceof GuiIngameModOptions) diff --git a/src/main/java/com/falsepattern/lib/internal/config/LibraryGuiConfig.java b/src/main/java/com/falsepattern/lib/internal/config/LibraryGuiConfig.java index e9a400d..d017f36 100644 --- a/src/main/java/com/falsepattern/lib/internal/config/LibraryGuiConfig.java +++ b/src/main/java/com/falsepattern/lib/internal/config/LibraryGuiConfig.java @@ -33,6 +33,6 @@ import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class LibraryGuiConfig extends SimpleGuiConfig { public LibraryGuiConfig(GuiScreen parent) throws ConfigException { - super(parent, Tags.MODID, Tags.MODNAME, LibraryConfig.class, ToastConfig.class); + super(parent, Tags.MODID, Tags.MODNAME, MiscConfig.class, ToastConfig.class, ConfigEngineConfig.class); } } diff --git a/src/main/java/com/falsepattern/lib/internal/config/LibraryConfig.java b/src/main/java/com/falsepattern/lib/internal/config/MiscConfig.java similarity index 73% rename from src/main/java/com/falsepattern/lib/internal/config/LibraryConfig.java rename to src/main/java/com/falsepattern/lib/internal/config/MiscConfig.java index 15d4791..68f816a 100644 --- a/src/main/java/com/falsepattern/lib/internal/config/LibraryConfig.java +++ b/src/main/java/com/falsepattern/lib/internal/config/MiscConfig.java @@ -22,7 +22,6 @@ */ package com.falsepattern.lib.internal.config; -import com.falsepattern.lib.StableAPI; import com.falsepattern.lib.config.Config; import com.falsepattern.lib.config.ConfigurationManager; import com.falsepattern.lib.internal.Tags; @@ -32,11 +31,7 @@ import com.falsepattern.lib.internal.Tags; @Config(modid = Tags.MODID, category = "misc", categoryMigrations = "general") -public class LibraryConfig { - static { - ConfigurationManager.selfInit(); - } - +public class MiscConfig { @Config.Comment({"Fixes the mod options menu in-game.", "By default, the mod options when in already in a game will show \"Test1, Test2, DISABLED\" in bright red.", "This replaces that interface with the one from the main menu."}) @@ -46,17 +41,7 @@ public class LibraryConfig { migrations = "") public static boolean IN_GAME_MOD_OPTIONS_FIX; - @Config.Comment({"How the config error logging should be set up.", - "[None] disables all built-in config validation error logging"}) - @Config.LangKey - @Config.DefaultEnum("Log") - @Config.Name(value = "configErrorLogging", - migrations = "CONFIG_ERROR_LOUDNESS") - public static ValidationLogging CONFIG_ERROR_LOGGING; - - public enum ValidationLogging { - @StableAPI.Expose(since = "__INTERNAL__") None, - @StableAPI.Expose(since = "__INTERNAL__") Log, - @StableAPI.Expose(since = "__INTERNAL__") LogAndToast + static { + ConfigurationManager.selfInit(); } } diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/event/ClientEventHandlerPre.java b/src/main/java/com/falsepattern/lib/internal/impl/config/event/ClientEventHandlerPre.java index fb6eb2e..8daec3a 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/event/ClientEventHandlerPre.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/event/ClientEventHandlerPre.java @@ -26,7 +26,9 @@ package com.falsepattern.lib.internal.impl.config.event; import com.falsepattern.lib.config.Config; import com.falsepattern.lib.config.event.ConfigSyncEvent; import com.falsepattern.lib.config.event.ConfigValidationFailureEvent; -import com.falsepattern.lib.internal.config.LibraryConfig; +import com.falsepattern.lib.internal.FPLog; +import com.falsepattern.lib.internal.config.ConfigEngineConfig; +import com.falsepattern.lib.internal.config.MiscConfig; import com.falsepattern.lib.text.FormattedText; import com.falsepattern.lib.toasts.GuiToast; import com.falsepattern.lib.toasts.SimpleToast; @@ -53,7 +55,7 @@ public class ClientEventHandlerPre { @SubscribeEvent @SideOnly(Side.CLIENT) public void onValidationErrorToast(ConfigValidationFailureEvent e) { - if (LibraryConfig.CONFIG_ERROR_LOGGING == LibraryConfig.ValidationLogging.LogAndToast) { + if (ConfigEngineConfig.CONFIG_ERROR_LOGGING == ConfigEngineConfig.LoggingLevel.LogAndToast) { e.toast(); } } @@ -63,23 +65,28 @@ public class ClientEventHandlerPre { public void onConfigSyncFinished(ConfigSyncEvent.End e) { val cfg = e.configClass.getAnnotation(Config.class); if (e.successful) { - GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK, - null, - FormattedText.parse(EnumChatFormatting.GREEN + "Synced config") - .toChatText() - .get(0), - FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0), - false, - 5000)); + if (ConfigEngineConfig.CONFIG_SYNC_SUCCESS_LOGGING == ConfigEngineConfig.LoggingLevel.LogAndToast) { + GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK, + null, + FormattedText.parse(EnumChatFormatting.GREEN + "Synced config") + .toChatText() + .get(0), + FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0), + false, + 5000)); + } } else { - GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK, - null, - FormattedText.parse(EnumChatFormatting.RED + "Failed to sync config") - .toChatText() - .get(0), - FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0), - false, - 5000)); + if (ConfigEngineConfig.CONFIG_SYNC_FAILURE_LOGGING == ConfigEngineConfig.LoggingLevel.LogAndToast) { + GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK, + null, + FormattedText.parse(EnumChatFormatting.RED + "Failed to sync config") + .toChatText() + .get(0), + FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0), + false, + 5000)); + } + } } } diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/event/CommonEventHandlerPre.java b/src/main/java/com/falsepattern/lib/internal/impl/config/event/CommonEventHandlerPre.java index 8a15f76..0457f63 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/event/CommonEventHandlerPre.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/event/CommonEventHandlerPre.java @@ -23,11 +23,16 @@ package com.falsepattern.lib.internal.impl.config.event; +import com.falsepattern.lib.config.Config; +import com.falsepattern.lib.config.event.ConfigSyncEvent; import com.falsepattern.lib.config.event.ConfigValidationFailureEvent; -import com.falsepattern.lib.internal.config.LibraryConfig; +import com.falsepattern.lib.internal.FPLog; +import com.falsepattern.lib.internal.config.ConfigEngineConfig; +import com.falsepattern.lib.internal.config.MiscConfig; import com.falsepattern.lib.internal.impl.config.ConfigurationManagerImpl; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import lombok.val; import cpw.mods.fml.client.event.ConfigChangedEvent; import cpw.mods.fml.common.FMLCommonHandler; @@ -48,8 +53,27 @@ public class CommonEventHandlerPre { @SubscribeEvent public void onValidationErrorLog(ConfigValidationFailureEvent e) { - if (LibraryConfig.CONFIG_ERROR_LOGGING != LibraryConfig.ValidationLogging.None) { + if (ConfigEngineConfig.CONFIG_ERROR_LOGGING != ConfigEngineConfig.LoggingLevel.None) { e.logWarn(); } } + + @SubscribeEvent + public void onConfigSyncFinished(ConfigSyncEvent.End e) { + if (e.successful) { + if (ConfigEngineConfig.CONFIG_SYNC_SUCCESS_LOGGING != ConfigEngineConfig.LoggingLevel.None) { + val cfg = e.configClass.getAnnotation(Config.class); + FPLog.LOG.info("Synced config: {}:{}", cfg.modid(), cfg.category()); + } + } else { + if (ConfigEngineConfig.CONFIG_SYNC_FAILURE_LOGGING != ConfigEngineConfig.LoggingLevel.None) { + val cfg = e.configClass.getAnnotation(Config.class); + FPLog.LOG.error("Failed to sync config: {}:{}", cfg.modid(), cfg.category()); + val t = e.error; + if (t != null) { + FPLog.LOG.error(t.getMessage(), t); + } + } + } + } } diff --git a/src/main/resources/assets/falsepatternlib/lang/en_US.lang b/src/main/resources/assets/falsepatternlib/lang/en_US.lang index 29e69a3..3f35167 100644 --- a/src/main/resources/assets/falsepatternlib/lang/en_US.lang +++ b/src/main/resources/assets/falsepatternlib/lang/en_US.lang @@ -1,7 +1,5 @@ config.falsepatternlib.misc=Miscellaneous config.falsepatternlib.misc.tooltip=Settings that don't fit into other categories -config.falsepatternlib.misc.configErrorLogging=Config error logging -config.falsepatternlib.misc.configErrorLogging.tooltip=How the config error logging should be set up.\n[None] disables all built-in config validation error logging. config.falsepatternlib.misc.inGameModOptionsFix=In-Game Mod Options Fix config.falsepatternlib.misc.inGameModOptionsFix.tooltip=Fixes the mod options menu in-game. @@ -13,3 +11,12 @@ config.falsepatternlib.toasts.yOffset=Toast Y Offset config.falsepatternlib.toasts.yOffset.tooltip=The amount of empty space from the top of the screen in pixels. config.falsepatternlib.toasts.align=Toast Alignment config.falsepatternlib.toasts.align.tooltip=Which side of the screen should toasts show up on. + +config.falsepatternlib.config_engine=Configuration Engine +config.falsepatternlib.config_engine.tooltip=Settings for the FPLib config system (also used by other mods) +config.falsepatternlib.config_engine.configErrorLogging=Config error logging +config.falsepatternlib.config_engine.configErrorLogging.tooltip=How the config error logging should be set up.\n[None] disables all built-in config validation error logging. +config.falsepatternlib.config_engine.configSyncSuccessLogging=Config sync success logging +config.falsepatternlib.config_engine.configSyncSuccessLogging.tooltip=How successful config synchronizations should be logged. +config.falsepatternlib.config_engine.configSyncFailureLogging=Config sync failure logging +config.falsepatternlib.config_engine.configSyncFailureLogging.tooltip=How failed config synchronizations should be logged. \ No newline at end of file