Skip to content

Commit b82e3ac

Browse files
committed
chore: cleanup some erro handling and gui state (avoids #10)
1 parent 8965fae commit b82e3ac

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

common/src/main/java/io/github/thebossmagnus/mods/config_manager/common/AddFlagsUtil.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,26 @@ public class AddFlagsUtil {
1010
private static final AtomicBoolean OVERWRITE_FLAG = new AtomicBoolean(false);
1111

1212

13-
public static void setUpdateFlag(boolean updateFlag) {
13+
public static void setUpdateFlag(boolean updateFlag) throws RuntimeException {
1414
UPDATE_FLAG.set(updateFlag);
1515
addFlags();
1616
}
1717

1818

19-
public static void setOverwriteFlag(boolean overwriteFlag) {
19+
public static void setOverwriteFlag(boolean overwriteFlag) throws RuntimeException {
2020
OVERWRITE_FLAG.set(overwriteFlag);
2121
addFlags();
2222
}
2323

2424
private static void addFlags() throws RuntimeException {
25-
Path gameDir = Services.PLATFORM.getGameDir();
26-
Path configDir = gameDir.resolve("config");
25+
Path configDir;
26+
try {
27+
Path gameDir = Services.PLATFORM.getGameDir();
28+
configDir = gameDir.resolve("config");
29+
} catch (Exception e) {
30+
Constants.LOGGER.error("Error while resolving path", e);
31+
throw new RuntimeException("Error while resolving path: " + e.getMessage(), e);
32+
}
2733
try {
2834
if (!Files.exists(configDir)) {
2935
Files.createDirectories(configDir);

common/src/main/java/io/github/thebossmagnus/mods/config_manager/common/screen/Gui.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ public class Gui extends Screen {
1616
private static final int COLOR_RED = 0xFF0000;
1717
private static final int COLOR_WHITE = 0xFFFFFF;
1818
private final Screen parent;
19-
private final Component updateWarnings = Component.translatable("* %s\n* %s",
19+
private final Component updateWarnings = Component.translatable("* %s\n" +
20+
"* %s",
2021
Component.translatable("config_manager.warning.lose_some_config"),
2122
Component.translatable("config_manager.warning.game_restart")
2223
);
23-
private final Component resetWarnings = Component.translatable("* %s\n* %s",
24+
private final Component resetWarnings = Component.translatable("* %s\n" +
25+
"* %s",
2426
Component.translatable("config_manager.warning.lose_all_config"),
2527
Component.translatable("config_manager.warning.game_restart")
2628
);
@@ -35,23 +37,21 @@ public Gui(Screen screen) {
3537
}
3638

3739
private Button createConfigButton(Component label, Runnable flagSetter) {
38-
// Use a local mutable state for each button
3940
final boolean[] isFirstClick = {true};
4041
return Button.builder(label, (btn) -> {
4142
if (isFirstClick[0]) {
4243
btn.setMessage(Component.translatable("config_manager.confirmation").withStyle(style -> style.withColor(COLOR_RED)));
4344
isFirstClick[0] = false;
4445
} else {
4546
try {
46-
btn.active = false;
4747
flagSetter.run();
48+
Constants.LOGGER.info("Flag Added, it will be processed on the next game boot");
4849
btn.setMessage(Component.translatable("config_manager.success").withStyle(style -> style.withColor(COLOR_WHITE)));
49-
Constants.LOGGER.info("Flag Added");
50-
} catch (Exception e) {
50+
} catch (Throwable e) {
5151
Constants.LOGGER.error("Failed to add flag", e);
5252
btn.setMessage(Component.translatable("config_manager.error").withStyle(style -> style.withColor(COLOR_RED)));
53-
btn.active = false;
5453
}
54+
btn.active = false;
5555
}
5656
})
5757
.size(buttonWidth, buttonHeight)

0 commit comments

Comments
 (0)