Skip to content

Commit

Permalink
Fix: New algorithm option got ignored at start in debug variant
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Jan 5, 2025
1 parent b14e265 commit 9b50b58
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.piepmeyer.gauguin.calculation.GridCalculationService
import org.piepmeyer.gauguin.calculation.GridPreviewCalculationService
import org.piepmeyer.gauguin.calculation.GridPreviewListener
import org.piepmeyer.gauguin.creation.GridBuilder
import org.piepmeyer.gauguin.creation.GridCalculatorFactory
import org.piepmeyer.gauguin.difficulty.GameDifficultyRater
import org.piepmeyer.gauguin.game.GameLifecycle
import org.piepmeyer.gauguin.grid.Grid
Expand Down Expand Up @@ -56,11 +57,15 @@ class NewGameViewModel :
val gameVariantState: StateFlow<GridVariantState> = mutableGameVariantState.asStateFlow()

init {
GridCalculatorFactory.alwaysUseNewAlgorithm = applicationPreferences.mergingCageAlgorithm

previewService.addListener(this)
previewService.calculateGrid(mutableGameVariantState.value.variant, viewModelScope)
}

private fun initialPreviewService(): GridPreviewState {
GridCalculatorFactory.alwaysUseNewAlgorithm = applicationPreferences.mergingCageAlgorithm

if (calculationService.hasCalculatedNextGrid(gameVariant())) {
val grid = calculationService.consumeNextGrid()
previewService.takeCalculatedGrid(grid)
Expand Down Expand Up @@ -114,8 +119,8 @@ class NewGameViewModel :
}

fun calculateGrid() {
val oldVariant = mutableGameVariantState.value
val newVariant = gameVariant()
val oldState = mutableGameVariantState.value
val newState = gridVariantState()

if (oldState != newState) {
mutableGameVariantState.value = newState
Expand Down

0 comments on commit 9b50b58

Please sign in to comment.