Skip to content

Commit

Permalink
added config sync logging settings
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Dec 6, 2024
1 parent 69e7e27 commit 627125b
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +62,7 @@ public FalsePatternLib() {

@Mod.EventHandler
public void construct(FMLConstructionEvent e) {
ConfigEngineConfig.poke();
proxy.construct(e);
Share.EARLY_INIT_DONE = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static void init() {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
@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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,11 +31,7 @@
@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."})
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
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;
Expand All @@ -53,7 +55,7 @@ public static void registerBus() {
@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();
}
}
Expand All @@ -63,23 +65,28 @@ public void onValidationErrorToast(ConfigValidationFailureEvent e) {
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));
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,8 +53,27 @@ public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {

@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);
}
}
}
}
}
11 changes: 9 additions & 2 deletions src/main/resources/assets/falsepatternlib/lang/en_US.lang
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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.

0 comments on commit 627125b

Please sign in to comment.