Skip to content

Commit 627125b

Browse files
committed
added config sync logging settings
1 parent 69e7e27 commit 627125b

File tree

8 files changed

+135
-42
lines changed

8 files changed

+135
-42
lines changed

src/main/java/com/falsepattern/lib/internal/FalsePatternLib.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package com.falsepattern.lib.internal;
2424

2525
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
26+
import com.falsepattern.lib.internal.config.ConfigEngineConfig;
2627
import com.falsepattern.lib.internal.proxy.CommonProxy;
2728

2829
import cpw.mods.fml.common.Loader;
@@ -61,6 +62,7 @@ public FalsePatternLib() {
6162

6263
@Mod.EventHandler
6364
public void construct(FMLConstructionEvent e) {
65+
ConfigEngineConfig.poke();
6466
proxy.construct(e);
6567
Share.EARLY_INIT_DONE = true;
6668
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This file is part of FalsePatternLib.
3+
*
4+
* Copyright (C) 2022-2024 FalsePattern
5+
* All Rights Reserved
6+
*
7+
* The above copyright notice and this permission notice shall be included
8+
* in all copies or substantial portions of the Software.
9+
*
10+
* FalsePatternLib is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Lesser General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* FalsePatternLib is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Lesser General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Lesser General Public License
21+
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
24+
package com.falsepattern.lib.internal.config;
25+
26+
import com.falsepattern.lib.StableAPI;
27+
import com.falsepattern.lib.config.Config;
28+
import com.falsepattern.lib.config.ConfigurationManager;
29+
import com.falsepattern.lib.internal.Tags;
30+
31+
@Config.Comment("Settings for the FPLib config system (also used by other mods)")
32+
@Config.LangKey
33+
@Config(modid = Tags.MODID,
34+
category = "config_engine")
35+
public class ConfigEngineConfig {
36+
37+
@Config.Comment("How the config error logging should be set up.")
38+
@Config.LangKey
39+
@Config.DefaultEnum("Log")
40+
@Config.Name(value = "configErrorLogging")
41+
public static LoggingLevel CONFIG_ERROR_LOGGING;
42+
43+
@Config.Comment("How successful config synchronizations should be logged.")
44+
@Config.LangKey
45+
@Config.DefaultEnum("Log")
46+
@Config.Name(value = "configSyncSuccessLogging")
47+
public static LoggingLevel CONFIG_SYNC_SUCCESS_LOGGING;
48+
49+
@Config.Comment("How failed config synchronizations should be logged.")
50+
@Config.LangKey
51+
@Config.DefaultEnum("LogAndToast")
52+
@Config.Name(value = "configSyncFailureLogging")
53+
public static LoggingLevel CONFIG_SYNC_FAILURE_LOGGING;
54+
55+
static {
56+
ConfigurationManager.selfInit();
57+
}
58+
59+
public static void poke() {
60+
61+
}
62+
63+
public enum LoggingLevel {
64+
@StableAPI.Expose(since = "__INTERNAL__") None,
65+
@StableAPI.Expose(since = "__INTERNAL__") Log,
66+
@StableAPI.Expose(since = "__INTERNAL__") LogAndToast
67+
}
68+
}

src/main/java/com/falsepattern/lib/internal/config/InGameModOptionsFix.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static void init() {
7171
public void onGuiOpen(final GuiOpenEvent event) {
7272
if (!isInitialized)
7373
return;
74-
if (!LibraryConfig.IN_GAME_MOD_OPTIONS_FIX)
74+
if (!MiscConfig.IN_GAME_MOD_OPTIONS_FIX)
7575
return;
7676

7777
if (event.gui instanceof GuiIngameModOptions)

src/main/java/com/falsepattern/lib/internal/config/LibraryGuiConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
@SideOnly(Side.CLIENT)
3434
public class LibraryGuiConfig extends SimpleGuiConfig {
3535
public LibraryGuiConfig(GuiScreen parent) throws ConfigException {
36-
super(parent, Tags.MODID, Tags.MODNAME, LibraryConfig.class, ToastConfig.class);
36+
super(parent, Tags.MODID, Tags.MODNAME, MiscConfig.class, ToastConfig.class, ConfigEngineConfig.class);
3737
}
3838
}

src/main/java/com/falsepattern/lib/internal/config/LibraryConfig.java renamed to src/main/java/com/falsepattern/lib/internal/config/MiscConfig.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
package com.falsepattern.lib.internal.config;
2424

25-
import com.falsepattern.lib.StableAPI;
2625
import com.falsepattern.lib.config.Config;
2726
import com.falsepattern.lib.config.ConfigurationManager;
2827
import com.falsepattern.lib.internal.Tags;
@@ -32,11 +31,7 @@
3231
@Config(modid = Tags.MODID,
3332
category = "misc",
3433
categoryMigrations = "general")
35-
public class LibraryConfig {
36-
static {
37-
ConfigurationManager.selfInit();
38-
}
39-
34+
public class MiscConfig {
4035
@Config.Comment({"Fixes the mod options menu in-game.",
4136
"By default, the mod options when in already in a game will show \"Test1, Test2, DISABLED\" in bright red.",
4237
"This replaces that interface with the one from the main menu."})
@@ -46,17 +41,7 @@ public class LibraryConfig {
4641
migrations = "")
4742
public static boolean IN_GAME_MOD_OPTIONS_FIX;
4843

49-
@Config.Comment({"How the config error logging should be set up.",
50-
"[None] disables all built-in config validation error logging"})
51-
@Config.LangKey
52-
@Config.DefaultEnum("Log")
53-
@Config.Name(value = "configErrorLogging",
54-
migrations = "CONFIG_ERROR_LOUDNESS")
55-
public static ValidationLogging CONFIG_ERROR_LOGGING;
56-
57-
public enum ValidationLogging {
58-
@StableAPI.Expose(since = "__INTERNAL__") None,
59-
@StableAPI.Expose(since = "__INTERNAL__") Log,
60-
@StableAPI.Expose(since = "__INTERNAL__") LogAndToast
44+
static {
45+
ConfigurationManager.selfInit();
6146
}
6247
}

src/main/java/com/falsepattern/lib/internal/impl/config/event/ClientEventHandlerPre.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import com.falsepattern.lib.config.Config;
2727
import com.falsepattern.lib.config.event.ConfigSyncEvent;
2828
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
29-
import com.falsepattern.lib.internal.config.LibraryConfig;
29+
import com.falsepattern.lib.internal.FPLog;
30+
import com.falsepattern.lib.internal.config.ConfigEngineConfig;
31+
import com.falsepattern.lib.internal.config.MiscConfig;
3032
import com.falsepattern.lib.text.FormattedText;
3133
import com.falsepattern.lib.toasts.GuiToast;
3234
import com.falsepattern.lib.toasts.SimpleToast;
@@ -53,7 +55,7 @@ public static void registerBus() {
5355
@SubscribeEvent
5456
@SideOnly(Side.CLIENT)
5557
public void onValidationErrorToast(ConfigValidationFailureEvent e) {
56-
if (LibraryConfig.CONFIG_ERROR_LOGGING == LibraryConfig.ValidationLogging.LogAndToast) {
58+
if (ConfigEngineConfig.CONFIG_ERROR_LOGGING == ConfigEngineConfig.LoggingLevel.LogAndToast) {
5759
e.toast();
5860
}
5961
}
@@ -63,23 +65,28 @@ public void onValidationErrorToast(ConfigValidationFailureEvent e) {
6365
public void onConfigSyncFinished(ConfigSyncEvent.End e) {
6466
val cfg = e.configClass.getAnnotation(Config.class);
6567
if (e.successful) {
66-
GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK,
67-
null,
68-
FormattedText.parse(EnumChatFormatting.GREEN + "Synced config")
69-
.toChatText()
70-
.get(0),
71-
FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0),
72-
false,
73-
5000));
68+
if (ConfigEngineConfig.CONFIG_SYNC_SUCCESS_LOGGING == ConfigEngineConfig.LoggingLevel.LogAndToast) {
69+
GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK,
70+
null,
71+
FormattedText.parse(EnumChatFormatting.GREEN + "Synced config")
72+
.toChatText()
73+
.get(0),
74+
FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0),
75+
false,
76+
5000));
77+
}
7478
} else {
75-
GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK,
76-
null,
77-
FormattedText.parse(EnumChatFormatting.RED + "Failed to sync config")
78-
.toChatText()
79-
.get(0),
80-
FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0),
81-
false,
82-
5000));
79+
if (ConfigEngineConfig.CONFIG_SYNC_FAILURE_LOGGING == ConfigEngineConfig.LoggingLevel.LogAndToast) {
80+
GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK,
81+
null,
82+
FormattedText.parse(EnumChatFormatting.RED + "Failed to sync config")
83+
.toChatText()
84+
.get(0),
85+
FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0),
86+
false,
87+
5000));
88+
}
89+
8390
}
8491
}
8592
}

src/main/java/com/falsepattern/lib/internal/impl/config/event/CommonEventHandlerPre.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@
2323

2424
package com.falsepattern.lib.internal.impl.config.event;
2525

26+
import com.falsepattern.lib.config.Config;
27+
import com.falsepattern.lib.config.event.ConfigSyncEvent;
2628
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
27-
import com.falsepattern.lib.internal.config.LibraryConfig;
29+
import com.falsepattern.lib.internal.FPLog;
30+
import com.falsepattern.lib.internal.config.ConfigEngineConfig;
31+
import com.falsepattern.lib.internal.config.MiscConfig;
2832
import com.falsepattern.lib.internal.impl.config.ConfigurationManagerImpl;
2933
import lombok.AccessLevel;
3034
import lombok.NoArgsConstructor;
35+
import lombok.val;
3136

3237
import cpw.mods.fml.client.event.ConfigChangedEvent;
3338
import cpw.mods.fml.common.FMLCommonHandler;
@@ -48,8 +53,27 @@ public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
4853

4954
@SubscribeEvent
5055
public void onValidationErrorLog(ConfigValidationFailureEvent e) {
51-
if (LibraryConfig.CONFIG_ERROR_LOGGING != LibraryConfig.ValidationLogging.None) {
56+
if (ConfigEngineConfig.CONFIG_ERROR_LOGGING != ConfigEngineConfig.LoggingLevel.None) {
5257
e.logWarn();
5358
}
5459
}
60+
61+
@SubscribeEvent
62+
public void onConfigSyncFinished(ConfigSyncEvent.End e) {
63+
if (e.successful) {
64+
if (ConfigEngineConfig.CONFIG_SYNC_SUCCESS_LOGGING != ConfigEngineConfig.LoggingLevel.None) {
65+
val cfg = e.configClass.getAnnotation(Config.class);
66+
FPLog.LOG.info("Synced config: {}:{}", cfg.modid(), cfg.category());
67+
}
68+
} else {
69+
if (ConfigEngineConfig.CONFIG_SYNC_FAILURE_LOGGING != ConfigEngineConfig.LoggingLevel.None) {
70+
val cfg = e.configClass.getAnnotation(Config.class);
71+
FPLog.LOG.error("Failed to sync config: {}:{}", cfg.modid(), cfg.category());
72+
val t = e.error;
73+
if (t != null) {
74+
FPLog.LOG.error(t.getMessage(), t);
75+
}
76+
}
77+
}
78+
}
5579
}

src/main/resources/assets/falsepatternlib/lang/en_US.lang

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
config.falsepatternlib.misc=Miscellaneous
22
config.falsepatternlib.misc.tooltip=Settings that don't fit into other categories
3-
config.falsepatternlib.misc.configErrorLogging=Config error logging
4-
config.falsepatternlib.misc.configErrorLogging.tooltip=How the config error logging should be set up.\n[None] disables all built-in config validation error logging.
53
config.falsepatternlib.misc.inGameModOptionsFix=In-Game Mod Options Fix
64
config.falsepatternlib.misc.inGameModOptionsFix.tooltip=Fixes the mod options menu in-game.
75

@@ -13,3 +11,12 @@ config.falsepatternlib.toasts.yOffset=Toast Y Offset
1311
config.falsepatternlib.toasts.yOffset.tooltip=The amount of empty space from the top of the screen in pixels.
1412
config.falsepatternlib.toasts.align=Toast Alignment
1513
config.falsepatternlib.toasts.align.tooltip=Which side of the screen should toasts show up on.
14+
15+
config.falsepatternlib.config_engine=Configuration Engine
16+
config.falsepatternlib.config_engine.tooltip=Settings for the FPLib config system (also used by other mods)
17+
config.falsepatternlib.config_engine.configErrorLogging=Config error logging
18+
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.
19+
config.falsepatternlib.config_engine.configSyncSuccessLogging=Config sync success logging
20+
config.falsepatternlib.config_engine.configSyncSuccessLogging.tooltip=How successful config synchronizations should be logged.
21+
config.falsepatternlib.config_engine.configSyncFailureLogging=Config sync failure logging
22+
config.falsepatternlib.config_engine.configSyncFailureLogging.tooltip=How failed config synchronizations should be logged.

0 commit comments

Comments
 (0)