Skip to content

Commit 9660e21

Browse files
committed
New proposal of errors
1 parent 67bb985 commit 9660e21

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

core/src/bms/player/beatoraja/MainController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ public void create() {
552552
});
553553
irResendProcess.start();
554554
}
555-
ImGuiNotify.info(getI18nMessage(TEST.WELCOME, "Endless Dream"));
555+
ImGuiNotify.error(getI18nError(TEST.TEST_ERROR));
556+
logger.error(getI18nError(TEST.TEST_ERROR));
556557

557558
lastConfigSave = System.nanoTime();
558559
}

core/src/bms/player/beatoraja/config/I18nMessage.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@
1313
public class I18nMessage {
1414
private static ResourceBundle bundle;
1515

16-
public static class TEST {
17-
public static final String WELCOME = "TEST_WELCOME";
18-
}
19-
2016
public static class IR {
2117
public static final String IR_SEND_SCORE_SUCCESS = "IR_SEND_SCORE_SUCCESS";
2218
public static final String IR_SEND_SCORE_FAILED = "IR_SEND_SCORE_FAILED";
2319
}
2420

21+
public static class TEST {
22+
public static final String TEST_ERROR = "TEST_ERROR";
23+
}
24+
25+
/**
26+
* For creating an error code automatically, all error messages should be registered here with their full-name
27+
*/
28+
private enum ErrorMessage {
29+
IR_SEND_SCORE_FAILED,
30+
TEST_ERROR;
31+
}
32+
2533
/**
2634
* An explicit function that allows you set a bundle manually
2735
*
@@ -42,4 +50,16 @@ public static String getI18nMessage(String key) {
4250
public static String getI18nMessage(String key, Object... args) {
4351
return MessageFormat.format(getI18nMessage(key), args);
4452
}
53+
54+
public static String getI18nError(String key, Object... args) {
55+
try {
56+
ErrorMessage errorMessage = ErrorMessage.valueOf(key);
57+
// Error code starts from 1 (we don't want a code like 0000)
58+
int errorCode = errorMessage.ordinal() + 1;
59+
String originalMessage = getI18nMessage(key, args);
60+
return String.format("[%04d]", errorCode) + originalMessage;
61+
} catch (IllegalArgumentException e) {
62+
throw new RuntimeException(e);
63+
}
64+
}
4565
}

core/src/resources/UIResources.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,4 @@ PROGRESS_TABLE_LABEL=Loading Table Info. Please wait warmly...
183183
PROGRESS_TABLE_TITLE=Loading Table Info
184184
MARK_AS_DOWNLOAD_DIRECTORY=Set DL Directory
185185
MARK_AS_DOWNLOAD_DIRECTORY_HINT=Mark this directory as download directory
186-
TEST_WELCOME=Welcome to {0}
186+
TEST_ERROR=I'm an error for test

0 commit comments

Comments
 (0)