Skip to content

Commit

Permalink
Fix crash and minefield render bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasnlm committed Oct 22, 2023
1 parent 8ae98ee commit 4adf82d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ val ViewModelModule =
viewModel { LocalizationViewModel(get(), get()) }
viewModel {
GameViewModel(
get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(),
get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ abstract class CommonGameDialogFragment : AppCompatDialogFragment() {
)
preferencesRepository.setShowMusicBanner(false)
gameAudioManager.playMonetization()
openComposer(composer.composerLink)
openComposer(it.context, composer.composerLink)
}
}

Expand All @@ -138,9 +138,10 @@ abstract class CommonGameDialogFragment : AppCompatDialogFragment() {
}
}

private fun openComposer(composerLink: String) {
val context = requireContext()

private fun openComposer(
context: Context,
composerLink: String,
) {
runCatching {
val intent =
Intent(Intent.ACTION_VIEW, Uri.parse(composerLink)).apply {
Expand All @@ -163,7 +164,7 @@ abstract class CommonGameDialogFragment : AppCompatDialogFragment() {
post {
addView(
adsManager.createBannerAd(
requireContext(),
adFrame.context,
onError = {
showHexBanner(this)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import dev.lucasnlm.antimine.preferences.models.GameControl
import dev.lucasnlm.antimine.preferences.models.Minefield
import dev.lucasnlm.external.Achievement
import dev.lucasnlm.external.AnalyticsManager
import dev.lucasnlm.external.FeatureFlagManager
import dev.lucasnlm.external.Leaderboard
import dev.lucasnlm.external.PlayGamesManager
import kotlinx.coroutines.Dispatchers
Expand All @@ -52,7 +51,6 @@ open class GameViewModel(
private val analyticsManager: AnalyticsManager,
private val playGamesManager: PlayGamesManager,
private val tipRepository: TipRepository,
private val featureFlagManager: FeatureFlagManager,
private val clockManager: ClockManager,
) : IntentViewModel<GameEvent, GameState>() {
private lateinit var gameController: GameController
Expand Down Expand Up @@ -143,12 +141,17 @@ open class GameViewModel(
emit(
state.copy(
isLoadingMap = false,
selectedAction = gameController.getSelectedAction(),
selectedAction =
if (initialized) {
gameController.getSelectedAction()
} else {
preferencesRepository.defaultSwitchButton()
},
),
)
}

if (!state.isGameCompleted && state.hasMines && !state.isLoadingMap) {
if (initialized && !state.isGameCompleted && state.hasMines && !state.isLoadingMap) {
if (
!gameController.isGameOver() &&
!gameController.isVictory() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ class AreaActor(
}

if (this.area != area) {
if (this.area?.id != area.id) {
x = area.posX * width
y = area.posY * height
refreshLinks(area, field)
}
x = area.posX * width
y = area.posY * height
refreshLinks(area, field)

this.area = area
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ class MinefieldStage(
this.newBoundAreas = null
}

if (actors.size != boundAreas.size) {
if (boundAreas.size < actors.size) {
actors.removeRange(boundAreas.size, actors.size)
actors.shrink()
} else {
val forceRebind = actors.size != boundAreas.size
if (forceRebind) {
if (boundAreas.size > actors.size) {
actors.ensureCapacity(boundAreas.size + 1)
}

Expand All @@ -101,10 +99,13 @@ class MinefieldStage(
)
actors.add(areaActor)
}
} else if (actors.size > boundAreas.size) {
actors.removeRange(boundAreas.size, actors.size - 1)
}
}

val areaSize = gameRenderingContext.areaSize
val checkShape = forceRefreshVisibleAreas || forceRebind
Gdx.graphics.isContinuousRendering = true
actors.forEachIndexed { index, actor ->
val areaActor = (actor as AreaActor)
Expand All @@ -122,7 +123,7 @@ class MinefieldStage(
reset = resetEvents,
area = area,
field = boundAreas,
checkShape = forceRefreshVisibleAreas,
checkShape = checkShape,
)
}
Gdx.graphics.isContinuousRendering = false
Expand Down

0 comments on commit 4adf82d

Please sign in to comment.