Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2b21a07f5 | ||
|
|
e98afbfd8d | ||
|
|
2c90de66d1 | ||
|
|
f93eba88e5 | ||
|
|
36ab518309 |
@@ -362,12 +362,7 @@ object GameCatalog {
|
|||||||
maxPlayers = 4,
|
maxPlayers = 4,
|
||||||
teamBased = false,
|
teamBased = false,
|
||||||
blurb = "Trade, build, and settle the island, in the base game or Cities & Knights.",
|
blurb = "Trade, build, and settle the island, in the base game or Cities & Knights.",
|
||||||
// Engine and screen exist but have not been verified on two real
|
available = true,
|
||||||
// devices yet. Dev builds can open it as a *Preview*; a production
|
|
||||||
// build does not list it. Flip `available` on, and `devPreview`
|
|
||||||
// off, once two-device play has been verified.
|
|
||||||
available = false,
|
|
||||||
devPreview = true,
|
|
||||||
),
|
),
|
||||||
GameDescriptor(
|
GameDescriptor(
|
||||||
id = MEOWDOKU,
|
id = MEOWDOKU,
|
||||||
@@ -378,8 +373,7 @@ object GameCatalog {
|
|||||||
teamBased = false,
|
teamBased = false,
|
||||||
blurb = "One cat in every row, column and colour, and no two touching. " +
|
blurb = "One cat in every row, column and colour, and no two touching. " +
|
||||||
"Wrong taps cost a heart; the board only ever accepts a cat that belongs.",
|
"Wrong taps cost a heart; the board only ever accepts a cat that belongs.",
|
||||||
available = false,
|
available = true,
|
||||||
devPreview = true,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ data class Settings(
|
|||||||
val soundEnabled: Boolean = true,
|
val soundEnabled: Boolean = true,
|
||||||
val animationSpeed: Float = 1.0f,
|
val animationSpeed: Float = 1.0f,
|
||||||
val checkForUpdatesOnLaunch: Boolean = true,
|
val checkForUpdatesOnLaunch: Boolean = true,
|
||||||
|
/** Multiplies the system font size across the whole app. */
|
||||||
|
val textScale: Float = 1.0f,
|
||||||
/**
|
/**
|
||||||
* Exactly what the user has typed, which may be blank while they are
|
* Exactly what the user has typed, which may be blank while they are
|
||||||
* mid-edit. Nothing substitutes a default into this value: doing so meant
|
* mid-edit. Nothing substitutes a default into this value: doing so meant
|
||||||
@@ -46,6 +48,8 @@ data class Settings(
|
|||||||
companion object {
|
companion object {
|
||||||
const val MIN_SPEED = 0.5f
|
const val MIN_SPEED = 0.5f
|
||||||
const val MAX_SPEED = 2.0f
|
const val MAX_SPEED = 2.0f
|
||||||
|
const val MIN_TEXT_SCALE = 0.8f
|
||||||
|
const val MAX_TEXT_SCALE = 1.6f
|
||||||
const val DEFAULT_PLAYER_NAME = "Player"
|
const val DEFAULT_PLAYER_NAME = "Player"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,6 +60,7 @@ class SettingsRepository(private val context: Context) {
|
|||||||
val SOUND = booleanPreferencesKey("sound_enabled")
|
val SOUND = booleanPreferencesKey("sound_enabled")
|
||||||
val SPEED = floatPreferencesKey("animation_speed")
|
val SPEED = floatPreferencesKey("animation_speed")
|
||||||
val UPDATE_ON_LAUNCH = booleanPreferencesKey("check_updates_on_launch")
|
val UPDATE_ON_LAUNCH = booleanPreferencesKey("check_updates_on_launch")
|
||||||
|
val TEXT_SCALE = floatPreferencesKey("text_scale")
|
||||||
val NAME = stringPreferencesKey("player_name")
|
val NAME = stringPreferencesKey("player_name")
|
||||||
// There is deliberately no update-channel key. The channel is a
|
// There is deliberately no update-channel key. The channel is a
|
||||||
// property of the installed APK, not a preference — an install that
|
// property of the installed APK, not a preference — an install that
|
||||||
@@ -69,6 +74,8 @@ class SettingsRepository(private val context: Context) {
|
|||||||
soundEnabled = prefs[Keys.SOUND] ?: true,
|
soundEnabled = prefs[Keys.SOUND] ?: true,
|
||||||
animationSpeed = prefs[Keys.SPEED] ?: 1.0f,
|
animationSpeed = prefs[Keys.SPEED] ?: 1.0f,
|
||||||
checkForUpdatesOnLaunch = prefs[Keys.UPDATE_ON_LAUNCH] ?: true,
|
checkForUpdatesOnLaunch = prefs[Keys.UPDATE_ON_LAUNCH] ?: true,
|
||||||
|
textScale = (prefs[Keys.TEXT_SCALE] ?: 1.0f)
|
||||||
|
.coerceIn(Settings.MIN_TEXT_SCALE, Settings.MAX_TEXT_SCALE),
|
||||||
playerName = prefs[Keys.NAME] ?: "",
|
playerName = prefs[Keys.NAME] ?: "",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -83,6 +90,12 @@ class SettingsRepository(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun setTextScale(scale: Float) {
|
||||||
|
context.dataStore.edit {
|
||||||
|
it[Keys.TEXT_SCALE] = scale.coerceIn(Settings.MIN_TEXT_SCALE, Settings.MAX_TEXT_SCALE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun setCheckForUpdatesOnLaunch(enabled: Boolean) {
|
suspend fun setCheckForUpdatesOnLaunch(enabled: Boolean) {
|
||||||
context.dataStore.edit { it[Keys.UPDATE_ON_LAUNCH] = enabled }
|
context.dataStore.edit { it[Keys.UPDATE_ON_LAUNCH] = enabled }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import androidx.compose.material3.Card
|
|||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.unit.Density
|
||||||
import androidx.compose.material3.OutlinedButton
|
import androidx.compose.material3.OutlinedButton
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@@ -139,7 +141,14 @@ fun AppRoot(env: AppEnv) {
|
|||||||
// Card motion reads its speed from here rather than from a parameter.
|
// Card motion reads its speed from here rather than from a parameter.
|
||||||
// Every card screen animates, most of them several layers deep, and the
|
// Every card screen animates, most of them several layers deep, and the
|
||||||
// alternative was passing one unchanging number down through all of it.
|
// alternative was passing one unchanging number down through all of it.
|
||||||
CompositionLocalProvider(LocalCardSpeed provides settings.animationSpeed) {
|
val density = LocalDensity.current
|
||||||
|
val scaledDensity = remember(density, settings.textScale) {
|
||||||
|
Density(density.density, density.fontScale * settings.textScale)
|
||||||
|
}
|
||||||
|
CompositionLocalProvider(
|
||||||
|
LocalCardSpeed provides settings.animationSpeed,
|
||||||
|
LocalDensity provides scaledDensity,
|
||||||
|
) {
|
||||||
AppContent(
|
AppContent(
|
||||||
env = env,
|
env = env,
|
||||||
settings = settings,
|
settings = settings,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlin.math.roundToInt
|
||||||
import org.prolibertate.games.settings.Settings
|
import org.prolibertate.games.settings.Settings
|
||||||
import org.prolibertate.games.update.Release
|
import org.prolibertate.games.update.Release
|
||||||
import org.prolibertate.games.update.UpdateChannel
|
import org.prolibertate.games.update.UpdateChannel
|
||||||
@@ -83,6 +84,26 @@ fun SettingsScreen(
|
|||||||
|
|
||||||
Divider()
|
Divider()
|
||||||
|
|
||||||
|
Column {
|
||||||
|
Text("Text size", fontWeight = FontWeight.Bold)
|
||||||
|
Text(
|
||||||
|
text = "${(settings.textScale * 100).roundToInt()}% — " +
|
||||||
|
"scales text throughout the app, on top of your phone's setting",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
)
|
||||||
|
Slider(
|
||||||
|
value = settings.textScale,
|
||||||
|
onValueChange = { scale ->
|
||||||
|
scope.launch { env.settingsRepository.setTextScale(scale) }
|
||||||
|
},
|
||||||
|
valueRange = Settings.MIN_TEXT_SCALE..Settings.MAX_TEXT_SCALE,
|
||||||
|
// 10% increments across 80%-160%.
|
||||||
|
steps = 7,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
Text("Your name", fontWeight = FontWeight.Bold)
|
Text("Your name", fontWeight = FontWeight.Bold)
|
||||||
Text(
|
Text(
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import androidx.compose.foundation.clickable
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.Canvas
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
@@ -30,6 +31,7 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import org.prolibertate.games.game.yahtzee.DICE_COUNT
|
import org.prolibertate.games.game.yahtzee.DICE_COUNT
|
||||||
@@ -69,6 +71,7 @@ fun YahtzeeScreen(
|
|||||||
|
|
||||||
val kept = remember { mutableStateListOf<Int>() }
|
val kept = remember { mutableStateListOf<Int>() }
|
||||||
var confirmingEnd by remember { mutableStateOf(false) }
|
var confirmingEnd by remember { mutableStateOf(false) }
|
||||||
|
var confirmingZero by remember { mutableStateOf<YahtzeeCategory?>(null) }
|
||||||
|
|
||||||
val endGameAction: @Composable () -> Unit = {
|
val endGameAction: @Composable () -> Unit = {
|
||||||
TextButton(onClick = { confirmingEnd = true }) { Text("End game") }
|
TextButton(onClick = { confirmingEnd = true }) { Text("End game") }
|
||||||
@@ -138,8 +141,14 @@ fun YahtzeeScreen(
|
|||||||
localSeat = localSeat,
|
localSeat = localSeat,
|
||||||
writable = if (yours) writable else emptySet(),
|
writable = if (yours) writable else emptySet(),
|
||||||
onWrite = {
|
onWrite = {
|
||||||
|
// A zero is a box spent for nothing, and one mis-tap on a
|
||||||
|
// dense card is all it takes, so ask first.
|
||||||
|
if (scoreOf(it, current.dice) == 0) {
|
||||||
|
confirmingZero = it
|
||||||
|
} else {
|
||||||
controller.submit(ScoreIn(it))
|
controller.submit(ScoreIn(it))
|
||||||
kept.clear()
|
kept.clear()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -150,7 +159,29 @@ fun YahtzeeScreen(
|
|||||||
|
|
||||||
abandoned?.let { LeftCardDialog(it, onExit, controller::dismissAbandoned) }
|
abandoned?.let { LeftCardDialog(it, onExit, controller::dismissAbandoned) }
|
||||||
if (confirmingEnd) EndCardDialog(onExit) { confirmingEnd = false }
|
if (confirmingEnd) EndCardDialog(onExit) { confirmingEnd = false }
|
||||||
|
confirmingZero?.let { category ->
|
||||||
|
ZeroScoreDialog(
|
||||||
|
category = category,
|
||||||
|
onConfirm = {
|
||||||
|
confirmingZero = null
|
||||||
|
controller.submit(ScoreIn(category))
|
||||||
|
kept.clear()
|
||||||
|
},
|
||||||
|
onCancel = { confirmingZero = null },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ZeroScoreDialog(category: YahtzeeCategory, onConfirm: () -> Unit, onCancel: () -> Unit) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onCancel,
|
||||||
|
title = { Text("Score zero?") },
|
||||||
|
text = { Text("These dice are worth 0 in ${category.label}. Write the zero there?") },
|
||||||
|
confirmButton = { TextButton(onClick = onConfirm) { Text("Score 0") } },
|
||||||
|
dismissButton = { TextButton(onClick = onCancel) { Text("Choose another") } },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -190,12 +221,29 @@ private fun Die(face: Int?, held: Boolean, enabled: Boolean, onClick: () -> Unit
|
|||||||
.clickable(enabled = enabled) { onClick() },
|
.clickable(enabled = enabled) { onClick() },
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center,
|
||||||
) {
|
) {
|
||||||
Text(
|
if (face != null) {
|
||||||
text = face?.toString() ?: "·",
|
Canvas(modifier = Modifier.size(48.dp)) {
|
||||||
style = MaterialTheme.typography.titleLarge,
|
val radius = size.minDimension * 0.08f
|
||||||
fontWeight = FontWeight.Bold,
|
pipPositions(face).forEach { (x, y) ->
|
||||||
color = WallaceRed,
|
drawCircle(WallaceRed, radius, Offset(size.width * x, size.height * y))
|
||||||
)
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Pip centres as fractions of the die face, in the usual casino layout. */
|
||||||
|
private fun pipPositions(face: Int): List<Pair<Float, Float>> {
|
||||||
|
val lo = 0.28f
|
||||||
|
val mid = 0.5f
|
||||||
|
val hi = 0.72f
|
||||||
|
return when (face) {
|
||||||
|
1 -> listOf(mid to mid)
|
||||||
|
2 -> listOf(lo to lo, hi to hi)
|
||||||
|
3 -> listOf(lo to lo, mid to mid, hi to hi)
|
||||||
|
4 -> listOf(lo to lo, hi to lo, lo to hi, hi to hi)
|
||||||
|
5 -> listOf(lo to lo, hi to lo, mid to mid, lo to hi, hi to hi)
|
||||||
|
else -> listOf(lo to lo, hi to lo, lo to mid, hi to mid, lo to hi, hi to hi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,42 +106,33 @@ class CatalogTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `every reference game in the catalogue can be played`() {
|
fun `every game in the catalogue can be played`() {
|
||||||
// Every game the app ships is playable. The exceptions are the games
|
// `available` is the release gate. Nothing is held back at the moment,
|
||||||
// whose engine and screen exist but have not been verified on a real
|
// so a production menu lists every game; a game parked behind the gate
|
||||||
// device yet: they are marked as previews so a production build keeps
|
// belongs in `devPreview`, and must say so rather than being quietly
|
||||||
// them out while a dev one can open them. `available = false` is what
|
// unavailable everywhere.
|
||||||
// keeps an unverified game out of a production build while leaving it
|
GameCatalog.all.filterNot { it.available }.forEach { game ->
|
||||||
// visible on a dev one.
|
assertTrue("${game.id} is unavailable but not a dev preview", game.devPreview)
|
||||||
assertEquals(
|
}
|
||||||
listOf(GameCatalog.CATAN, GameCatalog.MEOWDOKU),
|
GameMenu.entries.forEach { menu ->
|
||||||
GameCatalog.all.filterNot { it.available }.map { it.id },
|
val held = GameCatalog.inMenu(menu, includeComingSoon = true) -
|
||||||
)
|
GameCatalog.inMenu(menu, includeComingSoon = false).toSet()
|
||||||
// It is also the only difference the two channels see in a menu.
|
held.forEach { assertTrue("${it.id} hidden from production without a preview flag", it.devPreview) }
|
||||||
// Katan sits under Board and Meowdoku under Solitaire, so the two
|
}
|
||||||
// channels part ways in different sections.
|
|
||||||
val hiddenFromBoard = GameCatalog.inMenu(GameMenu.BOARD, includeComingSoon = true) -
|
|
||||||
GameCatalog.inMenu(GameMenu.BOARD, includeComingSoon = false)
|
|
||||||
assertEquals(listOf(GameCatalog.byId(GameCatalog.CATAN)!!), hiddenFromBoard)
|
|
||||||
val hiddenFromSolitaire = GameCatalog.inMenu(GameMenu.SOLITAIRE, includeComingSoon = true) -
|
|
||||||
GameCatalog.inMenu(GameMenu.SOLITAIRE, includeComingSoon = false)
|
|
||||||
assertEquals(listOf(GameCatalog.byId(GameCatalog.MEOWDOKU)!!), hiddenFromSolitaire)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `a preview game opens on a dev build and nowhere else`() {
|
fun `a preview game opens on a dev build and nowhere else`() {
|
||||||
// Katan until its two-device play is verified; Meowdoku until its board
|
GameCatalog.all.filter { it.devPreview }.forEach { game ->
|
||||||
// and hearts have been looked at on a real screen.
|
|
||||||
val preview = GameCatalog.all.filter { it.devPreview }
|
|
||||||
assertEquals(
|
|
||||||
setOf(GameCatalog.CATAN, GameCatalog.MEOWDOKU),
|
|
||||||
preview.map { it.id }.toSet(),
|
|
||||||
)
|
|
||||||
preview.forEach { game ->
|
|
||||||
assertFalse("${game.id}: preview is for games that are not yet available", game.available)
|
assertFalse("${game.id}: preview is for games that are not yet available", game.available)
|
||||||
assertTrue("${game.id} should open on a dev build", game.playableIn(devBuild = true))
|
assertTrue("${game.id} should open on a dev build", game.playableIn(devBuild = true))
|
||||||
assertFalse("${game.id} must not open in production", game.playableIn(devBuild = false))
|
assertFalse("${game.id} must not open in production", game.playableIn(devBuild = false))
|
||||||
}
|
}
|
||||||
|
// The two games that were once previews now open everywhere.
|
||||||
|
listOf(GameCatalog.CATAN, GameCatalog.MEOWDOKU).forEach { id ->
|
||||||
|
val game = GameCatalog.byId(id)!!
|
||||||
|
assertTrue("$id should open in production", game.playableIn(devBuild = false))
|
||||||
|
}
|
||||||
// An ordinary finished game opens everywhere.
|
// An ordinary finished game opens everywhere.
|
||||||
val chess = GameCatalog.byId(GameCatalog.CHESS)!!
|
val chess = GameCatalog.byId(GameCatalog.CHESS)!!
|
||||||
assertTrue(chess.playableIn(devBuild = true) && chess.playableIn(devBuild = false))
|
assertTrue(chess.playableIn(devBuild = true) && chess.playableIn(devBuild = false))
|
||||||
@@ -186,6 +177,8 @@ class CatalogTest {
|
|||||||
GameCatalog.MASTERMIND,
|
GameCatalog.MASTERMIND,
|
||||||
GameCatalog.BACKGAMMON,
|
GameCatalog.BACKGAMMON,
|
||||||
GameCatalog.PIRATES,
|
GameCatalog.PIRATES,
|
||||||
|
GameCatalog.CATAN,
|
||||||
|
GameCatalog.MEOWDOKU,
|
||||||
),
|
),
|
||||||
GameCatalog.playable.map { it.id }.toSet(),
|
GameCatalog.playable.map { it.id }.toSet(),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user