From 5a5f0e16a454721f8ad978cf3fb980ac5a7f6293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Thu, 19 Aug 2021 12:18:23 +0200 Subject: [PATCH] Store question answers for review --- src/main/kotlin/GameBoard.kt | 2 ++ src/main/kotlin/Main.kt | 1 + src/main/kotlin/components/Question.kt | 7 +++---- src/main/kotlin/components/QuestionGrid.kt | 2 ++ src/main/kotlin/components/TopicRow.kt | 2 ++ 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/GameBoard.kt b/src/main/kotlin/GameBoard.kt index 1cb8211..92ab5a7 100644 --- a/src/main/kotlin/GameBoard.kt +++ b/src/main/kotlin/GameBoard.kt @@ -17,6 +17,7 @@ fun GameBoard( reviewModeActive: Boolean, secondRoundDouble: Boolean, playerPointMap: Map, + questionsResolved: Map, onDisableReviewMode: () -> Unit, onPointsChange: (Player, Long) -> Unit, onQuestionDone: (QuestionData, QuestionResolution) -> Unit, @@ -43,6 +44,7 @@ fun GameBoard( QuestionGrid( game, secondRoundDouble, + questionsResolved, onResolveQuestion = onQuestionDone, onPointsChange = onPointsChange ) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index d9a8994..878350e 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -137,6 +137,7 @@ fun main() = application { reviewModeActive, secondRoundDouble, playerPointMap, + questionsResolved, onDisableReviewMode = { reviewModeActive = false }, onPointsChange = { player, points -> playerPointMap[player] = playerPointMap[player]?.plus(points) ?: 0 diff --git a/src/main/kotlin/components/Question.kt b/src/main/kotlin/components/Question.kt index 81d00fa..7a42264 100644 --- a/src/main/kotlin/components/Question.kt +++ b/src/main/kotlin/components/Question.kt @@ -29,23 +29,23 @@ fun Question( secondRoundDouble: Boolean, players: List, topic: Topic, + questionResolved: QuestionResolution, heightFraction: Float, color: Color, onPointsChange: (Player, Long) -> Unit, onResolve: (QuestionData, QuestionResolution) -> Unit ) { var questionVisible by remember { mutableStateOf(false) } - var questionResolution by remember { mutableStateOf(QuestionResolution(false, null)) } var pointsButtonActive by remember { mutableStateOf(false) } - if (questionResolution.answered) { + if (questionResolved.answered) { Surface( shape = MaterialTheme.shapes.small, modifier = Modifier .setButtonSize(heightFraction), color = Color.LightGray, ) { - val player = questionResolution.player + val player = questionResolved.player if (player != null) { Column( modifier = Modifier.fillMaxSize(), @@ -90,7 +90,6 @@ fun Question( players = players, secondRoundDouble = secondRoundDouble, onResolve = { - questionResolution = it questionVisible = false onResolve(questionData, it) }, diff --git a/src/main/kotlin/components/QuestionGrid.kt b/src/main/kotlin/components/QuestionGrid.kt index e3d6d40..434d061 100644 --- a/src/main/kotlin/components/QuestionGrid.kt +++ b/src/main/kotlin/components/QuestionGrid.kt @@ -11,6 +11,7 @@ import data.QuestionData fun QuestionGrid( game: Game, secondRoundDouble: Boolean, + questionResolved: Map, onPointsChange: (player: Player, points: Long) -> Unit, onResolveQuestion: (QuestionData, QuestionResolution) -> Unit ) { @@ -25,6 +26,7 @@ fun QuestionGrid( secondRoundDouble = secondRoundDouble, users = users, columnFraction = maxColumnFraction, + questionsResolved = questionResolved, onPointsChange = onPointsChange, onResolveQuestion = onResolveQuestion ) diff --git a/src/main/kotlin/components/TopicRow.kt b/src/main/kotlin/components/TopicRow.kt index 60bbd5b..80b2798 100644 --- a/src/main/kotlin/components/TopicRow.kt +++ b/src/main/kotlin/components/TopicRow.kt @@ -21,6 +21,7 @@ fun TopicRow( secondRoundDouble: Boolean, users: List, columnFraction: Float, + questionsResolved: Map, onPointsChange: (Player, Long) -> Unit, onResolveQuestion: (QuestionData, QuestionResolution) -> Unit ) { @@ -52,6 +53,7 @@ fun TopicRow( topic = topic, secondRoundDouble = secondRoundDouble, players = users, + questionResolved = questionsResolved[question] ?: error("No resolution found for question ${question.hint}"), heightFraction = buttonHeightFraction, color = topicColor, onPointsChange = onPointsChange,