Store question answers for review

This commit is contained in:
Oliver Rümpelein 2021-08-19 12:18:23 +02:00
parent fe7d40c4f0
commit 5a5f0e16a4
5 changed files with 10 additions and 4 deletions

View file

@ -17,6 +17,7 @@ fun GameBoard(
reviewModeActive: Boolean, reviewModeActive: Boolean,
secondRoundDouble: Boolean, secondRoundDouble: Boolean,
playerPointMap: Map<Player, Long>, playerPointMap: Map<Player, Long>,
questionsResolved: Map<QuestionData, QuestionResolution>,
onDisableReviewMode: () -> Unit, onDisableReviewMode: () -> Unit,
onPointsChange: (Player, Long) -> Unit, onPointsChange: (Player, Long) -> Unit,
onQuestionDone: (QuestionData, QuestionResolution) -> Unit, onQuestionDone: (QuestionData, QuestionResolution) -> Unit,
@ -43,6 +44,7 @@ fun GameBoard(
QuestionGrid( QuestionGrid(
game, game,
secondRoundDouble, secondRoundDouble,
questionsResolved,
onResolveQuestion = onQuestionDone, onResolveQuestion = onQuestionDone,
onPointsChange = onPointsChange onPointsChange = onPointsChange
) )

View file

@ -137,6 +137,7 @@ fun main() = application {
reviewModeActive, reviewModeActive,
secondRoundDouble, secondRoundDouble,
playerPointMap, playerPointMap,
questionsResolved,
onDisableReviewMode = { reviewModeActive = false }, onDisableReviewMode = { reviewModeActive = false },
onPointsChange = { player, points -> onPointsChange = { player, points ->
playerPointMap[player] = playerPointMap[player]?.plus(points) ?: 0 playerPointMap[player] = playerPointMap[player]?.plus(points) ?: 0

View file

@ -29,23 +29,23 @@ fun Question(
secondRoundDouble: Boolean, secondRoundDouble: Boolean,
players: List<Player>, players: List<Player>,
topic: Topic, topic: Topic,
questionResolved: QuestionResolution,
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 questionResolution by remember { mutableStateOf(QuestionResolution(false, null)) }
var pointsButtonActive by remember { mutableStateOf(false) } var pointsButtonActive by remember { mutableStateOf(false) }
if (questionResolution.answered) { if (questionResolved.answered) {
Surface( Surface(
shape = MaterialTheme.shapes.small, shape = MaterialTheme.shapes.small,
modifier = Modifier modifier = Modifier
.setButtonSize(heightFraction), .setButtonSize(heightFraction),
color = Color.LightGray, color = Color.LightGray,
) { ) {
val player = questionResolution.player val player = questionResolved.player
if (player != null) { if (player != null) {
Column( Column(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
@ -90,7 +90,6 @@ fun Question(
players = players, players = players,
secondRoundDouble = secondRoundDouble, secondRoundDouble = secondRoundDouble,
onResolve = { onResolve = {
questionResolution = it
questionVisible = false questionVisible = false
onResolve(questionData, it) onResolve(questionData, it)
}, },

View file

@ -11,6 +11,7 @@ import data.QuestionData
fun QuestionGrid( fun QuestionGrid(
game: Game, game: Game,
secondRoundDouble: Boolean, secondRoundDouble: Boolean,
questionResolved: Map<QuestionData, QuestionResolution>,
onPointsChange: (player: Player, points: Long) -> Unit, onPointsChange: (player: Player, points: Long) -> Unit,
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit onResolveQuestion: (QuestionData, QuestionResolution) -> Unit
) { ) {
@ -25,6 +26,7 @@ fun QuestionGrid(
secondRoundDouble = secondRoundDouble, secondRoundDouble = secondRoundDouble,
users = users, users = users,
columnFraction = maxColumnFraction, columnFraction = maxColumnFraction,
questionsResolved = questionResolved,
onPointsChange = onPointsChange, onPointsChange = onPointsChange,
onResolveQuestion = onResolveQuestion onResolveQuestion = onResolveQuestion
) )

View file

@ -21,6 +21,7 @@ fun TopicRow(
secondRoundDouble: Boolean, secondRoundDouble: Boolean,
users: List<Player>, users: List<Player>,
columnFraction: Float, columnFraction: Float,
questionsResolved: Map<QuestionData, QuestionResolution>,
onPointsChange: (Player, Long) -> Unit, onPointsChange: (Player, Long) -> Unit,
onResolveQuestion: (QuestionData, QuestionResolution) -> Unit onResolveQuestion: (QuestionData, QuestionResolution) -> Unit
) { ) {
@ -52,6 +53,7 @@ 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}"),
heightFraction = buttonHeightFraction, heightFraction = buttonHeightFraction,
color = topicColor, color = topicColor,
onPointsChange = onPointsChange, onPointsChange = onPointsChange,