Skip to content

Commit

Permalink
reverse refactoring of magic numbers - in case that constants in code…
Browse files Browse the repository at this point in the history
… is locally understandable what it is used about, without any additional explanations about it (like MIN_SIZE, etc...)
  • Loading branch information
b0r1ngx committed Mar 21, 2024
1 parent 069a93b commit 21882f6
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import com.arkivanov.decompose.value.update
import com.arkivanov.minesweeper.game.GameSettings
import com.arkivanov.minesweeper.settings.EditSettingsComponent.Model

private const val MIN_SIZE = 2
private const val MAX_WIDTH = 100
private const val MAX_HEIGHT = 50

internal class DefaultEditSettingsComponent(
settings: GameSettings,
private val onConfirmed: (GameSettings) -> Unit,
Expand Down Expand Up @@ -44,9 +40,9 @@ internal class DefaultEditSettingsComponent(
val height = _model.value.height.toIntOrNull() ?: return
val maxMines = _model.value.maxMines.toIntOrNull() ?: return

val finalWidth = width.coerceIn(MIN_SIZE..MAX_WIDTH)
val finalHeight = height.coerceIn(MIN_SIZE..MAX_HEIGHT)
val finalMines = maxMines.coerceIn(1 until finalWidth * finalHeight - 1)
val finalWidth = width.coerceIn(2..100)
val finalHeight = height.coerceIn(2..50)
val finalMines = maxMines.coerceIn(1 until finalWidth * finalHeight)

onConfirmed(GameSettings(width = finalWidth, height = finalHeight, maxMines = finalMines))
}
Expand Down

0 comments on commit 21882f6

Please sign in to comment.