Renamed DifficultyPreset to Difficulty only
This commit is contained in:
parent
63e6750b0f
commit
5bd72333dd
12 changed files with 61 additions and 61 deletions
|
@ -246,10 +246,10 @@ class GameActivity : DaggerAppCompatActivity() {
|
|||
var handled = true
|
||||
|
||||
when (item.itemId) {
|
||||
R.id.standard -> changeDifficulty(DifficultyPreset.Standard)
|
||||
R.id.beginner -> changeDifficulty(DifficultyPreset.Beginner)
|
||||
R.id.intermediate -> changeDifficulty(DifficultyPreset.Intermediate)
|
||||
R.id.expert -> changeDifficulty(DifficultyPreset.Expert)
|
||||
R.id.standard -> changeDifficulty(Difficulty.Standard)
|
||||
R.id.beginner -> changeDifficulty(Difficulty.Beginner)
|
||||
R.id.intermediate -> changeDifficulty(Difficulty.Intermediate)
|
||||
R.id.expert -> changeDifficulty(Difficulty.Expert)
|
||||
R.id.custom -> showCustomLevelDialog()
|
||||
R.id.about -> showAbout()
|
||||
R.id.settings -> showSettings()
|
||||
|
@ -286,14 +286,14 @@ class GameActivity : DaggerAppCompatActivity() {
|
|||
preferencesRepository.putInt(PREFERENCE_USE_COUNT, current + 1)
|
||||
}
|
||||
|
||||
private fun onChangeDifficulty(difficulty: DifficultyPreset) {
|
||||
private fun onChangeDifficulty(difficulty: Difficulty) {
|
||||
navigationView.menu.apply {
|
||||
arrayOf(
|
||||
DifficultyPreset.Standard to findItem(R.id.standard),
|
||||
DifficultyPreset.Beginner to findItem(R.id.beginner),
|
||||
DifficultyPreset.Intermediate to findItem(R.id.intermediate),
|
||||
DifficultyPreset.Expert to findItem(R.id.expert),
|
||||
DifficultyPreset.Custom to findItem(R.id.custom)
|
||||
Difficulty.Standard to findItem(R.id.standard),
|
||||
Difficulty.Beginner to findItem(R.id.beginner),
|
||||
Difficulty.Intermediate to findItem(R.id.intermediate),
|
||||
Difficulty.Expert to findItem(R.id.expert),
|
||||
Difficulty.Custom to findItem(R.id.custom)
|
||||
).map {
|
||||
it.second to (if (it.first == difficulty) R.drawable.checked else R.drawable.unchecked)
|
||||
}.forEach { (menuItem, icon) ->
|
||||
|
@ -407,7 +407,7 @@ class GameActivity : DaggerAppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun changeDifficulty(newDifficulty: DifficultyPreset) {
|
||||
private fun changeDifficulty(newDifficulty: Difficulty) {
|
||||
if (status == Status.PreGame) {
|
||||
GlobalScope.launch {
|
||||
viewModel.startNewGame(newDifficulty)
|
||||
|
|
|
@ -250,7 +250,7 @@ class TvGameActivity : DaggerAppCompatActivity() {
|
|||
}, null, DateUtils.SECOND_IN_MILLIS)
|
||||
}
|
||||
|
||||
private fun changeDifficulty(newDifficulty: DifficultyPreset) {
|
||||
private fun changeDifficulty(newDifficulty: Difficulty) {
|
||||
if (status == Status.PreGame) {
|
||||
GlobalScope.launch {
|
||||
viewModel.startNewGame(newDifficulty)
|
||||
|
|
|
@ -8,7 +8,7 @@ import androidx.lifecycle.ViewModelProviders
|
|||
|
||||
import dagger.android.support.DaggerAppCompatDialogFragment
|
||||
import dev.lucasnlm.antimine.R
|
||||
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
|
||||
import dev.lucasnlm.antimine.common.level.models.Difficulty
|
||||
import dev.lucasnlm.antimine.common.level.models.Minefield
|
||||
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
|
||||
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory
|
||||
|
@ -80,7 +80,7 @@ class CustomLevelDialogFragment : DaggerAppCompatDialogFragment() {
|
|||
)
|
||||
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
viewModel.startNewGame(DifficultyPreset.Custom)
|
||||
viewModel.startNewGame(Difficulty.Custom)
|
||||
}
|
||||
}
|
||||
}.create()
|
||||
|
|
|
@ -11,7 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import dev.lucasnlm.antimine.common.R
|
||||
import dev.lucasnlm.antimine.common.level.view.UnlockedHorizontalScrollView
|
||||
import dagger.android.support.DaggerFragment
|
||||
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
|
||||
import dev.lucasnlm.antimine.common.level.models.Difficulty
|
||||
import dev.lucasnlm.antimine.common.level.models.Event
|
||||
import dev.lucasnlm.antimine.common.level.view.AreaAdapter
|
||||
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
|
||||
|
@ -110,16 +110,16 @@ open class LevelFragment : DaggerFragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleNewGameDeeplink(): DifficultyPreset? {
|
||||
var result: DifficultyPreset? = null
|
||||
private fun handleNewGameDeeplink(): Difficulty? {
|
||||
var result: Difficulty? = null
|
||||
|
||||
activity?.intent?.data?.let { uri ->
|
||||
if (uri.scheme == DEFAULT_SCHEME) {
|
||||
result = when (uri.schemeSpecificPart.removePrefix("//new-game/")) {
|
||||
"beginner" -> DifficultyPreset.Beginner
|
||||
"intermediate" -> DifficultyPreset.Intermediate
|
||||
"expert" -> DifficultyPreset.Expert
|
||||
"standard" -> DifficultyPreset.Standard
|
||||
"beginner" -> Difficulty.Beginner
|
||||
"intermediate" -> Difficulty.Intermediate
|
||||
"expert" -> Difficulty.Expert
|
||||
"standard" -> Difficulty.Standard
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
package dev.lucasnlm.antimine.common.level
|
||||
|
||||
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
|
||||
import dev.lucasnlm.antimine.common.level.models.Difficulty
|
||||
import dev.lucasnlm.antimine.common.level.models.Minefield
|
||||
import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
|
||||
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
|
||||
|
||||
object GameModeFactory {
|
||||
fun fromDifficultyPreset(
|
||||
difficulty: DifficultyPreset,
|
||||
difficulty: Difficulty,
|
||||
dimensionRepository: IDimensionRepository,
|
||||
preferencesRepository: IPreferencesRepository
|
||||
): Minefield =
|
||||
when (difficulty) {
|
||||
DifficultyPreset.Standard -> calculateStandardMode(dimensionRepository)
|
||||
DifficultyPreset.Beginner -> Minefield(
|
||||
Difficulty.Standard -> calculateStandardMode(dimensionRepository)
|
||||
Difficulty.Beginner -> Minefield(
|
||||
9,
|
||||
9,
|
||||
10
|
||||
)
|
||||
DifficultyPreset.Intermediate -> Minefield(
|
||||
Difficulty.Intermediate -> Minefield(
|
||||
16,
|
||||
16,
|
||||
40
|
||||
)
|
||||
DifficultyPreset.Expert -> Minefield(
|
||||
Difficulty.Expert -> Minefield(
|
||||
24,
|
||||
24,
|
||||
99
|
||||
)
|
||||
DifficultyPreset.Custom -> preferencesRepository.customGameMode()
|
||||
Difficulty.Custom -> preferencesRepository.customGameMode()
|
||||
}
|
||||
|
||||
private fun calculateStandardMode(
|
||||
|
|
|
@ -248,7 +248,7 @@ class LevelFacade {
|
|||
(it.posX == this.posX + x) && (it.posY == this.posY + y)
|
||||
}
|
||||
|
||||
fun getSaveState(duration: Long, difficulty: DifficultyPreset): Save {
|
||||
fun getSaveState(duration: Long, difficulty: Difficulty): Save {
|
||||
val saveStatus: SaveStatus = when {
|
||||
checkVictory() -> SaveStatus.VICTORY
|
||||
hasAnyMineExploded() -> SaveStatus.DEFEAT
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
package dev.lucasnlm.antimine.common.level.database.converters
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
|
||||
import dev.lucasnlm.antimine.common.level.models.Difficulty
|
||||
|
||||
class DifficultyConverter {
|
||||
|
||||
@TypeConverter
|
||||
fun toDifficulty(difficulty: Int): DifficultyPreset =
|
||||
fun toDifficulty(difficulty: Int): Difficulty =
|
||||
when (difficulty) {
|
||||
0 -> DifficultyPreset.Standard
|
||||
1 -> DifficultyPreset.Beginner
|
||||
2 -> DifficultyPreset.Intermediate
|
||||
3 -> DifficultyPreset.Expert
|
||||
0 -> Difficulty.Standard
|
||||
1 -> Difficulty.Beginner
|
||||
2 -> Difficulty.Intermediate
|
||||
3 -> Difficulty.Expert
|
||||
else -> throw IllegalArgumentException("Could not recognize Difficulty")
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toInteger(difficulty: DifficultyPreset): Int = difficulty.ordinal
|
||||
fun toInteger(difficulty: Difficulty): Int = difficulty.ordinal
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import androidx.room.Entity
|
|||
import androidx.room.PrimaryKey
|
||||
import androidx.room.TypeConverters
|
||||
import dev.lucasnlm.antimine.common.level.models.Area
|
||||
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
|
||||
import dev.lucasnlm.antimine.common.level.models.Difficulty
|
||||
import dev.lucasnlm.antimine.common.level.models.Minefield
|
||||
import dev.lucasnlm.antimine.common.level.database.converters.FieldConverter
|
||||
import dev.lucasnlm.antimine.common.level.database.converters.SaveStatusConverter
|
||||
|
@ -28,7 +28,7 @@ data class Save(
|
|||
val minefield: Minefield,
|
||||
|
||||
@ColumnInfo(name = "difficulty")
|
||||
val difficulty: DifficultyPreset,
|
||||
val difficulty: Difficulty,
|
||||
|
||||
@TypeConverters(SaveStatusConverter::class)
|
||||
@ColumnInfo(name = "status")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package dev.lucasnlm.antimine.common.level.models
|
||||
|
||||
enum class DifficultyPreset(
|
||||
enum class Difficulty(
|
||||
val text: String
|
||||
) {
|
||||
Standard("STANDARD"),
|
|
@ -6,7 +6,7 @@ import androidx.lifecycle.ViewModel
|
|||
import dev.lucasnlm.antimine.common.level.GameModeFactory
|
||||
import dev.lucasnlm.antimine.common.level.LevelFacade
|
||||
import dev.lucasnlm.antimine.common.level.models.Area
|
||||
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
|
||||
import dev.lucasnlm.antimine.common.level.models.Difficulty
|
||||
import dev.lucasnlm.antimine.common.level.models.Event
|
||||
import dev.lucasnlm.antimine.common.level.models.Minefield
|
||||
import dev.lucasnlm.antimine.common.level.database.models.Save
|
||||
|
@ -33,35 +33,35 @@ class GameViewModel(
|
|||
private val clock: Clock
|
||||
) : ViewModel() {
|
||||
private lateinit var levelFacade: LevelFacade
|
||||
private var currentDifficulty: DifficultyPreset = DifficultyPreset.Standard
|
||||
private var currentDifficulty: Difficulty = Difficulty.Standard
|
||||
private var initialized = false
|
||||
|
||||
val field = MutableLiveData<List<Area>>()
|
||||
val fieldRefresh = MutableLiveData<Int>()
|
||||
val elapsedTimeSeconds = MutableLiveData<Long>()
|
||||
val mineCount = MutableLiveData<Int>()
|
||||
val difficulty = MutableLiveData<DifficultyPreset>()
|
||||
val difficulty = MutableLiveData<Difficulty>()
|
||||
val levelSetup = MutableLiveData<Minefield>()
|
||||
|
||||
private fun startNewGame(gameId: Int, difficultyPreset: DifficultyPreset): Minefield {
|
||||
private fun startNewGame(gameId: Int, difficulty: Difficulty): Minefield {
|
||||
clock.reset()
|
||||
elapsedTimeSeconds.postValue(0L)
|
||||
currentDifficulty = difficultyPreset
|
||||
currentDifficulty = difficulty
|
||||
|
||||
val setup = GameModeFactory.fromDifficultyPreset(
|
||||
difficultyPreset, dimensionRepository, preferencesRepository
|
||||
difficulty, dimensionRepository, preferencesRepository
|
||||
)
|
||||
|
||||
levelFacade = LevelFacade(gameId, setup)
|
||||
|
||||
mineCount.postValue(setup.mines)
|
||||
difficulty.postValue(difficultyPreset)
|
||||
this.difficulty.postValue(difficulty)
|
||||
levelSetup.postValue(setup)
|
||||
field.postValue(levelFacade.field.toList())
|
||||
|
||||
eventObserver.postValue(Event.StartNewGame)
|
||||
|
||||
analyticsManager.sentEvent(Analytics.NewGame(setup, difficultyPreset, levelFacade.seed, useAccessibilityMode()))
|
||||
analyticsManager.sentEvent(Analytics.NewGame(setup, difficulty, levelFacade.seed, useAccessibilityMode()))
|
||||
|
||||
return setup
|
||||
}
|
||||
|
@ -88,13 +88,13 @@ class GameViewModel(
|
|||
return setup
|
||||
}
|
||||
|
||||
suspend fun startNewGame(difficultyPreset: DifficultyPreset = currentDifficulty): Minefield =
|
||||
suspend fun startNewGame(difficulty: Difficulty = currentDifficulty): Minefield =
|
||||
withContext(Dispatchers.IO) {
|
||||
val newGameId = savesRepository.getNewSaveId()
|
||||
startNewGame(newGameId, difficultyPreset)
|
||||
startNewGame(newGameId, difficulty)
|
||||
}
|
||||
|
||||
suspend fun onCreate(newGame: DifficultyPreset? = null): Minefield = withContext(Dispatchers.IO) {
|
||||
suspend fun onCreate(newGame: Difficulty? = null): Minefield = withContext(Dispatchers.IO) {
|
||||
val lastGame = if (newGame == null) savesRepository.fetchCurrentSave() else null
|
||||
|
||||
if (lastGame != null) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package dev.lucasnlm.antimine.core.analytics.models
|
||||
|
||||
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
|
||||
import dev.lucasnlm.antimine.common.level.models.Difficulty
|
||||
import dev.lucasnlm.antimine.common.level.models.Score
|
||||
import dev.lucasnlm.antimine.common.level.models.Minefield
|
||||
|
||||
|
@ -10,10 +10,10 @@ sealed class Analytics(
|
|||
) {
|
||||
class Open : Analytics("Open game")
|
||||
|
||||
class NewGame(minefield: Minefield, difficultyPreset: DifficultyPreset, seed: Long, useAccessibilityMode: Boolean) :
|
||||
class NewGame(minefield: Minefield, difficulty: Difficulty, seed: Long, useAccessibilityMode: Boolean) :
|
||||
Analytics("New Game", mapOf(
|
||||
"Seed" to seed.toString(),
|
||||
"Difficulty Preset" to difficultyPreset.text,
|
||||
"Difficulty Preset" to difficulty.text,
|
||||
"Width" to minefield.width.toString(),
|
||||
"Height" to minefield.height.toString(),
|
||||
"Mines" to minefield.mines.toString(),
|
||||
|
@ -44,11 +44,11 @@ sealed class Analytics(
|
|||
)
|
||||
)
|
||||
|
||||
class Victory(time: Long, score: Score, difficultyPreset: DifficultyPreset) : Analytics(
|
||||
class Victory(time: Long, score: Score, difficulty: Difficulty) : Analytics(
|
||||
"Victory",
|
||||
mapOf(
|
||||
"Time" to time.toString(),
|
||||
"Difficulty" to difficultyPreset.text,
|
||||
"Difficulty" to difficulty.text,
|
||||
"Right Mines" to score.rightMines.toString(),
|
||||
"Total Mines" to score.totalMines.toString(),
|
||||
"Total Area" to score.totalArea.toString()
|
||||
|
|
|
@ -3,7 +3,7 @@ package dev.lucasnlm.antimine.common.level
|
|||
import android.util.DisplayMetrics
|
||||
import com.nhaarman.mockitokotlin2.doReturn
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
|
||||
import dev.lucasnlm.antimine.common.level.models.Difficulty
|
||||
import dev.lucasnlm.antimine.common.level.models.Minefield
|
||||
import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
|
||||
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
|
||||
|
@ -17,7 +17,7 @@ class MinefieldFactoryTest {
|
|||
@Test
|
||||
fun testFromDifficultyPresetBeginner() {
|
||||
GameModeFactory.fromDifficultyPreset(
|
||||
DifficultyPreset.Beginner, dimensionRepository, preferencesRepository
|
||||
Difficulty.Beginner, dimensionRepository, preferencesRepository
|
||||
).run {
|
||||
assertEquals(9, width)
|
||||
assertEquals(9, height)
|
||||
|
@ -28,7 +28,7 @@ class MinefieldFactoryTest {
|
|||
@Test
|
||||
fun testFromDifficultyPresetIntermediate() {
|
||||
GameModeFactory.fromDifficultyPreset(
|
||||
DifficultyPreset.Intermediate, dimensionRepository, preferencesRepository
|
||||
Difficulty.Intermediate, dimensionRepository, preferencesRepository
|
||||
).run {
|
||||
assertEquals(16, width)
|
||||
assertEquals(16, height)
|
||||
|
@ -39,7 +39,7 @@ class MinefieldFactoryTest {
|
|||
@Test
|
||||
fun testFromDifficultyPresetExpert() {
|
||||
GameModeFactory.fromDifficultyPreset(
|
||||
DifficultyPreset.Expert, dimensionRepository, preferencesRepository
|
||||
Difficulty.Expert, dimensionRepository, preferencesRepository
|
||||
).run {
|
||||
assertEquals(24, width)
|
||||
assertEquals(24, height)
|
||||
|
@ -58,7 +58,7 @@ class MinefieldFactoryTest {
|
|||
}
|
||||
|
||||
GameModeFactory.fromDifficultyPreset(
|
||||
DifficultyPreset.Custom,
|
||||
Difficulty.Custom,
|
||||
mock(),
|
||||
preferencesRepository
|
||||
).run {
|
||||
|
@ -80,7 +80,7 @@ class MinefieldFactoryTest {
|
|||
}
|
||||
|
||||
GameModeFactory.fromDifficultyPreset(
|
||||
DifficultyPreset.Standard,
|
||||
Difficulty.Standard,
|
||||
dimensionRepository,
|
||||
preferencesRepository
|
||||
).run {
|
||||
|
|
Loading…
Reference in a new issue