Skip to content

Commit

Permalink
Merge pull request #284 from lucasnlm/update-strings
Browse files Browse the repository at this point in the history
Update strings
  • Loading branch information
lucasnlm authored May 29, 2021
2 parents 564ebd6 + b0959a6 commit ac22e00
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 94 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {

defaultConfig {
// versionCode and versionName must be hardcoded to support F-droid
versionCode 1003001
versionName '10.3.0'
versionCode 1101001
versionName '11.1.0'
minSdkVersion 21
targetSdkVersion 30
multiDexEnabled true
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/dev/lucasnlm/antimine/GameActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import dev.lucasnlm.antimine.gameover.GameOverDialogFragment
import dev.lucasnlm.antimine.gameover.WinGameDialogFragment
import dev.lucasnlm.antimine.gameover.model.GameResult
import dev.lucasnlm.antimine.common.level.view.GdxLevelFragment
import dev.lucasnlm.antimine.gdx.GdxLocal
import dev.lucasnlm.antimine.main.MainActivity
import dev.lucasnlm.antimine.preferences.IPreferencesRepository
import dev.lucasnlm.antimine.splash.SplashActivity
Expand Down Expand Up @@ -74,6 +75,9 @@ class GameActivity :
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intent?.run(::handleIntent)

GdxLocal.zoom = 1.0f
GdxLocal.zoomLevelAlpha = 1.0f
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class StatsViewModel(
}

private fun isMaster(stats: Stats): Boolean {
return stats.mines == 200 && stats.width == 50 && stats.height == 50
return (stats.mines == 200 || stats.mines == 300) && stats.width == 50 && stats.height == 50
}

private fun isIntermediate(stats: Stats): Boolean {
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies {
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.2.0'
implementation 'androidx.activity:activity-ktx:1.2.3'
implementation "androidx.fragment:fragment-ktx:1.3.3"
implementation 'androidx.fragment:fragment-ktx:1.3.4'

// Google
implementation 'com.google.android.material:material:1.3.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MinefieldRepository : IMinefieldRepository {
private val beginnerMinefield = Minefield(9, 9, 10)
private val intermediateMinefield = Minefield(16, 16, 40)
private val expertMinefield = Minefield(24, 24, 99)
private val masterMinefield = Minefield(50, 50, 200)
private val masterMinefield = Minefield(50, 50, 300)

private const val CUSTOM_LEVEL_MINE_RATIO = 0.2
private const val MAX_LEVEL_MINE_RATIO = 0.45
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,15 @@ open class GdxLevelFragment : AndroidFragmentApplication() {

override fun onResume() {
super.onResume()
levelApplicationListener.refreshSettings()
levelApplicationListener.apply {
refreshSettings()
refreshZoom()
}

view?.let {
bindControlSwitcherIfNeeded(it)
if (preferencesRepository.controlStyle() == ControlStyle.SwitchMarkOpen) {
view?.let {
bindControlSwitcherIfNeeded(it)
}
}
}

Expand All @@ -122,6 +127,10 @@ open class GdxLevelFragment : AndroidFragmentApplication() {
.collect {
GdxLocal.currentFocus = null
levelApplicationListener.recenter()

if (preferencesRepository.controlStyle() == ControlStyle.SwitchMarkOpen) {
bindControlSwitcherIfNeeded(view)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import dev.lucasnlm.antimine.core.models.Score
import dev.lucasnlm.antimine.preferences.models.ControlStyle
import dev.lucasnlm.antimine.preferences.models.GameControl
import dev.lucasnlm.antimine.preferences.models.Minefield
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.single
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Assert.assertEquals
Expand All @@ -18,6 +18,7 @@ import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test

@ExperimentalCoroutinesApi
class GameControllerTest {
private fun withGameController(
clickOnCreate: Boolean = true,
Expand All @@ -26,7 +27,9 @@ class GameControllerTest {
val minefield = Minefield(10, 10, 20)
val gameController = GameController(minefield, 200L)
if (clickOnCreate) {
gameController.fakeSingleClick(10)
runBlockingTest {
fakeSingleClick(gameController, 10)
}
}
block(gameController)
}
Expand Down Expand Up @@ -94,7 +97,7 @@ class GameControllerTest {
withGameController { controller ->
assertNull(controller.findExplodedMine())
val target = controller.mines().first()
controller.fakeSingleClick(target.id)
fakeSingleClick(controller, target.id)
assertNotNull(controller.findExplodedMine())
assertEquals(target.id, controller.findExplodedMine()!!.id)
}
Expand Down Expand Up @@ -219,7 +222,7 @@ class GameControllerTest {
controller.field()
.filter { !it.hasMine }
.onEach {
controller.fakeSingleClick(it.id)
fakeSingleClick(controller, it.id)

if (it.id != lastArea) {
assertFalse(controller.hasIsolatedAllMines())
Expand All @@ -237,7 +240,7 @@ class GameControllerTest {
withGameController { controller ->
assertFalse(controller.hasAnyMineExploded())

controller.field().first { it.hasMine }.also { controller.fakeSingleClick(it.id) }
controller.field().first { it.hasMine }.also { fakeSingleClick(controller, it.id) }

assertTrue(controller.hasAnyMineExploded())
}
Expand All @@ -248,7 +251,7 @@ class GameControllerTest {
withGameController { controller ->
assertFalse(controller.isGameOver())

controller.field().first { it.hasMine }.also { controller.fakeSingleClick(it.id) }
controller.field().first { it.hasMine }.also { fakeSingleClick(controller, it.id) }

assertTrue(controller.isGameOver())
}
Expand All @@ -262,12 +265,12 @@ class GameControllerTest {
controller.mines().forEach { fakeLongPress(controller, it.id) }
assertFalse(controller.isVictory())

controller.field { !it.hasMine }.forEach { controller.fakeSingleClick(it.id) }
controller.field { !it.hasMine }.forEach { fakeSingleClick(controller, it.id) }
assertTrue(controller.isVictory())

controller.mines().first().run {
controller.fakeSingleClick(id)
controller.fakeSingleClick(id)
fakeSingleClick(controller, id)
fakeSingleClick(controller, id)
}
assertFalse(controller.isVictory())
}
Expand All @@ -285,7 +288,7 @@ class GameControllerTest {
withGameController { controller ->
controller.updateGameControl(GameControl.fromControlType(ControlStyle.Standard))
assertTrue(controller.at(3).isCovered)
controller.fakeSingleClick(3)
fakeSingleClick(controller, 3)
assertFalse(controller.at(3).isCovered)
}
}
Expand Down Expand Up @@ -323,7 +326,7 @@ class GameControllerTest {
withGameController { controller ->
controller.run {
updateGameControl(GameControl.fromControlType(ControlStyle.Standard))
fakeSingleClick(14)
fakeSingleClick(controller, 14)
assertFalse(at(14).isCovered)

field().filterNeighborsOf(at(14)).forEach {
Expand Down Expand Up @@ -352,7 +355,7 @@ class GameControllerTest {
withGameController { controller ->
controller.run {
updateGameControl(GameControl.fromControlType(ControlStyle.FastFlag))
fakeSingleClick(3)
fakeSingleClick(controller, 3)
assertTrue(at(3).isCovered)
assertTrue(at(3).mark.isFlag())
fakeLongPress(controller, 3)
Expand All @@ -365,28 +368,28 @@ class GameControllerTest {
}

@Test
fun testControlFirstActionWithInvertedDoubleClick() {
fun testControlFirstActionWithInvertedDoubleClick() = runBlockingTest {
withGameController { controller ->
controller.run {
updateGameControl(GameControl.fromControlType(ControlStyle.DoubleClickInverted))
assertTrue(at(3).isCovered)
fakeDoubleClick(3)
fakeDoubleClick(controller, 3)
assertTrue(at(3).isCovered)
assertTrue(at(3).mark.isFlag())
fakeDoubleClick(3)
fakeDoubleClick(controller, 3)
assertFalse(at(3).mark.isFlag())
assertTrue(at(3).isCovered)
}
}
}

@Test
fun testControlSecondActionWithInvertedDoubleClick() {
fun testControlSecondActionWithInvertedDoubleClick() = runBlockingTest {
withGameController { controller ->
controller.run {
updateGameControl(GameControl.fromControlType(ControlStyle.DoubleClickInverted))
assertTrue(at(3).isCovered)
fakeSingleClick(3)
fakeSingleClick(controller, 3)
assertFalse(at(3).isCovered)
}
}
Expand All @@ -405,14 +408,14 @@ class GameControllerTest {
}

mines().forEach {
fakeSingleClick(it.id)
fakeSingleClick(controller, it.id)
}

mines().forEach {
assertTrue(it.mark.isFlag())
}

fakeSingleClick(14)
fakeSingleClick(controller, 14)
field().filterNeighborsOf(at(14)).forEach {
if (it.hasMine) {
assertTrue(it.isCovered)
Expand All @@ -425,72 +428,72 @@ class GameControllerTest {
}

@Test
fun testControlFirstActionWithDoubleClick() {
fun testControlFirstActionWithDoubleClick() = runBlockingTest {
withGameController { controller ->
controller.run {
updateGameControl(GameControl.fromControlType(ControlStyle.DoubleClick))
fakeSingleClick(3)
fakeSingleClick(controller, 3)
assertTrue(at(3).isCovered)
assertTrue(at(3).mark.isFlag())
fakeDoubleClick(3)
fakeDoubleClick(controller, 3)
assertFalse(at(3).mark.isFlag())
assertTrue(at(3).isCovered)
fakeDoubleClick(3)
fakeDoubleClick(controller, 3)
assertFalse(at(3).isCovered)
}
}
}

@Test
fun testControlFirstActionWithDoubleClickAndWithoutQuestionMark() {
fun testControlFirstActionWithDoubleClickAndWithoutQuestionMark() = runBlockingTest {
withGameController { controller ->
controller.run {
updateGameControl(GameControl.fromControlType(ControlStyle.DoubleClick))

useQuestionMark(true)
var targetId = 4
fakeSingleClick(targetId)
fakeSingleClick(controller, targetId)
assertTrue(at(targetId).isCovered)
assertTrue(at(targetId).mark.isFlag())
fakeSingleClick(targetId)
fakeSingleClick(controller, targetId)
assertTrue(at(targetId).mark.isQuestion())
assertTrue(at(targetId).isCovered)
fakeSingleClick(targetId)
fakeSingleClick(controller, targetId)
assertTrue(at(targetId).mark.isNone())
assertTrue(at(targetId).isCovered)
fakeDoubleClick(targetId)
fakeDoubleClick(controller, targetId)
assertFalse(at(targetId).isCovered)

useQuestionMark(false)
targetId = 3
fakeSingleClick(targetId)
fakeSingleClick(controller, targetId)
assertTrue(at(targetId).isCovered)
assertTrue(at(targetId).mark.isFlag())
fakeSingleClick(targetId)
fakeSingleClick(controller, targetId)
assertFalse(at(targetId).mark.isFlag())
assertTrue(at(targetId).isCovered)
fakeDoubleClick(targetId)
fakeDoubleClick(controller, targetId)
assertFalse(at(targetId).isCovered)
}
}
}

@Test
fun testControlDoubleClickOpenMultiple() {
fun testControlDoubleClickOpenMultiple() = runBlockingTest {
withGameController { controller ->
controller.run {
updateGameControl(GameControl.fromControlType(ControlStyle.DoubleClick))
fakeDoubleClick(14)
fakeDoubleClick(controller, 14)
assertFalse(at(14).isCovered)
field().filterNeighborsOf(at(14)).forEach {
assertTrue(it.isCovered)
}

mines().forEach { fakeSingleClick(it.id) }
mines().forEach { fakeSingleClick(controller, it.id) }

mines().forEach { assertTrue(it.mark.isFlag()) }

fakeDoubleClick(14)
fakeDoubleClick(controller, 14)
field().filterNeighborsOf(at(14)).forEach {
if (it.hasMine) {
assertTrue(it.isCovered)
Expand All @@ -503,27 +506,27 @@ class GameControllerTest {
}

@Test
fun testIfDoubleClickPlantMinesOnFirstClick() {
fun testIfDoubleClickPlantMinesOnFirstClick() = runBlockingTest {
withGameController(clickOnCreate = false) { controller ->
controller.run {
updateGameControl(GameControl.fromControlType(ControlStyle.DoubleClick))
assertFalse(hasMines())
assertEquals(0, field().filterNot { it.isCovered }.count())
fakeSingleClick(40)
fakeSingleClick(controller, 40)
assertTrue(hasMines())
field().filterNeighborsOf(at(40)).forEach { assertFalse(it.isCovered) }
}
}
}

@Test
fun testIfFastFlagPlantMinesOnFirstClick() {
fun testIfFastFlagPlantMinesOnFirstClick() = runBlockingTest {
withGameController(clickOnCreate = false) { controller ->
controller.run {
updateGameControl(GameControl.fromControlType(ControlStyle.FastFlag))
assertFalse(hasMines())
assertEquals(0, field().filterNot { it.isCovered }.count())
fakeSingleClick(40)
fakeSingleClick(controller, 40)
assertTrue(hasMines())
field().filterNeighborsOf(at(40)).forEach { assertFalse(it.isCovered) }
}
Expand All @@ -546,11 +549,9 @@ class GameControllerTest {
}
}

private fun GameController.fakeDoubleClick(index: Int) {
runBlocking {
launch {
doubleClick(index).single()
}.join()
private fun TestCoroutineScope.fakeDoubleClick(gameController: GameController, index: Int) {
launch {
gameController.doubleClick(index).single()
}
}
}
2 changes: 1 addition & 1 deletion gdx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ dependencies {
// AndroidX
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.activity:activity-ktx:1.2.3'
implementation "androidx.fragment:fragment-ktx:1.3.3"
implementation 'androidx.fragment:fragment-ktx:1.3.4'

// Koin
implementation 'org.koin:koin-android:2.2.1'
Expand Down
Loading

0 comments on commit ac22e00

Please sign in to comment.