Moved classes from data to models folder

This commit is contained in:
Lucas Lima 2020-03-17 01:35:41 -03:00
parent 2effaddc15
commit 63e6750b0f
35 changed files with 274 additions and 99 deletions

View file

@ -27,7 +27,7 @@ import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.UpdateAvailability
import dagger.android.support.DaggerAppCompatActivity
import dev.lucasnlm.antimine.about.AboutActivity
import dev.lucasnlm.antimine.common.level.data.*
import dev.lucasnlm.antimine.common.level.models.*
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory
import dev.lucasnlm.antimine.core.analytics.AnalyticsManager
@ -436,7 +436,11 @@ class GameActivity : DaggerAppCompatActivity() {
invalidateOptionsMenu()
}
Event.Victory -> {
val score = Score(rightMines, totalMines, totalArea)
val score = Score(
rightMines,
totalMines,
totalArea
)
status = Status.Over(currentTime, score)
viewModel.stopClock()
viewModel.revealAllEmptyAreas()
@ -445,7 +449,11 @@ class GameActivity : DaggerAppCompatActivity() {
waitAndShowEndGameDialog(true, 0L)
}
Event.GameOver -> {
val score = Score(rightMines, totalMines, totalArea)
val score = Score(
rightMines,
totalMines,
totalArea
)
status = Status.Over(currentTime, score)
invalidateOptionsMenu()
viewModel.stopClock()
@ -454,7 +462,11 @@ class GameActivity : DaggerAppCompatActivity() {
waitAndShowEndGameDialog(false)
}
Event.ResumeVictory -> {
val score = Score(rightMines, totalMines, totalArea)
val score = Score(
rightMines,
totalMines,
totalArea
)
status = Status.Over(currentTime, score)
invalidateOptionsMenu()
viewModel.stopClock()
@ -462,7 +474,11 @@ class GameActivity : DaggerAppCompatActivity() {
waitAndShowEndGameDialog(true)
}
Event.ResumeGameOver -> {
val score = Score(rightMines, totalMines, totalArea)
val score = Score(
rightMines,
totalMines,
totalArea
)
status = Status.Over(currentTime, score)
invalidateOptionsMenu()
viewModel.stopClock()

View file

@ -21,7 +21,7 @@ import com.google.android.play.core.install.model.AppUpdateType
import com.google.android.play.core.install.model.UpdateAvailability
import dagger.android.support.DaggerAppCompatActivity
import dev.lucasnlm.antimine.about.AboutActivity
import dev.lucasnlm.antimine.common.level.data.*
import dev.lucasnlm.antimine.common.level.models.*
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
@ -279,7 +279,11 @@ class TvGameActivity : DaggerAppCompatActivity() {
invalidateOptionsMenu()
}
Event.Victory -> {
val score = Score(rightMines, totalMines, totalArea)
val score = Score(
rightMines,
totalMines,
totalArea
)
status = Status.Over(currentTime, score)
viewModel.stopClock()
viewModel.revealAllEmptyAreas()
@ -287,7 +291,11 @@ class TvGameActivity : DaggerAppCompatActivity() {
showVictory()
}
Event.GameOver -> {
val score = Score(rightMines, totalMines, totalArea)
val score = Score(
rightMines,
totalMines,
totalArea
)
status = Status.Over(currentTime, score)
invalidateOptionsMenu()
viewModel.stopClock()
@ -296,7 +304,11 @@ class TvGameActivity : DaggerAppCompatActivity() {
waitAndShowGameOverConfirmNewGame()
}
Event.ResumeVictory, Event.ResumeGameOver -> {
val score = Score(rightMines, totalMines, totalArea)
val score = Score(
rightMines,
totalMines,
totalArea
)
status = Status.Over(currentTime, score)
invalidateOptionsMenu()
viewModel.stopClock()

View file

@ -8,8 +8,8 @@ import androidx.lifecycle.ViewModelProviders
import dagger.android.support.DaggerAppCompatDialogFragment
import dev.lucasnlm.antimine.R
import dev.lucasnlm.antimine.common.level.data.DifficultyPreset
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
import dev.lucasnlm.antimine.common.level.models.Minefield
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
@ -71,7 +71,13 @@ class CustomLevelDialogFragment : DaggerAppCompatDialogFragment() {
height = height.coerceAtMost(50)
mines = mines.coerceAtLeast(1)
preferencesRepository.updateCustomGameMode(Minefield(width, height, mines))
preferencesRepository.updateCustomGameMode(
Minefield(
width,
height,
mines
)
)
GlobalScope.launch(Dispatchers.IO) {
viewModel.startNewGame(DifficultyPreset.Custom)

View file

@ -11,8 +11,8 @@ 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.data.DifficultyPreset
import dev.lucasnlm.antimine.common.level.data.Event
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
import dev.lucasnlm.antimine.common.level.models.Event
import dev.lucasnlm.antimine.common.level.view.AreaAdapter
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory

View file

@ -12,10 +12,10 @@ import android.graphics.Typeface
import androidx.core.content.FileProvider
import dev.lucasnlm.antimine.BuildConfig
import dev.lucasnlm.antimine.R
import dev.lucasnlm.antimine.common.level.data.Area
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.data.Mark
import dev.lucasnlm.antimine.common.level.model.AreaPalette
import dev.lucasnlm.antimine.common.level.models.Area
import dev.lucasnlm.antimine.common.level.models.Minefield
import dev.lucasnlm.antimine.common.level.models.Mark
import dev.lucasnlm.antimine.common.level.models.AreaPalette
import dev.lucasnlm.antimine.common.level.repository.DrawableRepository
import dev.lucasnlm.antimine.common.level.view.AreaPaintSettings
import dev.lucasnlm.antimine.common.level.view.paintOnCanvas

View file

@ -5,8 +5,8 @@ import android.widget.Toast
import androidx.lifecycle.AndroidViewModel
import dev.lucasnlm.antimine.R
import dev.lucasnlm.antimine.share.ShareBuilder
import dev.lucasnlm.antimine.common.level.data.Area
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.models.Area
import dev.lucasnlm.antimine.common.level.models.Minefield
class ShareViewModel(
application: Application

View file

@ -6,9 +6,9 @@ import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import androidx.test.platform.app.InstrumentationRegistry
import dev.lucasnlm.antimine.common.level.data.Area
import dev.lucasnlm.antimine.common.level.data.Mark
import dev.lucasnlm.antimine.common.level.model.AreaPalette
import dev.lucasnlm.antimine.common.level.models.Area
import dev.lucasnlm.antimine.common.level.models.Mark
import dev.lucasnlm.antimine.common.level.models.AreaPalette
import dev.lucasnlm.antimine.common.level.repository.DrawableRepository
import dev.lucasnlm.antimine.common.level.view.AreaAdapter
import dev.lucasnlm.antimine.common.level.view.paintOnCanvas
@ -115,7 +115,13 @@ class AreaScreenshot {
repeat(8) {
val id = it + 1
screenshotTest(
Area(0, 0, 0, isCovered = false, minesAround = id),
Area(
0,
0,
0,
isCovered = false,
minesAround = id
),
"mines_around_$id.png"
)
}
@ -126,7 +132,13 @@ class AreaScreenshot {
repeat(8) {
val id = it + 1
screenshotTest(
Area(0, 0, 0, isCovered = false, minesAround = id),
Area(
0,
0,
0,
isCovered = false,
minesAround = id
),
"mines_around_${id}_ambient.png",
true
)
@ -135,85 +147,173 @@ class AreaScreenshot {
@Test
fun testCoveredAreaWithFlag() {
val area = Area(0, 0, 0, isCovered = true, mark = Mark.Flag)
val area = Area(
0,
0,
0,
isCovered = true,
mark = Mark.Flag
)
screenshotTest(area, "covered_flag.png")
}
@Test
fun testCoveredAreaWithFlagAmbient() {
val area = Area(0, 0, 0, isCovered = true, mark = Mark.Flag)
val area = Area(
0,
0,
0,
isCovered = true,
mark = Mark.Flag
)
screenshotTest(area, "covered_flag_ambient.png", true)
}
@Test
fun testCoveredAreaWithQuestion() {
val area = Area(0, 0, 0, isCovered = true, mark = Mark.Question)
val area = Area(
0,
0,
0,
isCovered = true,
mark = Mark.Question
)
screenshotTest(area, "covered_question.png")
}
@Test
fun testCoveredAreaWithQuestionAmbient() {
val area = Area(0, 0, 0, isCovered = true, mark = Mark.Question)
val area = Area(
0,
0,
0,
isCovered = true,
mark = Mark.Question
)
screenshotTest(area, "covered_question_ambient.png", true)
}
@Test
fun testCoveredAreaHighlighted() {
val area = Area(0, 0, 0, isCovered = true, highlighted = true)
val area = Area(
0,
0,
0,
isCovered = true,
highlighted = true
)
screenshotTest(area, "covered_highlighted.png")
}
@Test
fun testCoveredAreaHighlightedAmbient() {
val area = Area(0, 0, 0, isCovered = true, highlighted = true)
val area = Area(
0,
0,
0,
isCovered = true,
highlighted = true
)
screenshotTest(area, "covered_highlighted_ambient.png", true)
}
@Test
fun testCoveredAreaWithMine() {
val area = Area(0, 0, 0, isCovered = true, hasMine = true)
val area = Area(
0,
0,
0,
isCovered = true,
hasMine = true
)
screenshotTest(area, "covered_mine.png")
}
@Test
fun testCoveredAreaWithMineAmbient() {
val area = Area(0, 0, 0, isCovered = true, hasMine = true)
val area = Area(
0,
0,
0,
isCovered = true,
hasMine = true
)
screenshotTest(area, "covered_mine_ambient.png", true)
}
@Test
fun testUncoveredAreaWithMine() {
val area = Area(0, 0, 0, isCovered = false, hasMine = true)
val area = Area(
0,
0,
0,
isCovered = false,
hasMine = true
)
screenshotTest(area, "uncovered_mine.png")
}
@Test
fun testUncoveredAreaWithMineAmbient() {
val area = Area(0, 0, 0, isCovered = false, hasMine = true)
val area = Area(
0,
0,
0,
isCovered = false,
hasMine = true
)
screenshotTest(area, "uncovered_mine_ambient.png", true)
}
@Test
fun testUncoveredAreaHighlighted() {
val area = Area(0, 0, 0, isCovered = false, hasMine = false, highlighted = true)
val area = Area(
0,
0,
0,
isCovered = false,
hasMine = false,
highlighted = true
)
screenshotTest(area, "uncovered_highlighted.png")
}
@Test
fun testUncoveredAreaHighlightedAmbient() {
val area = Area(0, 0, 0, isCovered = false, hasMine = false, highlighted = true)
val area = Area(
0,
0,
0,
isCovered = false,
hasMine = false,
highlighted = true
)
screenshotTest(area, "uncovered_highlighted_ambient.png", true)
}
@Test
fun testUncoveredAreaWithMineExploded() {
val area = Area(0, 0, 0, isCovered = false, hasMine = true, mistake = true)
val area = Area(
0,
0,
0,
isCovered = false,
hasMine = true,
mistake = true
)
screenshotTest(area, "uncovered_mine_exploded.png")
}
@Test
fun testUncoveredAreaWithMineExplodedAmbient() {
val area = Area(0, 0, 0, isCovered = false, hasMine = true, mistake = true)
val area = Area(
0,
0,
0,
isCovered = false,
hasMine = true,
mistake = true
)
screenshotTest(area, "uncovered_mine_exploded_ambient.png", true)
}
@ -222,7 +322,14 @@ class AreaScreenshot {
repeat(8) {
val id = it + 1
screenshotTest(
Area(0, 0, 0, isCovered = false, minesAround = id, highlighted = true),
Area(
0,
0,
0,
isCovered = false,
minesAround = id,
highlighted = true
),
"mines_around_highlighted_$id.png"
)
}
@ -233,7 +340,14 @@ class AreaScreenshot {
repeat(8) {
val id = it + 1
screenshotTest(
Area(0, 0, 0, isCovered = false, minesAround = id, highlighted = true),
Area(
0,
0,
0,
isCovered = false,
minesAround = id,
highlighted = true
),
"mines_around_highlighted_${id}_ambient.png",
true
)

View file

@ -1,7 +1,7 @@
package dev.lucasnlm.antimine.common.level
import dev.lucasnlm.antimine.common.level.data.DifficultyPreset
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
import dev.lucasnlm.antimine.common.level.models.Minefield
import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
@ -13,9 +13,21 @@ object GameModeFactory {
): Minefield =
when (difficulty) {
DifficultyPreset.Standard -> calculateStandardMode(dimensionRepository)
DifficultyPreset.Beginner -> Minefield(9, 9, 10)
DifficultyPreset.Intermediate -> Minefield(16, 16, 40)
DifficultyPreset.Expert -> Minefield(24, 24, 99)
DifficultyPreset.Beginner -> Minefield(
9,
9,
10
)
DifficultyPreset.Intermediate -> Minefield(
16,
16,
40
)
DifficultyPreset.Expert -> Minefield(
24,
24,
99
)
DifficultyPreset.Custom -> preferencesRepository.customGameMode()
}

View file

@ -1,8 +1,8 @@
package dev.lucasnlm.antimine.common.level
import dev.lucasnlm.antimine.common.level.data.*
import dev.lucasnlm.antimine.common.level.database.models.Save
import dev.lucasnlm.antimine.common.level.database.models.SaveStatus
import dev.lucasnlm.antimine.common.level.models.*
import java.util.Random
import kotlin.math.floor
@ -187,10 +187,10 @@ class LevelFacade {
}
fun getStats() = Score(
mines.filter { !it.mistake && it.mark == Mark.Flag }.count(),
mines.count(),
field.count()
)
mines.filter { !it.mistake && it.mark == Mark.Flag }.count(),
mines.count(),
field.count()
)
fun showAllMines() {
mines.filter { it.mark != Mark.Flag }.forEach { it.isCovered = false }

View file

@ -1,7 +1,7 @@
package dev.lucasnlm.antimine.common.level.database.converters
import androidx.room.TypeConverter
import dev.lucasnlm.antimine.common.level.data.DifficultyPreset
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
class DifficultyConverter {

View file

@ -5,7 +5,7 @@ import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import dev.lucasnlm.antimine.common.level.data.Area
import dev.lucasnlm.antimine.common.level.models.Area
import java.lang.reflect.Type
class FieldConverter {

View file

@ -4,15 +4,20 @@ import androidx.room.TypeConverter
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.models.Minefield
class MinefieldConverter {
private val moshi: Moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
private val jsonAdapter: JsonAdapter<Minefield> = moshi.adapter(Minefield::class.java)
private val jsonAdapter: JsonAdapter<Minefield> = moshi.adapter(
Minefield::class.java)
@TypeConverter
fun toMinefield(jsonInput: String): Minefield =
jsonAdapter.fromJson(jsonInput) ?: Minefield(9,9, 9)
jsonAdapter.fromJson(jsonInput) ?: Minefield(
9,
9,
9
)
@TypeConverter
fun toJsonString(field: Minefield): String = jsonAdapter.toJson(field)

View file

@ -4,9 +4,9 @@ import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import dev.lucasnlm.antimine.common.level.data.Area
import dev.lucasnlm.antimine.common.level.data.DifficultyPreset
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.models.Area
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
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

View file

@ -6,7 +6,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.room.Room
import dagger.Module
import dagger.Provides
import dev.lucasnlm.antimine.common.level.data.Event
import dev.lucasnlm.antimine.common.level.models.Event
import dev.lucasnlm.antimine.common.level.database.AppDataBase
import dev.lucasnlm.antimine.common.level.database.dao.SaveDao
import dev.lucasnlm.antimine.common.level.repository.DimensionRepository

View file

@ -1,4 +1,4 @@
package dev.lucasnlm.antimine.common.level.data
package dev.lucasnlm.antimine.common.level.models
data class AmbientSettings(
val isAmbientMode: Boolean = false,

View file

@ -1,4 +1,4 @@
package dev.lucasnlm.antimine.common.level.data
package dev.lucasnlm.antimine.common.level.models
data class Area(
val id: Int,

View file

@ -1,4 +1,4 @@
package dev.lucasnlm.antimine.common.level.model
package dev.lucasnlm.antimine.common.level.models
import android.content.Context
import android.graphics.Color

View file

@ -1,4 +1,4 @@
package dev.lucasnlm.antimine.common.level.data
package dev.lucasnlm.antimine.common.level.models
enum class DifficultyPreset(
val text: String

View file

@ -1,4 +1,4 @@
package dev.lucasnlm.antimine.common.level.data
package dev.lucasnlm.antimine.common.level.models
enum class Event {
StartNewGame,

View file

@ -1,4 +1,4 @@
package dev.lucasnlm.antimine.common.level.data
package dev.lucasnlm.antimine.common.level.models
enum class Mark {
None,

View file

@ -1,4 +1,4 @@
package dev.lucasnlm.antimine.common.level.data
package dev.lucasnlm.antimine.common.level.models
data class Minefield(
val width: Int,

View file

@ -1,4 +1,4 @@
package dev.lucasnlm.antimine.common.level.data
package dev.lucasnlm.antimine.common.level.models
data class Score(
val rightMines: Int,

View file

@ -1,4 +1,4 @@
package dev.lucasnlm.antimine.common.level.data
package dev.lucasnlm.antimine.common.level.models
sealed class Status {
object PreGame : Status()

View file

@ -9,7 +9,7 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import dev.lucasnlm.antimine.common.R
import dev.lucasnlm.antimine.common.level.data.Area
import dev.lucasnlm.antimine.common.level.models.Area
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
class AreaAdapter(

View file

@ -5,9 +5,9 @@ import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.RectF
import dev.lucasnlm.antimine.common.R
import dev.lucasnlm.antimine.common.level.data.Area
import dev.lucasnlm.antimine.common.level.data.Mark
import dev.lucasnlm.antimine.common.level.model.AreaPalette
import dev.lucasnlm.antimine.common.level.models.Area
import dev.lucasnlm.antimine.common.level.models.Mark
import dev.lucasnlm.antimine.common.level.models.AreaPalette
import dev.lucasnlm.antimine.common.level.repository.DrawableRepository
fun Area.paintOnCanvas(

View file

@ -6,15 +6,15 @@ import android.graphics.Canvas
import androidx.core.content.ContextCompat
import android.util.AttributeSet
import android.view.View
import dev.lucasnlm.antimine.common.level.data.Area
import dev.lucasnlm.antimine.common.level.models.Area
import dev.lucasnlm.antimine.common.level.repository.DrawableRepository
import android.util.TypedValue
import android.graphics.drawable.Drawable
import android.os.Build
import androidx.core.view.ViewCompat
import dev.lucasnlm.antimine.common.R
import dev.lucasnlm.antimine.common.level.data.Mark
import dev.lucasnlm.antimine.common.level.model.AreaPalette
import dev.lucasnlm.antimine.common.level.models.Mark
import dev.lucasnlm.antimine.common.level.models.AreaPalette
class AreaView : View {
// Used on Wear OS

View file

@ -5,10 +5,10 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import dev.lucasnlm.antimine.common.level.GameModeFactory
import dev.lucasnlm.antimine.common.level.LevelFacade
import dev.lucasnlm.antimine.common.level.data.Area
import dev.lucasnlm.antimine.common.level.data.DifficultyPreset
import dev.lucasnlm.antimine.common.level.data.Event
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.models.Area
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
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
import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
import dev.lucasnlm.antimine.common.level.repository.ISavesRepository

View file

@ -4,7 +4,7 @@ import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import dev.lucasnlm.antimine.common.level.data.Event
import dev.lucasnlm.antimine.common.level.models.Event
import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
import dev.lucasnlm.antimine.common.level.repository.ISavesRepository
import dev.lucasnlm.antimine.common.level.utils.Clock

View file

@ -1,8 +1,8 @@
package dev.lucasnlm.antimine.core.analytics.models
import dev.lucasnlm.antimine.common.level.data.DifficultyPreset
import dev.lucasnlm.antimine.common.level.data.Score
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
import dev.lucasnlm.antimine.common.level.models.Score
import dev.lucasnlm.antimine.common.level.models.Minefield
sealed class Analytics(
val title: String,

View file

@ -2,7 +2,7 @@ package dev.lucasnlm.antimine.core.preferences
import android.app.Application
import androidx.preference.PreferenceManager
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.models.Minefield
import javax.inject.Inject
class PreferencesInteractor @Inject constructor(

View file

@ -1,6 +1,6 @@
package dev.lucasnlm.antimine.core.preferences
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.models.Minefield
interface IPreferencesRepository {
fun customGameMode(): Minefield

View file

@ -1,8 +1,8 @@
package dev.lucasnlm.antimine.common.level
import dev.lucasnlm.antimine.common.level.data.Area
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.data.Mark
import dev.lucasnlm.antimine.common.level.models.Area
import dev.lucasnlm.antimine.common.level.models.Minefield
import dev.lucasnlm.antimine.common.level.models.Mark
import dev.lucasnlm.antimine.common.level.data.isFlag
import dev.lucasnlm.antimine.common.level.data.isQuestion
import org.junit.Assert.assertEquals
@ -14,7 +14,8 @@ import org.junit.Test
class LevelFacadeTest {
private fun levelFacadeOf(width: Int, height: Int, mines: Int, seed: Long = 0L) =
LevelFacade(0, Minefield(width, height, mines), seed)
LevelFacade(0,
Minefield(width, height, mines), seed)
private fun LevelFacade.at(id: Int): Area = field.first { it.id == id }

View file

@ -3,8 +3,8 @@ 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.data.DifficultyPreset
import dev.lucasnlm.antimine.common.level.data.Minefield
import dev.lucasnlm.antimine.common.level.models.DifficultyPreset
import dev.lucasnlm.antimine.common.level.models.Minefield
import dev.lucasnlm.antimine.common.level.repository.IDimensionRepository
import dev.lucasnlm.antimine.core.preferences.IPreferencesRepository
import org.junit.Assert.assertEquals
@ -50,7 +50,11 @@ class MinefieldFactoryTest {
@Test
fun testFromDifficultyPresetCustom() {
val preferencesRepository: IPreferencesRepository = mock {
on { customGameMode() } doReturn Minefield(10, 10, 30)
on { customGameMode() } doReturn Minefield(
10,
10,
30
)
}
GameModeFactory.fromDifficultyPreset(

View file

@ -8,7 +8,7 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.wear.widget.SwipeDismissFrameLayout
import dagger.android.support.DaggerAppCompatActivity
import dev.lucasnlm.antimine.common.level.data.Status
import dev.lucasnlm.antimine.common.level.models.Status
import dev.lucasnlm.antimine.common.level.utils.Clock
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory
@ -22,8 +22,8 @@ import androidx.wear.ambient.AmbientModeSupport
import androidx.wear.ambient.AmbientModeSupport.AmbientCallback
import androidx.wear.ambient.AmbientModeSupport.EXTRA_LOWBIT_AMBIENT
import dev.lucasnlm.antimine.R
import dev.lucasnlm.antimine.common.level.data.AmbientSettings
import dev.lucasnlm.antimine.common.level.data.Event
import dev.lucasnlm.antimine.common.level.models.AmbientSettings
import dev.lucasnlm.antimine.common.level.models.Event
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@ -59,7 +59,12 @@ class WatchGameActivity : DaggerAppCompatActivity(), AmbientModeSupport.AmbientC
override fun onEnterAmbient(ambientDetails: Bundle?) {
super.onEnterAmbient(ambientDetails)
val lowBit = ambientDetails?.getBoolean(EXTRA_LOWBIT_AMBIENT) ?: true
currentLevelFragment?.setAmbientMode(AmbientSettings(true, lowBit))
currentLevelFragment?.setAmbientMode(
AmbientSettings(
true,
lowBit
)
)
updateClockText(true)
}
}

View file

@ -10,8 +10,8 @@ import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import dev.lucasnlm.antimine.common.R
import dagger.android.support.DaggerFragment
import dev.lucasnlm.antimine.common.level.data.AmbientSettings
import dev.lucasnlm.antimine.common.level.data.Event
import dev.lucasnlm.antimine.common.level.models.AmbientSettings
import dev.lucasnlm.antimine.common.level.models.Event
import dev.lucasnlm.antimine.common.level.view.AreaAdapter
import dev.lucasnlm.antimine.common.level.view.UnlockedHorizontalScrollView
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel