Fix ktlint

This commit is contained in:
Lucas Lima 2020-12-31 17:47:38 -03:00 committed by Lucas Nunes
parent 8e96da3996
commit 7f611deef4
22 changed files with 106 additions and 100 deletions

View file

@ -26,6 +26,7 @@ import androidx.lifecycle.Transformations
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import dev.lucasnlm.antimine.about.AboutActivity
import dev.lucasnlm.antimine.core.models.Difficulty import dev.lucasnlm.antimine.core.models.Difficulty
import dev.lucasnlm.antimine.common.level.models.Event import dev.lucasnlm.antimine.common.level.models.Event
import dev.lucasnlm.antimine.core.models.Score import dev.lucasnlm.antimine.core.models.Score
@ -604,7 +605,7 @@ class GameActivity : ThematicActivity(R.layout.activity_game), DialogInterface.O
private fun showAbout() { private fun showAbout() {
analyticsManager.sentEvent(Analytics.OpenAbout) analyticsManager.sentEvent(Analytics.OpenAbout)
Intent(this, dev.lucasnlm.antimine.about.AboutActivity::class.java).apply { Intent(this, AboutActivity::class.java).apply {
startActivity(this) startActivity(this)
} }
} }

View file

@ -42,7 +42,7 @@ class EndGameDialogFragment : AppCompatDialogFragment() {
private val instantAppManager: IInstantAppManager by inject() private val instantAppManager: IInstantAppManager by inject()
private val endGameViewModel by viewModel<EndGameDialogViewModel>() private val endGameViewModel by viewModel<EndGameDialogViewModel>()
private val gameViewModel by sharedViewModel<GameViewModel>() 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() private val billingManager: IBillingManager by inject()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {

View file

@ -25,7 +25,7 @@ class CreateGameViewModelTest : IntentViewModelTest() {
@Test @Test
fun testSetNewCustomValues() { fun testSetNewCustomValues() {
val preferenceRepository: dev.lucasnlm.antimine.preferences.IPreferencesRepository = mockk { val preferenceRepository: IPreferencesRepository = mockk {
every { customGameMode() } returns Minefield(10, 12, 9) every { customGameMode() } returns Minefield(10, 12, 9)
every { updateCustomGameMode(any()) } returns Unit every { updateCustomGameMode(any()) } returns Unit
} }

View file

@ -23,7 +23,7 @@ val TestCommonModule = module {
} bind ISoundManager::class } bind ISoundManager::class
single { single {
object : dev.lucasnlm.antimine.ui.repository.IThemeRepository { object : IThemeRepository {
override fun getCustomTheme(): AppTheme? = null override fun getCustomTheme(): AppTheme? = null
override fun getTheme(): AppTheme = LightTheme override fun getTheme(): AppTheme = LightTheme

View file

@ -7,7 +7,7 @@ buildscript {
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.0.2' 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')) { if (System.getenv('IS_GOOGLE_BUILD')) {
classpath 'com.google.gms:google-services:4.3.4' classpath 'com.google.gms:google-services:4.3.4'

View file

@ -8,8 +8,9 @@ import android.graphics.Paint
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import dev.lucasnlm.antimine.core.models.Area import dev.lucasnlm.antimine.core.models.Area
import dev.lucasnlm.antimine.core.models.Mark 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.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.Assert.assertTrue
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
@ -19,8 +20,8 @@ import java.io.FileOutputStream
class AreaScreenshot { class AreaScreenshot {
private lateinit var context: Context private lateinit var context: Context
private fun saveImage(area: dev.lucasnlm.antimine.core.models.Area, fileName: String, ambientMode: Boolean): File { private fun saveImage(area: Area, fileName: String, ambientMode: Boolean): File {
val paintSettings = AreaAdapter.createAreaPaintSettings(context, 128.0f, 3) val paintSettings = createAreaPaintSettings(context, 128.0f, 3)
val size = paintSettings.rectF.width().toInt() val size = paintSettings.rectF.width().toInt()
val testPadding = 4 val testPadding = 4
val bitmap = Bitmap.createBitmap(size + testPadding, size + testPadding, Bitmap.Config.ARGB_8888) val bitmap = Bitmap.createBitmap(size + testPadding, size + testPadding, Bitmap.Config.ARGB_8888)
@ -72,7 +73,7 @@ class AreaScreenshot {
return result 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) val current = saveImage(area, fileName, ambientMode)
assertTrue("$fileName doesn't match the reference", compareScreenshot(current, fileName)) assertTrue("$fileName doesn't match the reference", compareScreenshot(current, fileName))
} }
@ -84,25 +85,25 @@ class AreaScreenshot {
@Test @Test
fun testCoveredArea() { 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") screenshotTest(area, "covered.png")
} }
@Test @Test
fun testCoveredAreaAmbientMode() { 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) screenshotTest(area, "covered_ambient.png", true)
} }
@Test @Test
fun testUncoveredArea() { 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") screenshotTest(area, "uncovered.png")
} }
@Test @Test
fun testUncoveredAreaAmbientMode() { 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) screenshotTest(area, "uncovered_ambient.png", ambientMode = true)
} }
@ -111,7 +112,7 @@ class AreaScreenshot {
repeat(8) { repeat(8) {
val id = it + 1 val id = it + 1
screenshotTest( screenshotTest(
dev.lucasnlm.antimine.core.models.Area( Area(
0, 0,
0, 0,
0, 0,
@ -128,7 +129,7 @@ class AreaScreenshot {
repeat(8) { repeat(8) {
val id = it + 1 val id = it + 1
screenshotTest( screenshotTest(
dev.lucasnlm.antimine.core.models.Area( Area(
0, 0,
0, 0,
0, 0,
@ -143,55 +144,55 @@ class AreaScreenshot {
@Test @Test
fun testCoveredAreaWithFlag() { fun testCoveredAreaWithFlag() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
isCovered = true, isCovered = true,
mark = dev.lucasnlm.antimine.core.models.Mark.Flag mark = Mark.Flag
) )
screenshotTest(area, "covered_flag.png") screenshotTest(area, "covered_flag.png")
} }
@Test @Test
fun testCoveredAreaWithFlagAmbient() { fun testCoveredAreaWithFlagAmbient() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
isCovered = true, isCovered = true,
mark = dev.lucasnlm.antimine.core.models.Mark.Flag mark = Mark.Flag
) )
screenshotTest(area, "covered_flag_ambient.png", true) screenshotTest(area, "covered_flag_ambient.png", true)
} }
@Test @Test
fun testCoveredAreaWithQuestion() { fun testCoveredAreaWithQuestion() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
isCovered = true, isCovered = true,
mark = dev.lucasnlm.antimine.core.models.Mark.Question mark = Mark.Question
) )
screenshotTest(area, "covered_question.png") screenshotTest(area, "covered_question.png")
} }
@Test @Test
fun testCoveredAreaWithQuestionAmbient() { fun testCoveredAreaWithQuestionAmbient() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
isCovered = true, isCovered = true,
mark = dev.lucasnlm.antimine.core.models.Mark.Question mark = Mark.Question
) )
screenshotTest(area, "covered_question_ambient.png", true) screenshotTest(area, "covered_question_ambient.png", true)
} }
@Test @Test
fun testCoveredAreaHighlighted() { fun testCoveredAreaHighlighted() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
@ -203,7 +204,7 @@ class AreaScreenshot {
@Test @Test
fun testCoveredAreaHighlightedAmbient() { fun testCoveredAreaHighlightedAmbient() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
@ -215,7 +216,7 @@ class AreaScreenshot {
@Test @Test
fun testCoveredAreaWithMine() { fun testCoveredAreaWithMine() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
@ -227,7 +228,7 @@ class AreaScreenshot {
@Test @Test
fun testCoveredAreaWithMineAmbient() { fun testCoveredAreaWithMineAmbient() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
@ -239,7 +240,7 @@ class AreaScreenshot {
@Test @Test
fun testUncoveredAreaWithMine() { fun testUncoveredAreaWithMine() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
@ -251,7 +252,7 @@ class AreaScreenshot {
@Test @Test
fun testUncoveredAreaWithMineAmbient() { fun testUncoveredAreaWithMineAmbient() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
@ -263,7 +264,7 @@ class AreaScreenshot {
@Test @Test
fun testUncoveredAreaHighlighted() { fun testUncoveredAreaHighlighted() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
@ -276,7 +277,7 @@ class AreaScreenshot {
@Test @Test
fun testUncoveredAreaHighlightedAmbient() { fun testUncoveredAreaHighlightedAmbient() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
@ -289,7 +290,7 @@ class AreaScreenshot {
@Test @Test
fun testUncoveredAreaWithMineExploded() { fun testUncoveredAreaWithMineExploded() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
@ -302,7 +303,7 @@ class AreaScreenshot {
@Test @Test
fun testUncoveredAreaWithMineExplodedAmbient() { fun testUncoveredAreaWithMineExplodedAmbient() {
val area = dev.lucasnlm.antimine.core.models.Area( val area = Area(
0, 0,
0, 0,
0, 0,
@ -318,7 +319,7 @@ class AreaScreenshot {
repeat(8) { repeat(8) {
val id = it + 1 val id = it + 1
screenshotTest( screenshotTest(
dev.lucasnlm.antimine.core.models.Area( Area(
0, 0,
0, 0,
0, 0,
@ -336,7 +337,7 @@ class AreaScreenshot {
repeat(8) { repeat(8) {
val id = it + 1 val id = it + 1
screenshotTest( screenshotTest(
dev.lucasnlm.antimine.core.models.Area( Area(
0, 0,
0, 0,
0, 0,

View file

@ -56,7 +56,7 @@ class GameController {
fun field() = field 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 } fun mines() = field.filter { it.hasMine }
@ -77,7 +77,7 @@ class GameController {
firstOpen = FirstOpen.Position(safeId) 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 mustPlantMines = !hasMines()
val minefieldHandler: MinefieldHandler 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() }, mines().count { !it.mistake && it.mark.isFlag() },
getMinesCount(), getMinesCount(),
field.count() field.count()
@ -192,7 +192,7 @@ class GameController {
fun findExplodedMine() = mines().firstOrNull { it.mistake } 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 { mines().filter { it.isCovered && it.mark.isNone() }.sortedBy {
val dx1 = (it.posX - target.posX) val dx1 = (it.posX - target.posX)
val dy1 = (it.posY - target.posY) val dy1 = (it.posY - target.posY)

View file

@ -10,16 +10,16 @@ import java.lang.reflect.Type
class AreaConverter { class AreaConverter {
private val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build() 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 { 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) this.jsonAdapter = moshi.adapter(type)
} }
@TypeConverter @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 @TypeConverter
fun toJsonString(field: List<dev.lucasnlm.antimine.core.models.Area>): String = jsonAdapter.toJson(field) fun toJsonString(field: List<Area>): String = jsonAdapter.toJson(field)
} }

View file

@ -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.AreaConverter
import dev.lucasnlm.antimine.common.level.database.converters.FirstOpenConverter import dev.lucasnlm.antimine.common.level.database.converters.FirstOpenConverter
import dev.lucasnlm.antimine.common.level.database.converters.SaveStatusConverter import dev.lucasnlm.antimine.common.level.database.converters.SaveStatusConverter
import dev.lucasnlm.antimine.core.models.Area
import dev.lucasnlm.antimine.core.models.Difficulty import dev.lucasnlm.antimine.core.models.Difficulty
@Entity @Entity
@ -40,7 +41,7 @@ data class Save(
@TypeConverters(AreaConverter::class) @TypeConverters(AreaConverter::class)
@ColumnInfo(name = "field") @ColumnInfo(name = "field")
val field: List<dev.lucasnlm.antimine.core.models.Area>, val field: List<Area>,
@ColumnInfo(name = "actions") @ColumnInfo(name = "actions")
val actions: Int, val actions: Int,

View file

@ -4,7 +4,7 @@ import dev.lucasnlm.antimine.core.models.Area
import dev.lucasnlm.antimine.core.models.Mark import dev.lucasnlm.antimine.core.models.Mark
class FlagAssistant( class FlagAssistant(
private val field: MutableList<dev.lucasnlm.antimine.core.models.Area>, private val field: MutableList<Area>,
) { ) {
fun runFlagAssistant() { fun runFlagAssistant() {
// Must not select Mark.PurposefulNone, only Mark.None. Otherwise, it will flag // Must not select Mark.PurposefulNone, only Mark.None. Otherwise, it will flag
@ -14,9 +14,9 @@ class FlagAssistant(
.forEach(::putFlagIfIsolated) .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 neighbors = field.filterNeighborsOf(it)
val neighborsCount = neighbors.count() val neighborsCount = neighbors.count()
val revealedNeighborsCount = neighbors.count { neighbor -> val revealedNeighborsCount = neighbors.count { neighbor ->
@ -24,7 +24,7 @@ class FlagAssistant(
} }
if (revealedNeighborsCount == neighborsCount) { if (revealedNeighborsCount == neighborsCount) {
field[it.id] = it.copy(mark = dev.lucasnlm.antimine.core.models.Mark.Flag) field[it.id] = it.copy(mark = Mark.Flag)
} }
} }
} }

View file

@ -9,7 +9,7 @@ class MinefieldCreator(
private val minefield: Minefield, private val minefield: Minefield,
private val randomGenerator: Random, private val randomGenerator: Random,
) { ) {
private fun createMutableEmpty(): List<dev.lucasnlm.antimine.core.models.Area> { private fun createMutableEmpty(): List<Area> {
val width = minefield.width val width = minefield.width
val height = minefield.height val height = minefield.height
val fieldLength = width * height val fieldLength = width * height
@ -17,7 +17,7 @@ class MinefieldCreator(
return (0 until fieldLength).map { index -> return (0 until fieldLength).map { index ->
val yPosition = floor((index / width).toDouble()).toInt() val yPosition = floor((index / width).toDouble()).toInt()
val xPosition = (index % width) val xPosition = (index % width)
dev.lucasnlm.antimine.core.models.Area( Area(
index, index,
xPosition, xPosition,
yPosition, yPosition,
@ -27,11 +27,11 @@ class MinefieldCreator(
} }
} }
fun createEmpty(): List<dev.lucasnlm.antimine.core.models.Area> { fun createEmpty(): List<Area> {
return createMutableEmpty() 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 { return createMutableEmpty().toMutableList().apply {
// Plant mines and setup number tips // Plant mines and setup number tips
if (safeZone) { filterNotNeighborsOf(safeIndex) } else { filterNot { it.id == safeIndex } } if (safeZone) { filterNotNeighborsOf(safeIndex) } else { filterNot { it.id == safeIndex } }

View file

@ -4,17 +4,17 @@ import dev.lucasnlm.antimine.core.models.Area
import dev.lucasnlm.antimine.core.models.Mark import dev.lucasnlm.antimine.core.models.Mark
class MinefieldHandler( class MinefieldHandler(
private val field: MutableList<dev.lucasnlm.antimine.core.models.Area>, private val field: MutableList<Area>,
private val useQuestionMark: Boolean, private val useQuestionMark: Boolean,
) { ) {
fun showAllMines() { 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) } .forEach { field[it.id] = it.copy(isCovered = false) }
} }
fun flagAllMines() { fun flagAllMines() {
field.filter { it.hasMine } 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() { fun revealAllEmptyAreas() {
@ -36,7 +36,7 @@ class MinefieldHandler(
fun removeMarkAt(index: Int) { fun removeMarkAt(index: Int) {
field.getOrNull(index)?.let { 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) { if (it.isCovered) {
field[index] = it.copy( field[index] = it.copy(
mark = when (it.mark) { 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 Mark.PurposefulNone, Mark.None -> 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 Mark.Flag -> if (useQuestionMark) Mark.Question else Mark.None
dev.lucasnlm.antimine.core.models.Mark.Question -> dev.lucasnlm.antimine.core.models.Mark.None Mark.Question -> Mark.None
} }
) )
} }
@ -59,7 +59,7 @@ class MinefieldHandler(
if (isCovered) { if (isCovered) {
field[index] = copy( field[index] = copy(
isCovered = false, isCovered = false,
mark = dev.lucasnlm.antimine.core.models.Mark.None, mark = Mark.None,
mistake = (!passive && hasMine) || (!hasMine && mark.isFlag()) 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()
} }

View file

@ -7,6 +7,6 @@ sealed class Status {
class Over( class Over(
val time: Long = 0L, val time: Long = 0L,
val score: dev.lucasnlm.antimine.core.models.Score? = null, val score: Score? = null,
) : Status() ) : Status()
} }

View file

@ -4,7 +4,7 @@ import dev.lucasnlm.antimine.common.level.logic.MinefieldHandler
import dev.lucasnlm.antimine.core.models.Area import dev.lucasnlm.antimine.core.models.Area
open class BruteForceSolver : GameSolver() { 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) val minefieldHandler = MinefieldHandler(minefield, false)
do { do {

View file

@ -12,5 +12,5 @@ abstract class GameSolver {
* Try solve the given [minefield]. * Try solve the given [minefield].
* Returns true if it's solvable or false otherwise. * 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
} }

View file

@ -59,7 +59,7 @@ open class GameViewModel(
private var initialized = false private var initialized = false
private var currentDifficulty: Difficulty = Difficulty.Standard 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 elapsedTimeSeconds = MutableLiveData<Long>()
val mineCount = MutableLiveData<Int>() val mineCount = MutableLiveData<Int>()
val difficulty = MutableLiveData<Difficulty>() val difficulty = MutableLiveData<Difficulty>()
@ -90,7 +90,7 @@ open class GameViewModel(
eventObserver.postValue(Event.StartNewGame) eventObserver.postValue(Event.StartNewGame)
analyticsManager.sentEvent( analyticsManager.sentEvent(
dev.lucasnlm.antimine.core.models.Analytics.NewGame( Analytics.NewGame(
minefield, minefield,
newDifficulty, newDifficulty,
gameController.seed, gameController.seed,
@ -123,7 +123,7 @@ open class GameViewModel(
} }
saveId.postValue(save.uid.toLong()) saveId.postValue(save.uid.toLong())
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.ResumePreviousGame) analyticsManager.sentEvent(Analytics.ResumePreviousGame)
return setup return setup
} }
@ -144,7 +144,7 @@ open class GameViewModel(
eventObserver.postValue(Event.ResumeGame) eventObserver.postValue(Event.ResumeGame)
analyticsManager.sentEvent( analyticsManager.sentEvent(
dev.lucasnlm.antimine.core.models.Analytics.RetryGame( Analytics.RetryGame(
setup, setup,
currentDifficulty, currentDifficulty,
gameController.seed, gameController.seed,
@ -310,19 +310,19 @@ open class GameViewModel(
private fun onFeedbackAnalytics(action: ActionResponse, index: Int) { private fun onFeedbackAnalytics(action: ActionResponse, index: Int) {
when (action) { when (action) {
ActionResponse.OpenTile -> { ActionResponse.OpenTile -> {
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.OpenTile(index)) analyticsManager.sentEvent(Analytics.OpenTile(index))
} }
ActionResponse.SwitchMark -> { ActionResponse.SwitchMark -> {
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.SwitchMark(index)) analyticsManager.sentEvent(Analytics.SwitchMark(index))
} }
ActionResponse.HighlightNeighbors -> { ActionResponse.HighlightNeighbors -> {
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.HighlightNeighbors(index)) analyticsManager.sentEvent(Analytics.HighlightNeighbors(index))
} }
ActionResponse.OpenNeighbors -> { ActionResponse.OpenNeighbors -> {
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.OpenNeighbors(index)) analyticsManager.sentEvent(Analytics.OpenNeighbors(index))
} }
ActionResponse.OpenOrMark -> { 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) { suspend fun gameOver(fromResumeGame: Boolean) {
gameController.run { gameController.run {
analyticsManager.sentEvent(dev.lucasnlm.antimine.core.models.Analytics.GameOver(clock.time(), getScore())) analyticsManager.sentEvent(Analytics.GameOver(clock.time(), getScore()))
if (!fromResumeGame) { if (!fromResumeGame) {
if (preferencesRepository.useHapticFeedback()) { if (preferencesRepository.useHapticFeedback()) {
@ -473,7 +473,7 @@ open class GameViewModel(
fun victory() { fun victory() {
gameController.run { gameController.run {
analyticsManager.sentEvent( analyticsManager.sentEvent(
dev.lucasnlm.antimine.core.models.Analytics.Victory( Analytics.Victory(
clock.time(), clock.time(),
getScore(), getScore(),
currentDifficulty currentDifficulty

View file

@ -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()) { val message = if (event.extra.isNotEmpty()) {
"Sent event: '${event.name}' with ${event.extra}" "Sent event: '${event.name}' with ${event.extra}"
} else { } else {

View file

@ -12,7 +12,7 @@ class ProdAnalyticsManager(
analyticsWrapper.setup(context, properties) 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) analyticsWrapper.sendEvent(event.name, event.extra)
} }
} }

View file

@ -66,39 +66,39 @@ class AreaConverterTest {
private val areaList = private val areaList =
listOf( listOf(
dev.lucasnlm.antimine.core.models.Area( Area(
1, 2, 3, 5, 1, 2, 3, 5,
hasMine = false, hasMine = false,
mistake = false, mistake = false,
isCovered = true, isCovered = true,
mark = dev.lucasnlm.antimine.core.models.Mark.None, mark = Mark.None,
highlighted = true, highlighted = true,
revealed = false, revealed = false,
), ),
dev.lucasnlm.antimine.core.models.Area( Area(
2, 5, 3, 0, 2, 5, 3, 0,
hasMine = true, hasMine = true,
mistake = true, mistake = true,
isCovered = false, isCovered = false,
mark = dev.lucasnlm.antimine.core.models.Mark.PurposefulNone, mark = Mark.PurposefulNone,
highlighted = false, highlighted = false,
revealed = false, revealed = false,
), ),
dev.lucasnlm.antimine.core.models.Area( Area(
3, 1, 1, 3, 3, 1, 1, 3,
hasMine = true, hasMine = true,
mistake = false, mistake = false,
isCovered = true, isCovered = true,
mark = dev.lucasnlm.antimine.core.models.Mark.Flag, mark = Mark.Flag,
highlighted = true, highlighted = true,
revealed = false, revealed = false,
), ),
dev.lucasnlm.antimine.core.models.Area( Area(
4, 0, 0, 6, 4, 0, 0, 6,
hasMine = false, hasMine = false,
mistake = false, mistake = false,
isCovered = true, isCovered = true,
mark = dev.lucasnlm.antimine.core.models.Mark.Question, mark = Mark.Question,
highlighted = true, highlighted = true,
revealed = true, revealed = true,
) )

View file

@ -39,7 +39,7 @@ class GameControllerTest {
@Test @Test
fun testGetScore() = runBlockingTest { fun testGetScore() = runBlockingTest {
withGameController { controller -> withGameController { controller ->
assertEquals(dev.lucasnlm.antimine.core.models.Score(0, 20, 100), controller.getScore()) assertEquals(Score(0, 20, 100), controller.getScore())
repeat(20) { markedMines -> repeat(20) { markedMines ->
controller controller
@ -51,7 +51,7 @@ class GameControllerTest {
controller.fakeLongPress(it.id) 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 @Test
fun testGetScoreWithQuestion() = runBlockingTest { fun testGetScoreWithQuestion() = runBlockingTest {
withGameController { controller -> 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.useQuestionMark(true)
controller controller
@ -71,7 +71,7 @@ class GameControllerTest {
controller.fakeLongPress(it.id) 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 } return this.field().first { it.id == index }
} }

View file

@ -26,7 +26,7 @@ class MinefieldHandlerTest {
assertTrue(handler.result()[3].isCovered) assertTrue(handler.result()[3].isCovered)
handler.openAt(3, false, openNeighbors = false) handler.openAt(3, false, openNeighbors = false)
assertFalse(handler.result()[3].isCovered) 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) assertTrue(handler.result()[3].isCovered)
handler.openAt(3, false, openNeighbors = false) handler.openAt(3, false, openNeighbors = false)
assertFalse(handler.result()[3].isCovered) 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.switchMarkAt(3)
handler.removeMarkAt(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()) assertTrue(handler.result()[3].mark.isNone())
} }
} }

View file

@ -12,6 +12,9 @@ import android.view.MotionEvent
import android.view.View import android.view.View
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.ViewCompat 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.R
import dev.lucasnlm.antimine.ui.model.AppTheme import dev.lucasnlm.antimine.ui.model.AppTheme
@ -20,8 +23,8 @@ class AreaView : View {
private var isAmbientMode: Boolean = false private var isAmbientMode: Boolean = false
private var isLowBitAmbient: Boolean = false private var isLowBitAmbient: Boolean = false
private var area: dev.lucasnlm.antimine.core.models.Area? = null private var area: Area? = null
private lateinit var paintSettings: dev.lucasnlm.antimine.core.models.AreaPaintSettings private lateinit var paintSettings: AreaPaintSettings
private lateinit var theme: AppTheme private lateinit var theme: AppTheme
private val gestureDetector: GestureDetector by lazy { private val gestureDetector: GestureDetector by lazy {
@ -46,11 +49,11 @@ class AreaView : View {
} }
fun bindField( fun bindField(
area: dev.lucasnlm.antimine.core.models.Area, area: Area,
theme: AppTheme, theme: AppTheme,
isAmbientMode: Boolean, isAmbientMode: Boolean,
isLowBitAmbient: Boolean, isLowBitAmbient: Boolean,
paintSettings: dev.lucasnlm.antimine.core.models.AreaPaintSettings paintSettings: AreaPaintSettings
) { ) {
this.paintSettings = paintSettings this.paintSettings = paintSettings
@ -84,12 +87,12 @@ class AreaView : View {
override fun onTouchEvent(event: MotionEvent?): Boolean = override fun onTouchEvent(event: MotionEvent?): Boolean =
gestureDetector.onTouchEvent(event) || super.onTouchEvent(event) gestureDetector.onTouchEvent(event) || super.onTouchEvent(event)
private fun bindContentDescription(area: dev.lucasnlm.antimine.core.models.Area) { private fun bindContentDescription(area: Area) {
contentDescription = when { 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) 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 -> context.getString(R.string.desc_convered_area)
!area.isCovered && area.minesAround > 0 -> area.minesAround.toString() !area.isCovered && area.minesAround > 0 -> area.minesAround.toString()
!area.isCovered && area.hasMine -> context.getString(R.string.exploded_mine) !area.isCovered && area.hasMine -> context.getString(R.string.exploded_mine)