Fix ktlint
This commit is contained in:
parent
8e96da3996
commit
7f611deef4
22 changed files with 106 additions and 100 deletions
|
@ -26,6 +26,7 @@ import androidx.lifecycle.Transformations
|
|||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.preference.PreferenceManager
|
||||
import dev.lucasnlm.antimine.about.AboutActivity
|
||||
import dev.lucasnlm.antimine.core.models.Difficulty
|
||||
import dev.lucasnlm.antimine.common.level.models.Event
|
||||
import dev.lucasnlm.antimine.core.models.Score
|
||||
|
@ -604,7 +605,7 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
|
|||
|
||||
private fun showAbout() {
|
||||
analyticsManager.sentEvent(Analytics.OpenAbout)
|
||||
Intent(this, dev.lucasnlm.antimine.about.AboutActivity::class.java).apply {
|
||||
Intent(this, AboutActivity::class.java).apply {
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ class EndGameDialogFragment : AppCompatDialogFragment() {
|
|||
private val instantAppManager: IInstantAppManager by inject()
|
||||
private val endGameViewModel by viewModel<EndGameDialogViewModel>()
|
||||
private val gameViewModel by sharedViewModel<GameViewModel>()
|
||||
private val preferencesRepository: dev.lucasnlm.antimine.preferences.IPreferencesRepository by inject()
|
||||
private val preferencesRepository: IPreferencesRepository by inject()
|
||||
private val billingManager: IBillingManager by inject()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
|
@ -25,7 +25,7 @@ class CreateGameViewModelTest : IntentViewModelTest() {
|
|||
|
||||
@Test
|
||||
fun testSetNewCustomValues() {
|
||||
val preferenceRepository: dev.lucasnlm.antimine.preferences.IPreferencesRepository = mockk {
|
||||
val preferenceRepository: IPreferencesRepository = mockk {
|
||||
every { customGameMode() } returns Minefield(10, 12, 9)
|
||||
every { updateCustomGameMode(any()) } returns Unit
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ val TestCommonModule = module {
|
|||
} bind ISoundManager::class
|
||||
|
||||
single {
|
||||
object : dev.lucasnlm.antimine.ui.repository.IThemeRepository {
|
||||
object : IThemeRepository {
|
||||
override fun getCustomTheme(): AppTheme? = null
|
||||
|
||||
override fun getTheme(): AppTheme = LightTheme
|
||||
|
|
|
@ -7,7 +7,7 @@ buildscript {
|
|||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.0.2'
|
||||
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21'
|
||||
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10'
|
||||
|
||||
if (System.getenv('IS_GOOGLE_BUILD')) {
|
||||
classpath 'com.google.gms:google-services:4.3.4'
|
||||
|
|
|
@ -8,8 +8,9 @@ import android.graphics.Paint
|
|||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import dev.lucasnlm.antimine.core.models.Area
|
||||
import dev.lucasnlm.antimine.core.models.Mark
|
||||
import dev.lucasnlm.antimine.common.level.view.AreaAdapter
|
||||
import dev.lucasnlm.antimine.ui.repository.Themes.LightTheme
|
||||
import dev.lucasnlm.antimine.ui.view.createAreaPaintSettings
|
||||
import dev.lucasnlm.antimine.ui.view.paintOnCanvas
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
@ -19,8 +20,8 @@ import java.io.FileOutputStream
|
|||
class AreaScreenshot {
|
||||
private lateinit var context: Context
|
||||
|
||||
private fun saveImage(area: dev.lucasnlm.antimine.core.models.Area, fileName: String, ambientMode: Boolean): File {
|
||||
val paintSettings = AreaAdapter.createAreaPaintSettings(context, 128.0f, 3)
|
||||
private fun saveImage(area: Area, fileName: String, ambientMode: Boolean): File {
|
||||
val paintSettings = createAreaPaintSettings(context, 128.0f, 3)
|
||||
val size = paintSettings.rectF.width().toInt()
|
||||
val testPadding = 4
|
||||
val bitmap = Bitmap.createBitmap(size + testPadding, size + testPadding, Bitmap.Config.ARGB_8888)
|
||||
|
@ -72,7 +73,7 @@ class AreaScreenshot {
|
|||
return result
|
||||
}
|
||||
|
||||
private fun screenshotTest(area: dev.lucasnlm.antimine.core.models.Area, fileName: String, ambientMode: Boolean = false) {
|
||||
private fun screenshotTest(area: Area, fileName: String, ambientMode: Boolean = false) {
|
||||
val current = saveImage(area, fileName, ambientMode)
|
||||
assertTrue("$fileName doesn't match the reference", compareScreenshot(current, fileName))
|
||||
}
|
||||
|
@ -84,25 +85,25 @@ class AreaScreenshot {
|
|||
|
||||
@Test
|
||||
fun testCoveredArea() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(0, 0, 0, isCovered = true)
|
||||
val area = Area(0, 0, 0, isCovered = true)
|
||||
screenshotTest(area, "covered.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCoveredAreaAmbientMode() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(0, 0, 0, isCovered = true)
|
||||
val area = Area(0, 0, 0, isCovered = true)
|
||||
screenshotTest(area, "covered_ambient.png", true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUncoveredArea() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(0, 0, 0, isCovered = false)
|
||||
val area = Area(0, 0, 0, isCovered = false)
|
||||
screenshotTest(area, "uncovered.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testUncoveredAreaAmbientMode() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(0, 0, 0, isCovered = false)
|
||||
val area = Area(0, 0, 0, isCovered = false)
|
||||
screenshotTest(area, "uncovered_ambient.png", ambientMode = true)
|
||||
}
|
||||
|
||||
|
@ -111,7 +112,7 @@ class AreaScreenshot {
|
|||
repeat(8) {
|
||||
val id = it + 1
|
||||
screenshotTest(
|
||||
dev.lucasnlm.antimine.core.models.Area(
|
||||
Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -128,7 +129,7 @@ class AreaScreenshot {
|
|||
repeat(8) {
|
||||
val id = it + 1
|
||||
screenshotTest(
|
||||
dev.lucasnlm.antimine.core.models.Area(
|
||||
Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -143,55 +144,55 @@ class AreaScreenshot {
|
|||
|
||||
@Test
|
||||
fun testCoveredAreaWithFlag() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
isCovered = true,
|
||||
mark = dev.lucasnlm.antimine.core.models.Mark.Flag
|
||||
mark = Mark.Flag
|
||||
)
|
||||
screenshotTest(area, "covered_flag.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCoveredAreaWithFlagAmbient() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
isCovered = true,
|
||||
mark = dev.lucasnlm.antimine.core.models.Mark.Flag
|
||||
mark = Mark.Flag
|
||||
)
|
||||
screenshotTest(area, "covered_flag_ambient.png", true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCoveredAreaWithQuestion() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
isCovered = true,
|
||||
mark = dev.lucasnlm.antimine.core.models.Mark.Question
|
||||
mark = Mark.Question
|
||||
)
|
||||
screenshotTest(area, "covered_question.png")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCoveredAreaWithQuestionAmbient() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
isCovered = true,
|
||||
mark = dev.lucasnlm.antimine.core.models.Mark.Question
|
||||
mark = Mark.Question
|
||||
)
|
||||
screenshotTest(area, "covered_question_ambient.png", true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCoveredAreaHighlighted() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -203,7 +204,7 @@ class AreaScreenshot {
|
|||
|
||||
@Test
|
||||
fun testCoveredAreaHighlightedAmbient() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -215,7 +216,7 @@ class AreaScreenshot {
|
|||
|
||||
@Test
|
||||
fun testCoveredAreaWithMine() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -227,7 +228,7 @@ class AreaScreenshot {
|
|||
|
||||
@Test
|
||||
fun testCoveredAreaWithMineAmbient() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -239,7 +240,7 @@ class AreaScreenshot {
|
|||
|
||||
@Test
|
||||
fun testUncoveredAreaWithMine() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -251,7 +252,7 @@ class AreaScreenshot {
|
|||
|
||||
@Test
|
||||
fun testUncoveredAreaWithMineAmbient() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -263,7 +264,7 @@ class AreaScreenshot {
|
|||
|
||||
@Test
|
||||
fun testUncoveredAreaHighlighted() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -276,7 +277,7 @@ class AreaScreenshot {
|
|||
|
||||
@Test
|
||||
fun testUncoveredAreaHighlightedAmbient() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -289,7 +290,7 @@ class AreaScreenshot {
|
|||
|
||||
@Test
|
||||
fun testUncoveredAreaWithMineExploded() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -302,7 +303,7 @@ class AreaScreenshot {
|
|||
|
||||
@Test
|
||||
fun testUncoveredAreaWithMineExplodedAmbient() {
|
||||
val area = dev.lucasnlm.antimine.core.models.Area(
|
||||
val area = Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -318,7 +319,7 @@ class AreaScreenshot {
|
|||
repeat(8) {
|
||||
val id = it + 1
|
||||
screenshotTest(
|
||||
dev.lucasnlm.antimine.core.models.Area(
|
||||
Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -336,7 +337,7 @@ class AreaScreenshot {
|
|||
repeat(8) {
|
||||
val id = it + 1
|
||||
screenshotTest(
|
||||
dev.lucasnlm.antimine.core.models.Area(
|
||||
Area(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
|
|
@ -56,7 +56,7 @@ class GameController {
|
|||
|
||||
fun field() = field
|
||||
|
||||
fun field(predicate: (dev.lucasnlm.antimine.core.models.Area) -> Boolean) = field.filter(predicate)
|
||||
fun field(predicate: (Area) -> Boolean) = field.filter(predicate)
|
||||
|
||||
fun mines() = field.filter { it.hasMine }
|
||||
|
||||
|
@ -77,7 +77,7 @@ class GameController {
|
|||
firstOpen = FirstOpen.Position(safeId)
|
||||
}
|
||||
|
||||
private fun handleAction(target: dev.lucasnlm.antimine.core.models.Area, actionResponse: ActionResponse?) {
|
||||
private fun handleAction(target: Area, actionResponse: ActionResponse?) {
|
||||
val mustPlantMines = !hasMines()
|
||||
|
||||
val minefieldHandler: MinefieldHandler
|
||||
|
@ -175,7 +175,7 @@ class GameController {
|
|||
}
|
||||
}
|
||||
|
||||
fun getScore() = dev.lucasnlm.antimine.core.models.Score(
|
||||
fun getScore() = Score(
|
||||
mines().count { !it.mistake && it.mark.isFlag() },
|
||||
getMinesCount(),
|
||||
field.count()
|
||||
|
@ -192,7 +192,7 @@ class GameController {
|
|||
|
||||
fun findExplodedMine() = mines().firstOrNull { it.mistake }
|
||||
|
||||
fun takeExplosionRadius(target: dev.lucasnlm.antimine.core.models.Area): List<dev.lucasnlm.antimine.core.models.Area> =
|
||||
fun takeExplosionRadius(target: Area): List<Area> =
|
||||
mines().filter { it.isCovered && it.mark.isNone() }.sortedBy {
|
||||
val dx1 = (it.posX - target.posX)
|
||||
val dy1 = (it.posY - target.posY)
|
||||
|
|
|
@ -10,16 +10,16 @@ import java.lang.reflect.Type
|
|||
|
||||
class AreaConverter {
|
||||
private val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
|
||||
private val jsonAdapter: JsonAdapter<List<dev.lucasnlm.antimine.core.models.Area>>
|
||||
private val jsonAdapter: JsonAdapter<List<Area>>
|
||||
|
||||
init {
|
||||
val type: Type = Types.newParameterizedType(List::class.java, dev.lucasnlm.antimine.core.models.Area::class.java)
|
||||
val type: Type = Types.newParameterizedType(List::class.java, Area::class.java)
|
||||
this.jsonAdapter = moshi.adapter(type)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun toAreaList(jsonInput: String): List<dev.lucasnlm.antimine.core.models.Area> = jsonAdapter.fromJson(jsonInput) ?: listOf()
|
||||
fun toAreaList(jsonInput: String): List<Area> = jsonAdapter.fromJson(jsonInput) ?: listOf()
|
||||
|
||||
@TypeConverter
|
||||
fun toJsonString(field: List<dev.lucasnlm.antimine.core.models.Area>): String = jsonAdapter.toJson(field)
|
||||
fun toJsonString(field: List<Area>): String = jsonAdapter.toJson(field)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import dev.lucasnlm.antimine.preferences.models.Minefield
|
|||
import dev.lucasnlm.antimine.common.level.database.converters.AreaConverter
|
||||
import dev.lucasnlm.antimine.common.level.database.converters.FirstOpenConverter
|
||||
import dev.lucasnlm.antimine.common.level.database.converters.SaveStatusConverter
|
||||
import dev.lucasnlm.antimine.core.models.Area
|
||||
import dev.lucasnlm.antimine.core.models.Difficulty
|
||||
|
||||
@Entity
|
||||
|
@ -40,7 +41,7 @@ data class Save(
|
|||
|
||||
@TypeConverters(AreaConverter::class)
|
||||
@ColumnInfo(name = "field")
|
||||
val field: List<dev.lucasnlm.antimine.core.models.Area>,
|
||||
val field: List<Area>,
|
||||
|
||||
@ColumnInfo(name = "actions")
|
||||
val actions: Int,
|
||||
|
|
|
@ -4,7 +4,7 @@ import dev.lucasnlm.antimine.core.models.Area
|
|||
import dev.lucasnlm.antimine.core.models.Mark
|
||||
|
||||
class FlagAssistant(
|
||||
private val field: MutableList<dev.lucasnlm.antimine.core.models.Area>,
|
||||
private val field: MutableList<Area>,
|
||||
) {
|
||||
fun runFlagAssistant() {
|
||||
// Must not select Mark.PurposefulNone, only Mark.None. Otherwise, it will flag
|
||||
|
@ -14,9 +14,9 @@ class FlagAssistant(
|
|||
.forEach(::putFlagIfIsolated)
|
||||
}
|
||||
|
||||
fun result(): List<dev.lucasnlm.antimine.core.models.Area> = field.toList()
|
||||
fun result(): List<Area> = field.toList()
|
||||
|
||||
private fun putFlagIfIsolated(it: dev.lucasnlm.antimine.core.models.Area) {
|
||||
private fun putFlagIfIsolated(it: Area) {
|
||||
val neighbors = field.filterNeighborsOf(it)
|
||||
val neighborsCount = neighbors.count()
|
||||
val revealedNeighborsCount = neighbors.count { neighbor ->
|
||||
|
@ -24,7 +24,7 @@ class FlagAssistant(
|
|||
}
|
||||
|
||||
if (revealedNeighborsCount == neighborsCount) {
|
||||
field[it.id] = it.copy(mark = dev.lucasnlm.antimine.core.models.Mark.Flag)
|
||||
field[it.id] = it.copy(mark = Mark.Flag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ class MinefieldCreator(
|
|||
private val minefield: Minefield,
|
||||
private val randomGenerator: Random,
|
||||
) {
|
||||
private fun createMutableEmpty(): List<dev.lucasnlm.antimine.core.models.Area> {
|
||||
private fun createMutableEmpty(): List<Area> {
|
||||
val width = minefield.width
|
||||
val height = minefield.height
|
||||
val fieldLength = width * height
|
||||
|
@ -17,7 +17,7 @@ class MinefieldCreator(
|
|||
return (0 until fieldLength).map { index ->
|
||||
val yPosition = floor((index / width).toDouble()).toInt()
|
||||
val xPosition = (index % width)
|
||||
dev.lucasnlm.antimine.core.models.Area(
|
||||
Area(
|
||||
index,
|
||||
xPosition,
|
||||
yPosition,
|
||||
|
@ -27,11 +27,11 @@ class MinefieldCreator(
|
|||
}
|
||||
}
|
||||
|
||||
fun createEmpty(): List<dev.lucasnlm.antimine.core.models.Area> {
|
||||
fun createEmpty(): List<Area> {
|
||||
return createMutableEmpty()
|
||||
}
|
||||
|
||||
fun create(safeIndex: Int, safeZone: Boolean): List<dev.lucasnlm.antimine.core.models.Area> {
|
||||
fun create(safeIndex: Int, safeZone: Boolean): List<Area> {
|
||||
return createMutableEmpty().toMutableList().apply {
|
||||
// Plant mines and setup number tips
|
||||
if (safeZone) { filterNotNeighborsOf(safeIndex) } else { filterNot { it.id == safeIndex } }
|
||||
|
|
|
@ -4,17 +4,17 @@ import dev.lucasnlm.antimine.core.models.Area
|
|||
import dev.lucasnlm.antimine.core.models.Mark
|
||||
|
||||
class MinefieldHandler(
|
||||
private val field: MutableList<dev.lucasnlm.antimine.core.models.Area>,
|
||||
private val field: MutableList<Area>,
|
||||
private val useQuestionMark: Boolean,
|
||||
) {
|
||||
fun showAllMines() {
|
||||
field.filter { it.hasMine && it.mark != dev.lucasnlm.antimine.core.models.Mark.Flag }
|
||||
field.filter { it.hasMine && it.mark != Mark.Flag }
|
||||
.forEach { field[it.id] = it.copy(isCovered = false) }
|
||||
}
|
||||
|
||||
fun flagAllMines() {
|
||||
field.filter { it.hasMine }
|
||||
.forEach { field[it.id] = it.copy(mark = dev.lucasnlm.antimine.core.models.Mark.Flag) }
|
||||
.forEach { field[it.id] = it.copy(mark = Mark.Flag) }
|
||||
}
|
||||
|
||||
fun revealAllEmptyAreas() {
|
||||
|
@ -36,7 +36,7 @@ class MinefieldHandler(
|
|||
|
||||
fun removeMarkAt(index: Int) {
|
||||
field.getOrNull(index)?.let {
|
||||
field[it.id] = it.copy(mark = dev.lucasnlm.antimine.core.models.Mark.PurposefulNone)
|
||||
field[it.id] = it.copy(mark = Mark.PurposefulNone)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,9 +45,9 @@ class MinefieldHandler(
|
|||
if (it.isCovered) {
|
||||
field[index] = it.copy(
|
||||
mark = when (it.mark) {
|
||||
dev.lucasnlm.antimine.core.models.Mark.PurposefulNone, dev.lucasnlm.antimine.core.models.Mark.None -> dev.lucasnlm.antimine.core.models.Mark.Flag
|
||||
dev.lucasnlm.antimine.core.models.Mark.Flag -> if (useQuestionMark) dev.lucasnlm.antimine.core.models.Mark.Question else dev.lucasnlm.antimine.core.models.Mark.None
|
||||
dev.lucasnlm.antimine.core.models.Mark.Question -> dev.lucasnlm.antimine.core.models.Mark.None
|
||||
Mark.PurposefulNone, Mark.None -> Mark.Flag
|
||||
Mark.Flag -> if (useQuestionMark) Mark.Question else Mark.None
|
||||
Mark.Question -> Mark.None
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class MinefieldHandler(
|
|||
if (isCovered) {
|
||||
field[index] = copy(
|
||||
isCovered = false,
|
||||
mark = dev.lucasnlm.antimine.core.models.Mark.None,
|
||||
mark = Mark.None,
|
||||
mistake = (!passive && hasMine) || (!hasMine && mark.isFlag())
|
||||
)
|
||||
|
||||
|
@ -111,5 +111,5 @@ class MinefieldHandler(
|
|||
}
|
||||
}
|
||||
|
||||
fun result(): List<dev.lucasnlm.antimine.core.models.Area> = field.toList()
|
||||
fun result(): List<Area> = field.toList()
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ sealed class Status {
|
|||
|
||||
class Over(
|
||||
val time: Long = 0L,
|
||||
val score: dev.lucasnlm.antimine.core.models.Score? = null,
|
||||
val score: Score? = null,
|
||||
) : Status()
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import dev.lucasnlm.antimine.common.level.logic.MinefieldHandler
|
|||
import dev.lucasnlm.antimine.core.models.Area
|
||||
|
||||
open class BruteForceSolver : GameSolver() {
|
||||
override fun trySolve(minefield: MutableList<dev.lucasnlm.antimine.core.models.Area>): Boolean {
|
||||
override fun trySolve(minefield: MutableList<Area>): Boolean {
|
||||
val minefieldHandler = MinefieldHandler(minefield, false)
|
||||
|
||||
do {
|
||||
|
|
|
@ -12,5 +12,5 @@ abstract class GameSolver {
|
|||
* Try solve the given [minefield].
|
||||
* Returns true if it's solvable or false otherwise.
|
||||
*/
|
||||
abstract fun trySolve(minefield: MutableList<dev.lucasnlm.antimine.core.models.Area>): Boolean
|
||||
abstract fun trySolve(minefield: MutableList<Area>): Boolean
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ open class GameViewModel(
|
|||
private var initialized = false
|
||||
private var currentDifficulty: Difficulty = Difficulty.Standard
|
||||
|
||||
val field = MutableLiveData<List<dev.lucasnlm.antimine.core.models.Area>>()
|
||||
val field = MutableLiveData<List<Area>>()
|
||||
val elapsedTimeSeconds = MutableLiveData<Long>()
|
||||
val mineCount = MutableLiveData<Int>()
|
||||
val difficulty = MutableLiveData<Difficulty>()
|
||||
|
@ -90,7 +90,7 @@ open class GameViewModel(
|
|||
eventObserver.postValue(Event.StartNewGame)
|
||||
|
||||
analyticsManager.sentEvent(
|
||||
dev.lucasnlm.antimine.core.models.Analytics.NewGame(
|
||||
Analytics.NewGame(
|
||||
minefield,
|
||||
newDifficulty,
|
||||
gameController.seed,
|
||||
|
@ -123,7 +123,7 @@ open class GameViewModel(
|
|||
}
|
||||
|
||||
saveId.postValue(save.uid.toLong())
|
||||
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.ResumePreviousGame)
|
||||
analyticsManager.sentEvent(Analytics.ResumePreviousGame)
|
||||
return setup
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ open class GameViewModel(
|
|||
eventObserver.postValue(Event.ResumeGame)
|
||||
|
||||
analyticsManager.sentEvent(
|
||||
dev.lucasnlm.antimine.core.models.Analytics.RetryGame(
|
||||
Analytics.RetryGame(
|
||||
setup,
|
||||
currentDifficulty,
|
||||
gameController.seed,
|
||||
|
@ -310,19 +310,19 @@ open class GameViewModel(
|
|||
private fun onFeedbackAnalytics(action: ActionResponse, index: Int) {
|
||||
when (action) {
|
||||
ActionResponse.OpenTile -> {
|
||||
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.OpenTile(index))
|
||||
analyticsManager.sentEvent(Analytics.OpenTile(index))
|
||||
}
|
||||
ActionResponse.SwitchMark -> {
|
||||
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.SwitchMark(index))
|
||||
analyticsManager.sentEvent(Analytics.SwitchMark(index))
|
||||
}
|
||||
ActionResponse.HighlightNeighbors -> {
|
||||
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.HighlightNeighbors(index))
|
||||
analyticsManager.sentEvent(Analytics.HighlightNeighbors(index))
|
||||
}
|
||||
ActionResponse.OpenNeighbors -> {
|
||||
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.OpenNeighbors(index))
|
||||
analyticsManager.sentEvent(Analytics.OpenNeighbors(index))
|
||||
}
|
||||
ActionResponse.OpenOrMark -> {
|
||||
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.OpenOrFlagTile(index))
|
||||
analyticsManager.sentEvent(Analytics.OpenOrFlagTile(index))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -430,7 +430,7 @@ open class GameViewModel(
|
|||
|
||||
suspend fun gameOver(fromResumeGame: Boolean) {
|
||||
gameController.run {
|
||||
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.GameOver(clock.time(), getScore()))
|
||||
analyticsManager.sentEvent(Analytics.GameOver(clock.time(), getScore()))
|
||||
|
||||
if (!fromResumeGame) {
|
||||
if (preferencesRepository.useHapticFeedback()) {
|
||||
|
@ -473,7 +473,7 @@ open class GameViewModel(
|
|||
fun victory() {
|
||||
gameController.run {
|
||||
analyticsManager.sentEvent(
|
||||
dev.lucasnlm.antimine.core.models.Analytics.Victory(
|
||||
Analytics.Victory(
|
||||
clock.time(),
|
||||
getScore(),
|
||||
currentDifficulty
|
||||
|
|
|
@ -12,7 +12,7 @@ class DebugAnalyticsManager : IAnalyticsManager {
|
|||
}
|
||||
}
|
||||
|
||||
override fun sentEvent(event: dev.lucasnlm.antimine.core.models.Analytics) {
|
||||
override fun sentEvent(event: Analytics) {
|
||||
val message = if (event.extra.isNotEmpty()) {
|
||||
"Sent event: '${event.name}' with ${event.extra}"
|
||||
} else {
|
||||
|
|
|
@ -12,7 +12,7 @@ class ProdAnalyticsManager(
|
|||
analyticsWrapper.setup(context, properties)
|
||||
}
|
||||
|
||||
override fun sentEvent(event: dev.lucasnlm.antimine.core.models.Analytics) {
|
||||
override fun sentEvent(event: Analytics) {
|
||||
analyticsWrapper.sendEvent(event.name, event.extra)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,39 +66,39 @@ class AreaConverterTest {
|
|||
|
||||
private val areaList =
|
||||
listOf(
|
||||
dev.lucasnlm.antimine.core.models.Area(
|
||||
Area(
|
||||
1, 2, 3, 5,
|
||||
hasMine = false,
|
||||
mistake = false,
|
||||
isCovered = true,
|
||||
mark = dev.lucasnlm.antimine.core.models.Mark.None,
|
||||
mark = Mark.None,
|
||||
highlighted = true,
|
||||
revealed = false,
|
||||
),
|
||||
dev.lucasnlm.antimine.core.models.Area(
|
||||
Area(
|
||||
2, 5, 3, 0,
|
||||
hasMine = true,
|
||||
mistake = true,
|
||||
isCovered = false,
|
||||
mark = dev.lucasnlm.antimine.core.models.Mark.PurposefulNone,
|
||||
mark = Mark.PurposefulNone,
|
||||
highlighted = false,
|
||||
revealed = false,
|
||||
),
|
||||
dev.lucasnlm.antimine.core.models.Area(
|
||||
Area(
|
||||
3, 1, 1, 3,
|
||||
hasMine = true,
|
||||
mistake = false,
|
||||
isCovered = true,
|
||||
mark = dev.lucasnlm.antimine.core.models.Mark.Flag,
|
||||
mark = Mark.Flag,
|
||||
highlighted = true,
|
||||
revealed = false,
|
||||
),
|
||||
dev.lucasnlm.antimine.core.models.Area(
|
||||
Area(
|
||||
4, 0, 0, 6,
|
||||
hasMine = false,
|
||||
mistake = false,
|
||||
isCovered = true,
|
||||
mark = dev.lucasnlm.antimine.core.models.Mark.Question,
|
||||
mark = Mark.Question,
|
||||
highlighted = true,
|
||||
revealed = true,
|
||||
)
|
||||
|
|
|
@ -39,7 +39,7 @@ class GameControllerTest {
|
|||
@Test
|
||||
fun testGetScore() = runBlockingTest {
|
||||
withGameController { controller ->
|
||||
assertEquals(dev.lucasnlm.antimine.core.models.Score(0, 20, 100), controller.getScore())
|
||||
assertEquals(Score(0, 20, 100), controller.getScore())
|
||||
|
||||
repeat(20) { markedMines ->
|
||||
controller
|
||||
|
@ -51,7 +51,7 @@ class GameControllerTest {
|
|||
controller.fakeLongPress(it.id)
|
||||
}
|
||||
|
||||
assertEquals(dev.lucasnlm.antimine.core.models.Score(markedMines, 20, 100), controller.getScore())
|
||||
assertEquals(Score(markedMines, 20, 100), controller.getScore())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class GameControllerTest {
|
|||
@Test
|
||||
fun testGetScoreWithQuestion() = runBlockingTest {
|
||||
withGameController { controller ->
|
||||
assertEquals(dev.lucasnlm.antimine.core.models.Score(0, 20, 100), controller.getScore())
|
||||
assertEquals(Score(0, 20, 100), controller.getScore())
|
||||
controller.useQuestionMark(true)
|
||||
|
||||
controller
|
||||
|
@ -71,7 +71,7 @@ class GameControllerTest {
|
|||
controller.fakeLongPress(it.id)
|
||||
}
|
||||
|
||||
assertEquals(dev.lucasnlm.antimine.core.models.Score(0, 20, 100), controller.getScore())
|
||||
assertEquals(Score(0, 20, 100), controller.getScore())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -528,7 +528,7 @@ class GameControllerTest {
|
|||
}
|
||||
}
|
||||
|
||||
private fun GameController.at(index: Int): dev.lucasnlm.antimine.core.models.Area {
|
||||
private fun GameController.at(index: Int): Area {
|
||||
return this.field().first { it.id == index }
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class MinefieldHandlerTest {
|
|||
assertTrue(handler.result()[3].isCovered)
|
||||
handler.openAt(3, false, openNeighbors = false)
|
||||
assertFalse(handler.result()[3].isCovered)
|
||||
assertEquals(dev.lucasnlm.antimine.core.models.Mark.None, handler.result()[3].mark)
|
||||
assertEquals(Mark.None, handler.result()[3].mark)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ class MinefieldHandlerTest {
|
|||
assertTrue(handler.result()[3].isCovered)
|
||||
handler.openAt(3, false, openNeighbors = false)
|
||||
assertFalse(handler.result()[3].isCovered)
|
||||
assertEquals(dev.lucasnlm.antimine.core.models.Mark.None, handler.result()[3].mark)
|
||||
assertEquals(Mark.None, handler.result()[3].mark)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ class MinefieldHandlerTest {
|
|||
handler.switchMarkAt(3)
|
||||
|
||||
handler.removeMarkAt(3)
|
||||
assertTrue(handler.result()[3].mark == dev.lucasnlm.antimine.core.models.Mark.PurposefulNone)
|
||||
assertTrue(handler.result()[3].mark == Mark.PurposefulNone)
|
||||
assertTrue(handler.result()[3].mark.isNone())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@ import android.view.MotionEvent
|
|||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.ViewCompat
|
||||
import dev.lucasnlm.antimine.core.models.Area
|
||||
import dev.lucasnlm.antimine.core.models.AreaPaintSettings
|
||||
import dev.lucasnlm.antimine.core.models.Mark
|
||||
import dev.lucasnlm.antimine.ui.R
|
||||
import dev.lucasnlm.antimine.ui.model.AppTheme
|
||||
|
||||
|
@ -20,8 +23,8 @@ class AreaView : View {
|
|||
private var isAmbientMode: Boolean = false
|
||||
private var isLowBitAmbient: Boolean = false
|
||||
|
||||
private var area: dev.lucasnlm.antimine.core.models.Area? = null
|
||||
private lateinit var paintSettings: dev.lucasnlm.antimine.core.models.AreaPaintSettings
|
||||
private var area: Area? = null
|
||||
private lateinit var paintSettings: AreaPaintSettings
|
||||
private lateinit var theme: AppTheme
|
||||
|
||||
private val gestureDetector: GestureDetector by lazy {
|
||||
|
@ -46,11 +49,11 @@ class AreaView : View {
|
|||
}
|
||||
|
||||
fun bindField(
|
||||
area: dev.lucasnlm.antimine.core.models.Area,
|
||||
area: Area,
|
||||
theme: AppTheme,
|
||||
isAmbientMode: Boolean,
|
||||
isLowBitAmbient: Boolean,
|
||||
paintSettings: dev.lucasnlm.antimine.core.models.AreaPaintSettings
|
||||
paintSettings: AreaPaintSettings
|
||||
) {
|
||||
this.paintSettings = paintSettings
|
||||
|
||||
|
@ -84,12 +87,12 @@ class AreaView : View {
|
|||
override fun onTouchEvent(event: MotionEvent?): Boolean =
|
||||
gestureDetector.onTouchEvent(event) || super.onTouchEvent(event)
|
||||
|
||||
private fun bindContentDescription(area: dev.lucasnlm.antimine.core.models.Area) {
|
||||
private fun bindContentDescription(area: Area) {
|
||||
contentDescription = when {
|
||||
area.mark == dev.lucasnlm.antimine.core.models.Mark.Flag -> {
|
||||
area.mark == Mark.Flag -> {
|
||||
context.getString(if (area.mistake) R.string.desc_wrongly_marked_area else R.string.desc_marked_area)
|
||||
}
|
||||
area.mark == dev.lucasnlm.antimine.core.models.Mark.Question -> context.getString(R.string.desc_marked_area)
|
||||
area.mark == Mark.Question -> context.getString(R.string.desc_marked_area)
|
||||
area.isCovered -> context.getString(R.string.desc_convered_area)
|
||||
!area.isCovered && area.minesAround > 0 -> area.minesAround.toString()
|
||||
!area.isCovered && area.hasMine -> context.getString(R.string.exploded_mine)
|
||||
|
|
Loading…
Reference in a new issue