Save each game for Debugging
This commit is contained in:
@@ -31,7 +31,7 @@ kotlin {
|
||||
implementation(compose.components.uiToolingPreview)
|
||||
// implementation(libs.compose.ui.text.googlefonts)
|
||||
|
||||
implementation(libs.logging)
|
||||
implementation(libs.bundles.logging)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,10 +40,23 @@ import ch.dissem.yaep.domain.NeighbourClue
|
||||
import ch.dissem.yaep.domain.OrderClue
|
||||
import ch.dissem.yaep.domain.SameColumnClue
|
||||
import ch.dissem.yaep.domain.TripletClue
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.jetbrains.compose.resources.painterResource
|
||||
import yaep.commonui.generated.resources.Res
|
||||
import yaep.commonui.generated.resources.neighbour
|
||||
import yaep.commonui.generated.resources.order
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.createDirectories
|
||||
import kotlin.io.path.createFile
|
||||
import kotlin.io.path.isDirectory
|
||||
import kotlin.io.path.notExists
|
||||
import kotlin.io.path.writeText
|
||||
import kotlin.time.Clock
|
||||
import kotlin.time.ExperimentalTime
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
class DisplayClue<C : Clue>(val clue: C) {
|
||||
var isActive: Boolean by mutableStateOf(true)
|
||||
@@ -59,13 +72,37 @@ class DisplayClue<C : Clue>(val clue: C) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun App(modifier: Modifier = Modifier, game: Game, onNewGame: () -> Unit, resetCluesBeacon: Any = Any()) {
|
||||
val horizontalClues = remember(game, resetCluesBeacon) { game.horizontalClues.map { DisplayClue(it) } }
|
||||
val verticalClues = remember(game, resetCluesBeacon) { game.verticalClues.map { DisplayClue(it) } }
|
||||
@OptIn(ExperimentalTime::class)
|
||||
fun App(
|
||||
modifier: Modifier = Modifier,
|
||||
game: Game,
|
||||
onNewGame: () -> Unit,
|
||||
resetCluesBeacon: Any = Any()
|
||||
) {
|
||||
val horizontalClues =
|
||||
remember(game, resetCluesBeacon) { game.horizontalClues.map { DisplayClue(it) } }
|
||||
val verticalClues =
|
||||
remember(game, resetCluesBeacon) { game.verticalClues.map { DisplayClue(it) } }
|
||||
val timer = remember(game) { GameTimer() }
|
||||
val time by timer.elapsedTime.collectAsState("00:00")
|
||||
var isSolved by remember(game) { mutableStateOf(false) }
|
||||
LaunchedEffect(game) {
|
||||
launch(Dispatchers.IO) {
|
||||
val dirName = """${System.getProperty("user.home")}/.yaep"""
|
||||
val dir = Path(dirName)
|
||||
if (dir.notExists()) {
|
||||
dir.createDirectories()
|
||||
} else if (!dir.isDirectory()) {
|
||||
log.error { "Yaep data directory already exists and is not a directory: $dir" }
|
||||
log.debug { "Game: $game" }
|
||||
} else {
|
||||
val fileName = "$dirName/${Clock.System.now()}.yaep"
|
||||
Path(fileName)
|
||||
.createFile()
|
||||
.writeText(game.toString())
|
||||
log.info { "Saved game to $fileName" }
|
||||
}
|
||||
}
|
||||
game.onStart {
|
||||
timer.start()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user