Add option for initial Points, remove second color data constructor (not supported by serialize), formatting

This commit is contained in:
Oliver Rümpelein 2021-09-18 12:58:25 +02:00
parent 30cdfdcd17
commit d7420415bc
18 changed files with 32 additions and 37 deletions

View File

@ -98,7 +98,8 @@
}
},
{
"name": "Playerererer"
"name": "Playerererer",
"initialPoints": 1000
},
{
"name": "P3"

View File

@ -40,7 +40,7 @@ fun graphicalApplication(gameDataJson: String) = application {
MaterialTheme {
val playerPointMap: MutableMap<Player, Long> = remember {
loadedGame.players.map { it to 0L }.toMutableStateMap()
loadedGame.players.map { it to it.initialPoints }.toMutableStateMap()
}
val questionsResolved: MutableMap<QuestionData, QuestionResolution> = remember {

View File

@ -18,7 +18,7 @@ import data.toColorOrDefault
fun PlayerCard(
player: Player,
maxHeightFraction: Float,
points: Long
points: Long,
) {
Surface(
color = player.color.toColorOrDefault(),

View File

@ -22,7 +22,7 @@ private fun Modifier.setButtonSize(heightFraction: Float) = this.fillMaxWidth(1f
data class QuestionResolution(
val answered: Boolean,
val player: Player?
val player: Player?,
)
@Composable
@ -36,7 +36,7 @@ fun Question(
heightFraction: Float,
color: Color,
onPointsChange: (Player, Long) -> Unit,
onResolve: (QuestionData, QuestionResolution) -> Unit
onResolve: (QuestionData, QuestionResolution) -> Unit,
) {
var questionVisible by remember { mutableStateOf(false) }
var pointsButtonActive by remember { mutableStateOf(false) }

View File

@ -1,7 +1,7 @@
package components
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import data.Game
import data.Player
import data.QuestionData
@ -13,7 +13,7 @@ fun QuestionGrid(
secondRoundDouble: Boolean,
questionResolved: Map<QuestionData, QuestionResolution>,
onPointsChange: (player: Player, points: Long) -> Unit,
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit,
) {
val users = game.players
val numberOfColumns = game.topics.size

View File

@ -9,7 +9,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.em
import data.*
import data.Player
import data.QuestionData
import data.Topic
import data.toColorOrDefault
@Composable
@Suppress("FunctionName")
@ -20,7 +23,7 @@ fun TopicRow(
columnFraction: Float,
questionsResolved: Map<QuestionData, QuestionResolution>,
onPointsChange: (Player, Long) -> Unit,
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit,
) {
val topicColor = topic.color.toColorOrDefault()
Column(
@ -50,7 +53,8 @@ fun TopicRow(
topic = topic,
secondRoundDouble = secondRoundDouble,
players = users,
questionResolved = questionsResolved[question] ?: error("No resolution found for question ${question.hint}"),
questionResolved = questionsResolved[question]
?: error("No resolution found for question ${question.hint}"),
heightFraction = buttonHeightFraction,
color = topicColor,
onPointsChange = onPointsChange,

View File

@ -22,7 +22,7 @@ import data.toColorOrDefault
fun EndCard(
playerPointMap: Map<Player, Long>,
reviewBoard: () -> Unit,
close: () -> Unit
close: () -> Unit,
) {
val sortedPlayersPoints = playerPointMap.entries
.sortedByDescending { it.value }
@ -68,7 +68,7 @@ fun HighScoreListEntry(
player: Player,
rank: Int,
points: Long,
fontSize: TextUnit
fontSize: TextUnit,
) {
Box(
modifier = Modifier.border(border = BorderStroke(5.dp, player.color.toColorOrDefault()))

View File

@ -21,7 +21,7 @@ fun QuestionDialogue(
players: List<Player>,
secondRoundDouble: Boolean,
onResolve: (QuestionResolution) -> Unit,
onPointsChange: (Player, Long) -> Unit
onPointsChange: (Player, Long) -> Unit,
) {
AlertDialog(
dialogProvider = UndecoratedWindowAlertDialogProvider,

View File

@ -26,7 +26,7 @@ fun QuestionDialogContent(
players: List<Player>,
onPointsChange: (Player, Long) -> Unit,
onResolve: (QuestionResolution) -> Unit,
secondRoundDouble: Boolean
secondRoundDouble: Boolean,
) {
val fontSize = 5.em
var showAnswer by remember { mutableStateOf(false) }

View File

@ -16,7 +16,7 @@ fun HintText(
points: UInt,
hint: String,
deferredDouble: Boolean = false,
doubleJeopardy: Boolean = false
doubleJeopardy: Boolean = false,
) {
Row(
verticalAlignment = Alignment.Top,

View File

@ -1,6 +1,8 @@
package components.questiondialog.buttons
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable

View File

@ -22,7 +22,7 @@ fun DeferredDoubleQuestionDialogPlayer(
onPointsChange: (Player, Long) -> Unit,
onQuestionDone: () -> Unit,
onQuestionAnswered: (Player) -> Unit,
questionPoints: Long
questionPoints: Long,
) {
Row(
modifier = Modifier.fillMaxWidth(),

View File

@ -20,7 +20,7 @@ fun QuestionDialogPlayer(
fontSize: TextUnit,
onPointsChange: (Player, Long) -> Unit,
questionPoints: Long,
onQuestionAnswered: (Player) -> Unit
onQuestionAnswered: (Player) -> Unit,
) {
Row(
modifier = Modifier.fillMaxWidth(),
@ -37,7 +37,6 @@ fun QuestionDialogPlayer(
if (hadFail) {
DisabledButton(maxWidthFraction = 1f, fontSize = fontSize)
} else {
// TODO: Implement "answer" view
BadAnswerButton(
fontSize = fontSize,
onClick = {

View File

@ -7,20 +7,8 @@ import kotlinx.serialization.Serializable
class ColorData(
val red: Int,
val green: Int,
val blue: Int
) {
constructor(rgbHexString: String) : this(
red = rgbHexString.redFromHex(),
green = rgbHexString.greenFromHex(),
blue = rgbHexString.blueFromHex()
)
}
internal fun String.colorFromHex(startPos: Int) = ("0x" + this[startPos] + this[startPos + 1]).toInt()
internal fun String.redFromHex() = colorFromHex(2)
internal fun String.greenFromHex() = colorFromHex(4)
internal fun String.blueFromHex() = colorFromHex(6)
val blue: Int,
)
fun ColorData?.toColorOrNull() = this?.toColor()
fun ColorData?.toColorOrDefault() = this?.toColor() ?: Color.Blue

View File

@ -9,5 +9,5 @@ class Game(
val players: List<Player>,
val headerColor: ColorData? = null,
val doubleAfter: Long = Long.MAX_VALUE,
val endGameAfter: Long = Long.MAX_VALUE
val endGameAfter: Long = Long.MAX_VALUE,
)

View File

@ -5,5 +5,6 @@ import kotlinx.serialization.Serializable
@Serializable
class Player(
val name: String,
val color: ColorData? = null
val color: ColorData? = null,
val initialPoints: Long = 0,
)

View File

@ -8,7 +8,7 @@ class QuestionData(
val answer: String,
val points: UInt,
val isDouble: Boolean = false,
val isDeferredDouble: Boolean = false
val isDeferredDouble: Boolean = false,
) {
fun actualDisplayPoints(double: Boolean) = points * (if (double) 2u else 1u)
fun actualUsagePoints(double: Boolean) = points * (if (double) 2u else 1u) * (if (isDouble) 2u else 1u)

View File

@ -6,5 +6,5 @@ import kotlinx.serialization.Serializable
class Topic(
val topic: String,
val questions: List<QuestionData>,
val color: ColorData? = null
val color: ColorData? = null,
)