added config sync logging settings

This commit is contained in:
FalsePattern committed 2024-12-06 20:44:47 +01:00
1 parent 69e7e27e43
commit 627125b821
8 files changed
+135 -42

No files matched your search

@@ -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;
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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
}
}
@@ -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)
@@ -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);
}
}
@@ -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();
}
}
@@ -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));
}
}
}
}
@@ -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);
}
}
}
}
}