Fix some inspection issues

This commit is contained in:
Christian Basler
2025-07-17 22:45:52 +02:00
parent 1800174087
commit 1836f53d7b
15 changed files with 36 additions and 37 deletions

View File

@@ -18,7 +18,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import ch.dissem.yaep.domain.Game
import ch.dissem.yaep.domain.generateGame import ch.dissem.yaep.domain.generateGame
import ch.dissem.yaep.ui.common.App import ch.dissem.yaep.ui.common.App
import org.jetbrains.compose.resources.painterResource import org.jetbrains.compose.resources.painterResource
@@ -34,7 +33,7 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContent { setContent {
var game by remember { mutableStateOf<Game>(generateGame()) } var game by remember { mutableStateOf(generateGame()) }
var resetCluesBeacon by remember { mutableStateOf(Any()) } var resetCluesBeacon by remember { mutableStateOf(Any()) }
Scaffold( Scaffold(

View File

@@ -4,7 +4,7 @@ import ch.dissem.yaep.domain.Game
import io.github.oshai.kotlinlogging.KotlinLogging import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
val log = KotlinLogging.logger {} private val log = KotlinLogging.logger {}
actual fun CoroutineScope.logGame(game: Game) { actual fun CoroutineScope.logGame(game: Game) {
log.debug { "Game: $game" } log.debug { "Game: $game" }

View File

@@ -180,17 +180,17 @@ fun PuzzleGrid(
item.options.add(it) item.options.add(it)
}, },
selectedItem = selection, selectedItem = selection,
onSelectItem = { onSelectItem = { selectedItem ->
if (it != null) { if (selectedItem != null) {
grid.snapshot() grid.snapshot()
item.selection = it item.selection = selectedItem
row.cleanupOptions() row.cleanupOptions()
} else { } else {
while (item.selection != null) { while (item.selection != null) {
if (!grid.undo()) break if (!grid.undo()) break
} }
options.forEach { options.forEach { option ->
it.enabled = item.options.contains(it.item) option.enabled = item.options.contains(option.item)
} }
} }
} }

View File

@@ -22,14 +22,14 @@ private enum class AspectRatio {
PORTRAIT, LANDSCAPE, SQUARISH; PORTRAIT, LANDSCAPE, SQUARISH;
companion object { companion object {
private const val landscapeRatio = 1.4f private const val ASPECT_RATIO_LANDSCAPE = 1.4f
private const val portraitRatio = 1 / landscapeRatio private const val ASPECT_RATIO_PORTRAIT = 1 / ASPECT_RATIO_LANDSCAPE
fun from(constraints: Constraints): AspectRatio { fun from(constraints: Constraints): AspectRatio {
val ratio = constraints.maxWidth.toFloat() / constraints.maxHeight.toFloat() val ratio = constraints.maxWidth.toFloat() / constraints.maxHeight.toFloat()
return when { return when {
ratio < portraitRatio -> PORTRAIT ratio < ASPECT_RATIO_PORTRAIT -> PORTRAIT
ratio > landscapeRatio -> LANDSCAPE ratio > ASPECT_RATIO_LANDSCAPE -> LANDSCAPE
else -> SQUARISH else -> SQUARISH
} }
} }

View File

@@ -12,7 +12,7 @@ import kotlin.io.path.writeText
import kotlin.time.Clock import kotlin.time.Clock
import kotlin.time.ExperimentalTime import kotlin.time.ExperimentalTime
val log = KotlinLogging.logger {} private val log = KotlinLogging.logger {}
@OptIn(ExperimentalTime::class) @OptIn(ExperimentalTime::class)
actual fun CoroutineScope.logGame(game: Game) { actual fun CoroutineScope.logGame(game: Game) {

View File

@@ -16,7 +16,6 @@ import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPlacement import androidx.compose.ui.window.WindowPlacement
import androidx.compose.ui.window.application import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState import androidx.compose.ui.window.rememberWindowState
import ch.dissem.yaep.domain.Game
import ch.dissem.yaep.domain.generateGame import ch.dissem.yaep.domain.generateGame
import ch.dissem.yaep.ui.common.App import ch.dissem.yaep.ui.common.App
import ch.dissem.yaep.ui.common.theme.emojiFontFamily import ch.dissem.yaep.ui.common.theme.emojiFontFamily
@@ -39,7 +38,7 @@ fun main(): Unit = application {
placement = WindowPlacement.Floating, placement = WindowPlacement.Floating,
size = DpSize(1250.dp, 800.dp) size = DpSize(1250.dp, 800.dp)
) )
var game by remember { mutableStateOf<Game>(generateGame()) } var game by remember { mutableStateOf(generateGame()) }
Window( Window(
onCloseRequest = ::exitApplication, onCloseRequest = ::exitApplication,

View File

@@ -6,9 +6,10 @@ class Game(
val grid: Grid, val grid: Grid,
val clues: Collection<Clue> val clues: Collection<Clue>
) { ) {
val log = KotlinLogging.logger { } private val log = KotlinLogging.logger { }
val horizontalClues = clues.filterIsInstance<HorizontalClue>() val horizontalClues: List<HorizontalClue> = clues.filterIsInstance<HorizontalClue>()
val verticalClues = clues.filterIsInstance<SameColumnClue<ItemClass<*>, ItemClass<*>>>() val verticalClues: List<SameColumnClue<ItemClass<*>, ItemClass<*>>> =
clues.filterIsInstance<SameColumnClue<ItemClass<*>, ItemClass<*>>>()
private val onStartListeners = mutableListOf<() -> Unit>() private val onStartListeners = mutableListOf<() -> Unit>()
private val onSolvedListeners = mutableListOf<() -> Unit>() private val onSolvedListeners = mutableListOf<() -> Unit>()

View File

@@ -44,9 +44,6 @@ fun <C : ItemClass<C>> GameCell<C>?.mayBe(item: Item<C>, mayHaveSelection: Boole
this != null && this != null &&
((mayHaveSelection && selection == item) || (selection == null && options.contains(item))) ((mayHaveSelection && selection == item) || (selection == null && options.contains(item)))
fun <C : ItemClass<C>> GameCell<C>?.isA(item: Item<C>): Boolean =
this != null && selection == item
fun <C : ItemClass<C>> GameCell<C>?.hasNoSelection(): Boolean = fun <C : ItemClass<C>> GameCell<C>?.hasNoSelection(): Boolean =
this != null && this.selection == null this != null && this.selection == null

View File

@@ -1,5 +1,6 @@
package ch.dissem.yaep.domain package ch.dissem.yaep.domain
@Suppress("JavaDefaultMethodsNotOverriddenByDelegation")
class GameRow<C : ItemClass<C>>( class GameRow<C : ItemClass<C>>(
val category: ItemClassCompanion<C>, val category: ItemClassCompanion<C>,
val options: List<Item<C>>, val options: List<Item<C>>,
@@ -79,4 +80,5 @@ class GameRow<C : ItemClass<C>>(
} }
return didChange return didChange
} }
} }

View File

@@ -1,6 +1,6 @@
package ch.dissem.yaep.domain package ch.dissem.yaep.domain
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST", "JavaDefaultMethodsNotOverriddenByDelegation")
class Grid( class Grid(
val rows: List<GameRow<*>> val rows: List<GameRow<*>>
) : List<GameRow<ItemClass<*>>> by rows as List<GameRow<ItemClass<*>>> { ) : List<GameRow<ItemClass<*>>> by rows as List<GameRow<ItemClass<*>>> {
@@ -41,7 +41,7 @@ class Grid(
} }
} }
fun List<List<Item<ItemClass<*>>>>.toGrid() = Grid( fun List<List<Item<ItemClass<*>>>>.toGrid(): Grid = Grid(
map { row -> map { row ->
GameRow( GameRow(
category = row.first().itemType.companion, category = row.first().itemType.companion,

View File

@@ -1,5 +1,6 @@
package ch.dissem.yaep.domain package ch.dissem.yaep.domain
@Suppress("JavaDefaultMethodsNotOverriddenByDelegation")
class ObservableSet<E> private constructor( class ObservableSet<E> private constructor(
private val mutableSet: MutableSet<E>, private val mutableSet: MutableSet<E>,
private val onElementChanged: (before: Set<E>, after: Set<E>) -> Unit private val onElementChanged: (before: Set<E>, after: Set<E>) -> Unit

View File

@@ -85,7 +85,7 @@ class NeighbourClue<A : ItemClass<A>, B : ItemClass<B>>(val a: Item<A>, val b: I
return removed return removed
} }
override fun toString() = "$aType is next to $bType" override fun toString(): String = "$aType is next to $bType"
companion object : ClueParser { companion object : ClueParser {
override fun <T : ItemClass<T>> parse( override fun <T : ItemClass<T>> parse(
@@ -147,7 +147,7 @@ class OrderClue<L : ItemClass<L>, R : ItemClass<R>>(val left: Item<L>, val right
return removed return removed
} }
override fun toString() = "$leftType is left of $rightType" override fun toString(): String = "$leftType is left of $rightType"
companion object : ClueParser { companion object : ClueParser {
override fun <T : ItemClass<T>> parse( override fun <T : ItemClass<T>> parse(
@@ -377,7 +377,7 @@ class SameColumnClue<A : ItemClass<A>, B : ItemClass<B>>(val a: Item<A>, val b:
} }
class PositionClue<C : ItemClass<C>>(val item: Item<C>, val index: Int) : Clue() { class PositionClue<C : ItemClass<C>>(val item: Item<C>, val index: Int) : Clue() {
val itemType = item.itemType val itemType: C = item.itemType
override fun isValid(grid: Grid): Boolean { override fun isValid(grid: Grid): Boolean {
val i = grid.indexOf(item.itemType) val i = grid.indexOf(item.itemType)
@@ -401,7 +401,7 @@ class PositionClue<C : ItemClass<C>>(val item: Item<C>, val index: Int) : Clue()
return removed return removed
} }
override fun toString() = "$itemType is at position $index" override fun toString(): String = "$itemType is at position $index"
companion object : ClueParser { companion object : ClueParser {
override fun <T : ItemClass<T>> parse( override fun <T : ItemClass<T>> parse(

View File

@@ -11,7 +11,7 @@ enum class Animal(symbol: String) : ItemClass<Animal> {
override val symbols: Array<String> = arrayOf(symbol) override val symbols: Array<String> = arrayOf(symbol)
override val companion override val companion: Animal.Companion
get() = Animal get() = Animal
companion object : ItemClassCompanion<Animal> { companion object : ItemClassCompanion<Animal> {
@@ -31,7 +31,7 @@ enum class Nationality(symbol: String) : ItemClass<Nationality> {
override val symbols: Array<String> = arrayOf(symbol) override val symbols: Array<String> = arrayOf(symbol)
override val companion override val companion: Nationality.Companion
get() = Nationality get() = Nationality
companion object : ItemClassCompanion<Nationality> { companion object : ItemClassCompanion<Nationality> {
@@ -50,7 +50,7 @@ enum class Drink(symbol: String) : ItemClass<Drink> {
override val symbols: Array<String> = arrayOf(symbol) override val symbols: Array<String> = arrayOf(symbol)
override val companion override val companion: Drink.Companion
get() = Drink get() = Drink
companion object : ItemClassCompanion<Drink> { companion object : ItemClassCompanion<Drink> {
@@ -70,7 +70,7 @@ enum class Profession(symbol: String) : ItemClass<Profession> {
override val symbols: Array<String> = idic(symbol) override val symbols: Array<String> = idic(symbol)
override val companion override val companion: Profession.Companion
get() = Profession get() = Profession
companion object : ItemClassCompanion<Profession> { companion object : ItemClassCompanion<Profession> {
@@ -92,7 +92,7 @@ enum class Fruit(symbol: String) : ItemClass<Fruit> {
override val symbols: Array<String> = arrayOf(symbol) override val symbols: Array<String> = arrayOf(symbol)
override val companion override val companion: Fruit.Companion
get() = Fruit get() = Fruit
companion object : ItemClassCompanion<Fruit> { companion object : ItemClassCompanion<Fruit> {
@@ -113,7 +113,7 @@ enum class Dessert(symbol: String) : ItemClass<Dessert> {
override val symbols: Array<String> = arrayOf(symbol) override val symbols: Array<String> = arrayOf(symbol)
override val companion override val companion: Dessert.Companion
get() = Dessert get() = Dessert
companion object : ItemClassCompanion<Dessert> { companion object : ItemClassCompanion<Dessert> {
@@ -132,7 +132,7 @@ enum class Transportation(symbol: String) : ItemClass<Transportation> {
override val symbols: Array<String> = arrayOf(symbol) override val symbols: Array<String> = arrayOf(symbol)
override val companion override val companion: Transportation.Companion
get() = Transportation get() = Transportation
companion object : ItemClassCompanion<Transportation> { companion object : ItemClassCompanion<Transportation> {

View File

@@ -1,11 +1,11 @@
package ch.dissem.yaep.domain package ch.dissem.yaep.domain
abstract class ClueTest { abstract class ClueTest {
protected val size = 6 protected val size: Int = 6
protected fun createGrid( protected fun createGrid(
selection: (Item<ItemClass<*>>) -> Item<ItemClass<*>>? = { it } selection: (Item<ItemClass<*>>) -> Item<ItemClass<*>>? = { it }
) = Grid( ): Grid = Grid(
ItemClass.randomClasses(size) ItemClass.randomClasses(size)
.map { .map {
it.randomItems(size).map { item -> Item(item) } it.randomItems(size).map { item -> Item(item) }

View File

@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME