Add option for initial Points, remove second color data constructor (not supported by serialize), formatting
This commit is contained in:
parent
30cdfdcd17
commit
d7420415bc
18 changed files with 32 additions and 37 deletions
|
@ -98,7 +98,8 @@
|
|||
}
|
||||
},
|
||||
{
|
||||
"name": "Playerererer"
|
||||
"name": "Playerererer",
|
||||
"initialPoints": 1000
|
||||
},
|
||||
{
|
||||
"name": "P3"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -18,7 +18,7 @@ import data.toColorOrDefault
|
|||
fun PlayerCard(
|
||||
player: Player,
|
||||
maxHeightFraction: Float,
|
||||
points: Long
|
||||
points: Long,
|
||||
) {
|
||||
Surface(
|
||||
color = player.color.toColorOrDefault(),
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()))
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -16,7 +16,7 @@ fun HintText(
|
|||
points: UInt,
|
||||
hint: String,
|
||||
deferredDouble: Boolean = false,
|
||||
doubleJeopardy: Boolean = false
|
||||
doubleJeopardy: Boolean = false,
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.Top,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -22,7 +22,7 @@ fun DeferredDoubleQuestionDialogPlayer(
|
|||
onPointsChange: (Player, Long) -> Unit,
|
||||
onQuestionDone: () -> Unit,
|
||||
onQuestionAnswered: (Player) -> Unit,
|
||||
questionPoints: Long
|
||||
questionPoints: Long,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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()
|
||||
val blue: Int,
|
||||
)
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
fun ColorData?.toColorOrNull() = this?.toColor()
|
||||
fun ColorData?.toColorOrDefault() = this?.toColor() ?: Color.Blue
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue