Skip to content

Commit 4e4f502

Browse files
committed
fix(sdk): statement preview now checks for statement_en.html.tpl too
1 parent dcead32 commit 4e4f502

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

playground/misc/misc-3-release-notes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ The CodinGame SDK is regularly updated and improved. This document lets you know
66

77
### 🐞 Bug fix
88

9-
- The statement preview page now presents HTML as it would show in the CodinGame IDE
9+
- The statement preview page now presents HTML as it would show in the CodinGame IDE.
10+
- The statement preview page now looks for both `.html` and `.html.tpl` files.
1011
- Fixed `ToggleModule` taking up a lot of characters in the game result from the allowed quota.
1112

13+
1214
## 3.15.2
1315

1416
### 🐞 Bug fix

runner/src/main/java/com/codingame/gameengine/runner/Renderer.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -440,18 +440,22 @@ private void checkUniqueOpti(GameConfig gameConfig, ExportReport exportReport) {
440440
}
441441

442442
private void checkLeaguePopups(QuestionConfig questionConfig, String tag, ExportReport exportReport) {
443-
if (!questionConfig.getWelcomeLanguageMap().containsKey(Constants.LANGUAGE_ID_ENGLISH)
444-
|| questionConfig.getWelcomeLanguageMap().get(Constants.LANGUAGE_ID_ENGLISH).isEmpty()) {
443+
if (
444+
!questionConfig.getWelcomeLanguageMap().containsKey(Constants.LANGUAGE_ID_ENGLISH)
445+
|| questionConfig.getWelcomeLanguageMap().get(Constants.LANGUAGE_ID_ENGLISH).isEmpty()
446+
) {
445447
exportReport.addItem(
446448
ReportItemType.WARNING, tag + "Missing welcome_"
447449
+ Constants.LANGUAGE_CODE[Constants.LANGUAGE_ID_ENGLISH - 1] + ".html file."
448450
);
449451
} else {
450452
for (int languageId : questionConfig.getWelcomeLanguageMap().keySet()) {
451453
//Avoid checking the same popup twice if duplicated
452-
if (languageId != Constants.LANGUAGE_ID_ENGLISH
453-
&& questionConfig.getWelcomeLanguageMap().get(languageId)
454-
.equals(questionConfig.getWelcomeLanguageMap().get(Constants.LANGUAGE_ID_ENGLISH))) {
454+
if (
455+
languageId != Constants.LANGUAGE_ID_ENGLISH
456+
&& questionConfig.getWelcomeLanguageMap().get(languageId)
457+
.equals(questionConfig.getWelcomeLanguageMap().get(Constants.LANGUAGE_ID_ENGLISH))
458+
) {
455459
continue;
456460
}
457461

@@ -485,8 +489,10 @@ private void checkBoss(QuestionConfig questionConfig, String tag, ExportReport e
485489
}
486490

487491
private void checkStatement(QuestionConfig questionConfig, String tag, ExportReport exportReport) {
488-
if (!questionConfig.getStatementsLanguageMap().containsKey(Constants.LANGUAGE_ID_ENGLISH)
489-
|| questionConfig.getStatementsLanguageMap().get(Constants.LANGUAGE_ID_ENGLISH).isEmpty()) {
492+
if (
493+
!questionConfig.getStatementsLanguageMap().containsKey(Constants.LANGUAGE_ID_ENGLISH)
494+
|| questionConfig.getStatementsLanguageMap().get(Constants.LANGUAGE_ID_ENGLISH).isEmpty()
495+
) {
490496
exportReport.addItem(ReportItemType.ERROR, tag + "Missing statement_en.html file. An English statement is mandatory.");
491497
}
492498
}
@@ -536,10 +542,12 @@ private void checkQuestionsTypeValidity(GameConfig gameConfig, QuestionConfig qu
536542
}
537543
if (questionConfig.getSortingOrder() == null) {
538544
throw new MissingConfigException("An optimization game must have a sorting_order property in config.ini.");
539-
} else if (!"ASC".equalsIgnoreCase(questionConfig.getSortingOrder())
540-
&& !"DESC".equalsIgnoreCase(questionConfig.getSortingOrder())) {
541-
throw new MissingConfigException("The sorting order for an optimization game must be ASC (ascendant) or DESC (descendant)");
542-
}
545+
} else if (
546+
!"ASC".equalsIgnoreCase(questionConfig.getSortingOrder())
547+
&& !"DESC".equalsIgnoreCase(questionConfig.getSortingOrder())
548+
) {
549+
throw new MissingConfigException("The sorting order for an optimization game must be ASC (ascendant) or DESC (descendant)");
550+
}
543551
}
544552

545553
switch (gameConfig.getGameType()) {
@@ -735,8 +743,9 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
735743
}
736744
}, StandardCharsets.UTF_8);
737745
} else if (exchange.getRelativePath().equals("/statement")) {
738-
File statementFileEN = sourceFolderPath.resolve("config/statement_en.html").toFile();
739-
File statementFileFR = sourceFolderPath.resolve("config/statement_fr.html").toFile();
746+
File statementFileEN = getStatementFile(sourceFolderPath, "en");
747+
File statementFileFR = getStatementFile(sourceFolderPath, "fr");
748+
740749
if (exchange.getRequestMethod().equalToString("GET")) {
741750
JsonObject statements = new JsonObject();
742751
String statementEN = FileUtils.readFileToString(statementFileEN, StandardCharsets.UTF_8);
@@ -784,6 +793,15 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
784793
}
785794
}
786795

796+
private File getStatementFile(Path sourceFolderPath, String langId) {
797+
File file = sourceFolderPath.resolve("config/statement_" + langId + ".html").toFile();
798+
if (!file.exists()) {
799+
file = sourceFolderPath.resolve("config/statement_" + langId + ".html.tpl").toFile();
800+
}
801+
return file;
802+
803+
}
804+
787805
private JsonElement toJsonElement(String statementFR) {
788806
return Optional.ofNullable(statementFR)
789807
.map(s -> (JsonElement) new JsonPrimitive(s))

0 commit comments

Comments
 (0)