Skip to content

Commit 86c1719

Browse files
author
Julien Poulton
committed
Merge branch '5376-sdkmodule-adding-options-to-replace-the-text-of-the-score-by-a-string' into 'master'
[SDK][endscreen] adding options to display a custom text instead of the score See merge request codingame/game-engine!175
2 parents 3503669 + e35751a commit 86c1719

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

engine/modules/endscreen/src/main/java/com/codingame/gameengine/module/endscreen/EndScreenModule.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class EndScreenModule implements Module {
1515

1616
private GameManager<AbstractPlayer> gameManager;
1717
private int[] scores;
18+
private String[] displayedText;
1819
private String titleRankingsSprite = "logo.png";
1920

2021
@Inject
@@ -33,6 +34,20 @@ public void setScores(int[] scores) {
3334
this.scores = scores;
3435
}
3536

37+
/**
38+
* Send scores to the module
39+
*
40+
* @param scores
41+
* the scores of the different players, the index matches the player.getIndex()
42+
* @param displayedText
43+
* the text displayed instead of the score of a player, if null or empty string for a player the score will still be displayed
44+
*
45+
*/
46+
public void setScores(int[] scores, String[] displayedText) {
47+
this.scores = scores;
48+
this.displayedText = displayedText;
49+
}
50+
3651
/**
3752
* Allows you to set the sprite used as the title of the ranking board
3853
*
@@ -61,7 +76,7 @@ public final void onAfterGameTurn() {
6176

6277
@Override
6378
public final void onAfterOnEnd() {
64-
Object[] data = { scores, titleRankingsSprite };
79+
Object[] data = { scores, titleRankingsSprite, displayedText };
6580
gameManager.setViewData("endScreen", data);
6681
}
6782

engine/modules/endscreen/src/main/resources/view/endscreen-module/EndScreenModule.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,27 @@ export class EndScreenModule {
2828
handleFrameData (frameInfo, data) {
2929
let scores = null
3030
let spriteName = null
31+
let displayedText = null
3132
if (data) {
3233
scores = data[0]
3334
spriteName = data[1]
35+
displayedText = data[2]
3436
}
3537
const state = {
3638
number: frameInfo.number,
3739
scores,
38-
spriteName
40+
spriteName,
41+
displayedText
3942
}
4043
if (scores) {
4144
this.scores = scores
4245
}
4346
if (spriteName) {
4447
this.spriteName = spriteName
4548
}
49+
if (displayedText) {
50+
this.displayedText = displayedText
51+
}
4652
this.states.push(state)
4753
return state
4854
}
@@ -176,7 +182,9 @@ export class EndScreenModule {
176182
avatarContainer.addChild(hudAvatar)
177183

178184
var name = this.generateText(finisher.player.name.toUpperCase(), 50, 'left', finisher.player.color)
179-
var scoreLabel = this.generateText(((finisher.score >= 0) ? finisher.score.toString() + ' points' : '-'), 64, 'left', finisher.player.color)
185+
186+
const scoreText = finisher.text || ((finisher.score >= 0) ? finisher.score.toString() + ' points' : '-')
187+
var scoreLabel = this.generateText(scoreText, 64, 'left', finisher.player.color)
180188

181189
name.x = 330
182190
name.y = -4
@@ -218,6 +226,7 @@ export class EndScreenModule {
218226
for (var i = 0; i < this.globalData.playerCount; ++i) {
219227
podium.push({
220228
score: this.scores[i],
229+
text: (this.displayedText) ? this.displayedText[i] : null,
221230
player: this.globalData.players[i],
222231
rank: 0
223232
})

playground/extensions/extensions-4-endscreen.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,24 @@ To guarantee the correct ranking, you must set this module's score property in y
3333
```java
3434
@Override
3535
public void onEnd() {
36-
endScreenModule.setScores(gameManager.getPlayers().stream().mapToInt(p -> p.getScore()).toArray());
36+
endScreenModule.setScores(gameManager.getPlayers().stream().mapToInt(p -> p.getScore()).toArray());
3737
}
3838
```
3939

4040
The module loads by default your `logo.png` as title, you can set your own image with `setTitleRankingsSprite()`.
4141
```java
4242
endScreenModule.setTitleRankingsSprite("myCustomSprite.png");
4343
```
44+
45+
You can also display a custom text instead of the score.
46+
47+
`Referee.java`
48+
```java
49+
@Override
50+
public void onEnd() {
51+
int[] scores = { player1.getScore(), player2.getScore() };
52+
String[] text = { scores[0] + " mana", scores[1] + " mana" };
53+
54+
endScreenModule.setScores(scores, text);
55+
}
56+
```

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
The CodinGame SDK is regularly updated and improved. This document lets you know what changed in the latest releases.
44

5+
## Next release
6+
7+
### 🎁 New feature
8+
9+
- The [EndScreenModule](playground/extensions/extensions-4-endscreen.md) allows you to display a custom text instead of the score.
10+
511
## 3.2.0
612

713
### 🎁 New features

0 commit comments

Comments
 (0)