Commit e552a63f authored by Lars Mitsem Selbekk's avatar Lars Mitsem Selbekk
Browse files

Merge branch 'i71/show-yourself-leaderboard' into 'master'

Always show your score and place on leaderboard

See merge request !64
parents 794dc3d2 27f00240
Pipeline #175847 canceled with stages
in 3 seconds
android/assets/tutorial/leaderboard.jpg

1010 KB | W: | H:

android/assets/tutorial/leaderboard.jpg

1.03 MB | W: | H:

android/assets/tutorial/leaderboard.jpg
android/assets/tutorial/leaderboard.jpg
android/assets/tutorial/leaderboard.jpg
android/assets/tutorial/leaderboard.jpg
  • 2-up
  • Swipe
  • Onion skin
......@@ -17,17 +17,41 @@ class LeaderboardState : GameState() {
stage
)
private var userId: String? = null
private var leaderboard: List<LeaderboardEntry> = listOf()
private val leaderboardText: String
get() {
return leaderboard.take(LEADERBOARD_SIZE).joinToString("\n") { entry ->
"${(entry.username ?: UNKNOWN_USERNAME)}: ${entry.score}"
private fun getUserScoreText(): String {
if (userId != null) {
val place = leaderboard.indexOfFirst { it.userId == userId }
if (place == -1) {
MultiplayerService.incrementScore(0) {
updateLeaderboard()
}
return ""
}
val score = leaderboard[place].score
return "\n\nYou (no. ${place + 1}): $score"
}
return ""
}
private fun getLeaderboardText(): String {
return leaderboard.take(LEADERBOARD_SIZE).joinToString("\n") { entry ->
"${(entry.username ?: UNKNOWN_USERNAME)}: ${entry.score}"
}
}
init {
updateLeaderboard()
MultiplayerService.getUserID {
userId = it
updateText()
}
}
private fun updateText() {
leaderboardView.setLeaderboardText(getLeaderboardText() + getUserScoreText())
}
private fun goBack() {
......@@ -38,7 +62,7 @@ class LeaderboardState : GameState() {
MultiplayerService.getLeaderboard {
it?.let {
leaderboard = it
leaderboardView.setLeaderboardText(leaderboardText)
updateText()
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment