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"
|
"name": "P3"
|
||||||
|
|
|
@ -40,7 +40,7 @@ fun graphicalApplication(gameDataJson: String) = application {
|
||||||
|
|
||||||
MaterialTheme {
|
MaterialTheme {
|
||||||
val playerPointMap: MutableMap<Player, Long> = remember {
|
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 {
|
val questionsResolved: MutableMap<QuestionData, QuestionResolution> = remember {
|
||||||
|
|
|
@ -18,7 +18,7 @@ import data.toColorOrDefault
|
||||||
fun PlayerCard(
|
fun PlayerCard(
|
||||||
player: Player,
|
player: Player,
|
||||||
maxHeightFraction: Float,
|
maxHeightFraction: Float,
|
||||||
points: Long
|
points: Long,
|
||||||
) {
|
) {
|
||||||
Surface(
|
Surface(
|
||||||
color = player.color.toColorOrDefault(),
|
color = player.color.toColorOrDefault(),
|
||||||
|
|
|
@ -22,7 +22,7 @@ private fun Modifier.setButtonSize(heightFraction: Float) = this.fillMaxWidth(1f
|
||||||
|
|
||||||
data class QuestionResolution(
|
data class QuestionResolution(
|
||||||
val answered: Boolean,
|
val answered: Boolean,
|
||||||
val player: Player?
|
val player: Player?,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -36,7 +36,7 @@ fun Question(
|
||||||
heightFraction: Float,
|
heightFraction: Float,
|
||||||
color: Color,
|
color: Color,
|
||||||
onPointsChange: (Player, Long) -> Unit,
|
onPointsChange: (Player, Long) -> Unit,
|
||||||
onResolve: (QuestionData, QuestionResolution) -> Unit
|
onResolve: (QuestionData, QuestionResolution) -> Unit,
|
||||||
) {
|
) {
|
||||||
var questionVisible by remember { mutableStateOf(false) }
|
var questionVisible by remember { mutableStateOf(false) }
|
||||||
var pointsButtonActive by remember { mutableStateOf(false) }
|
var pointsButtonActive by remember { mutableStateOf(false) }
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package components
|
package components
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.Composable
|
||||||
import data.Game
|
import data.Game
|
||||||
import data.Player
|
import data.Player
|
||||||
import data.QuestionData
|
import data.QuestionData
|
||||||
|
@ -13,7 +13,7 @@ fun QuestionGrid(
|
||||||
secondRoundDouble: Boolean,
|
secondRoundDouble: Boolean,
|
||||||
questionResolved: Map<QuestionData, QuestionResolution>,
|
questionResolved: Map<QuestionData, QuestionResolution>,
|
||||||
onPointsChange: (player: Player, points: Long) -> Unit,
|
onPointsChange: (player: Player, points: Long) -> Unit,
|
||||||
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit
|
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit,
|
||||||
) {
|
) {
|
||||||
val users = game.players
|
val users = game.players
|
||||||
val numberOfColumns = game.topics.size
|
val numberOfColumns = game.topics.size
|
||||||
|
|
|
@ -9,7 +9,10 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.em
|
import androidx.compose.ui.unit.em
|
||||||
import data.*
|
import data.Player
|
||||||
|
import data.QuestionData
|
||||||
|
import data.Topic
|
||||||
|
import data.toColorOrDefault
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Suppress("FunctionName")
|
@Suppress("FunctionName")
|
||||||
|
@ -20,7 +23,7 @@ fun TopicRow(
|
||||||
columnFraction: Float,
|
columnFraction: Float,
|
||||||
questionsResolved: Map<QuestionData, QuestionResolution>,
|
questionsResolved: Map<QuestionData, QuestionResolution>,
|
||||||
onPointsChange: (Player, Long) -> Unit,
|
onPointsChange: (Player, Long) -> Unit,
|
||||||
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit
|
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit,
|
||||||
) {
|
) {
|
||||||
val topicColor = topic.color.toColorOrDefault()
|
val topicColor = topic.color.toColorOrDefault()
|
||||||
Column(
|
Column(
|
||||||
|
@ -50,7 +53,8 @@ fun TopicRow(
|
||||||
topic = topic,
|
topic = topic,
|
||||||
secondRoundDouble = secondRoundDouble,
|
secondRoundDouble = secondRoundDouble,
|
||||||
players = users,
|
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,
|
heightFraction = buttonHeightFraction,
|
||||||
color = topicColor,
|
color = topicColor,
|
||||||
onPointsChange = onPointsChange,
|
onPointsChange = onPointsChange,
|
||||||
|
|
|
@ -22,7 +22,7 @@ import data.toColorOrDefault
|
||||||
fun EndCard(
|
fun EndCard(
|
||||||
playerPointMap: Map<Player, Long>,
|
playerPointMap: Map<Player, Long>,
|
||||||
reviewBoard: () -> Unit,
|
reviewBoard: () -> Unit,
|
||||||
close: () -> Unit
|
close: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val sortedPlayersPoints = playerPointMap.entries
|
val sortedPlayersPoints = playerPointMap.entries
|
||||||
.sortedByDescending { it.value }
|
.sortedByDescending { it.value }
|
||||||
|
@ -68,7 +68,7 @@ fun HighScoreListEntry(
|
||||||
player: Player,
|
player: Player,
|
||||||
rank: Int,
|
rank: Int,
|
||||||
points: Long,
|
points: Long,
|
||||||
fontSize: TextUnit
|
fontSize: TextUnit,
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.border(border = BorderStroke(5.dp, player.color.toColorOrDefault()))
|
modifier = Modifier.border(border = BorderStroke(5.dp, player.color.toColorOrDefault()))
|
||||||
|
|
|
@ -21,7 +21,7 @@ fun QuestionDialogue(
|
||||||
players: List<Player>,
|
players: List<Player>,
|
||||||
secondRoundDouble: Boolean,
|
secondRoundDouble: Boolean,
|
||||||
onResolve: (QuestionResolution) -> Unit,
|
onResolve: (QuestionResolution) -> Unit,
|
||||||
onPointsChange: (Player, Long) -> Unit
|
onPointsChange: (Player, Long) -> Unit,
|
||||||
) {
|
) {
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
dialogProvider = UndecoratedWindowAlertDialogProvider,
|
dialogProvider = UndecoratedWindowAlertDialogProvider,
|
||||||
|
|
|
@ -26,7 +26,7 @@ fun QuestionDialogContent(
|
||||||
players: List<Player>,
|
players: List<Player>,
|
||||||
onPointsChange: (Player, Long) -> Unit,
|
onPointsChange: (Player, Long) -> Unit,
|
||||||
onResolve: (QuestionResolution) -> Unit,
|
onResolve: (QuestionResolution) -> Unit,
|
||||||
secondRoundDouble: Boolean
|
secondRoundDouble: Boolean,
|
||||||
) {
|
) {
|
||||||
val fontSize = 5.em
|
val fontSize = 5.em
|
||||||
var showAnswer by remember { mutableStateOf(false) }
|
var showAnswer by remember { mutableStateOf(false) }
|
||||||
|
|
|
@ -16,7 +16,7 @@ fun HintText(
|
||||||
points: UInt,
|
points: UInt,
|
||||||
hint: String,
|
hint: String,
|
||||||
deferredDouble: Boolean = false,
|
deferredDouble: Boolean = false,
|
||||||
doubleJeopardy: Boolean = false
|
doubleJeopardy: Boolean = false,
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.Top,
|
verticalAlignment = Alignment.Top,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package components.questiondialog.buttons
|
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.Button
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
|
|
@ -22,7 +22,7 @@ fun DeferredDoubleQuestionDialogPlayer(
|
||||||
onPointsChange: (Player, Long) -> Unit,
|
onPointsChange: (Player, Long) -> Unit,
|
||||||
onQuestionDone: () -> Unit,
|
onQuestionDone: () -> Unit,
|
||||||
onQuestionAnswered: (Player) -> Unit,
|
onQuestionAnswered: (Player) -> Unit,
|
||||||
questionPoints: Long
|
questionPoints: Long,
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
|
|
@ -20,7 +20,7 @@ fun QuestionDialogPlayer(
|
||||||
fontSize: TextUnit,
|
fontSize: TextUnit,
|
||||||
onPointsChange: (Player, Long) -> Unit,
|
onPointsChange: (Player, Long) -> Unit,
|
||||||
questionPoints: Long,
|
questionPoints: Long,
|
||||||
onQuestionAnswered: (Player) -> Unit
|
onQuestionAnswered: (Player) -> Unit,
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
@ -37,7 +37,6 @@ fun QuestionDialogPlayer(
|
||||||
if (hadFail) {
|
if (hadFail) {
|
||||||
DisabledButton(maxWidthFraction = 1f, fontSize = fontSize)
|
DisabledButton(maxWidthFraction = 1f, fontSize = fontSize)
|
||||||
} else {
|
} else {
|
||||||
// TODO: Implement "answer" view
|
|
||||||
BadAnswerButton(
|
BadAnswerButton(
|
||||||
fontSize = fontSize,
|
fontSize = fontSize,
|
||||||
onClick = {
|
onClick = {
|
||||||
|
|
|
@ -7,20 +7,8 @@ import kotlinx.serialization.Serializable
|
||||||
class ColorData(
|
class ColorData(
|
||||||
val red: Int,
|
val red: Int,
|
||||||
val green: Int,
|
val green: Int,
|
||||||
val blue: 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)
|
|
||||||
|
|
||||||
fun ColorData?.toColorOrNull() = this?.toColor()
|
fun ColorData?.toColorOrNull() = this?.toColor()
|
||||||
fun ColorData?.toColorOrDefault() = this?.toColor() ?: Color.Blue
|
fun ColorData?.toColorOrDefault() = this?.toColor() ?: Color.Blue
|
||||||
|
|
|
@ -9,5 +9,5 @@ class Game(
|
||||||
val players: List<Player>,
|
val players: List<Player>,
|
||||||
val headerColor: ColorData? = null,
|
val headerColor: ColorData? = null,
|
||||||
val doubleAfter: Long = Long.MAX_VALUE,
|
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
|
@Serializable
|
||||||
class Player(
|
class Player(
|
||||||
val name: String,
|
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 answer: String,
|
||||||
val points: UInt,
|
val points: UInt,
|
||||||
val isDouble: Boolean = false,
|
val isDouble: Boolean = false,
|
||||||
val isDeferredDouble: Boolean = false
|
val isDeferredDouble: Boolean = false,
|
||||||
) {
|
) {
|
||||||
fun actualDisplayPoints(double: Boolean) = points * (if (double) 2u else 1u)
|
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)
|
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(
|
class Topic(
|
||||||
val topic: String,
|
val topic: String,
|
||||||
val questions: List<QuestionData>,
|
val questions: List<QuestionData>,
|
||||||
val color: ColorData? = null
|
val color: ColorData? = null,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue