Skip to content

Commit

Permalink
Merge branch 'feature/DRAW-220' into sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
comforest committed Aug 14, 2024
2 parents 1c0ac6f + 81fe0d6 commit 560c425
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ internal class MafiaGameRoomService(
}

private fun generateColor(gameInfo: MafiaGameInfo?): String {
if (gameInfo == null) return COLOR_LIST.first()

val alreadyUsedColors =
gameInfo.room.players.map { it.color }.toList()
val alreadyUsedColors = gameInfo?.room?.players?.map { it.color }?.toList() ?: emptyList()

return COLOR_LIST
.filterNot { alreadyUsedColors.contains(it) }
Expand Down
29 changes: 21 additions & 8 deletions domain/src/main/kotlin/com/xorker/draw/mafia/MafiaPhase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,32 @@ sealed class MafiaPhase {
}

fun getDraw(): List<Map<String, Any>> {
return if (drawData.isEmpty()) {
emptyList()
} else {
drawData.take(drawData.size - 1).map { it.second }
if (drawData.isEmpty()) {
return emptyList()
}

val currentUser = turnList[turnInfo.turn]

if (drawData.last().first == currentUser.userId) {
return drawData.take(drawData.size - 1).map { it.second }
}

return drawData.map { it.second }
}

fun getCurrentDraw(): Map<String, Any> {
return if (drawData.isEmpty()) {
emptyMap()
} else {
drawData.last().second
if (drawData.isEmpty()) {
return emptyMap()
}

val currentUser = turnList[turnInfo.turn]

val last = drawData.last()
if (last.first == currentUser.userId) {
return last.second
}

return emptyMap()
}
}

Expand Down

0 comments on commit 560c425

Please sign in to comment.