diff --git a/build.gradle.kts b/build.gradle.kts index a4f88ed..d64e2ed 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,6 @@ group = "de.pheerai" version = "1.0.0-SNAPSHOT" repositories { - jcenter() mavenCentral() google() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") @@ -21,6 +20,8 @@ repositories { dependencies { implementation(compose.desktop.currentOs) implementation("org.jetbrains.kotlinx", "kotlinx-serialization-json", "1.2.2") + implementation("com.github.ajalt.clikt", "clikt-jvm", "3.2.0") + implementation("com.github.ajalt.clikt", "clikt", "3.2.0") testImplementation(kotlin("test")) } diff --git a/game.json b/game.json new file mode 100644 index 0000000..b9c2d6f --- /dev/null +++ b/game.json @@ -0,0 +1,104 @@ +{ + "title": "j-party!", + "topics": [ + { + "topic": "Wat?", + "questions": [ + { + "hint": "He", + "answer": "She", + "points": 100, + "isDeferredDouble": true + }, + { + "hint": "It", + "answer": "Who", + "points": 200 + }, + { + "hint": "Why", + "answer": "Where", + "points": 300 + } + ], + "color": { + "red": 68, + "green": 68, + "blue": 170 + } + }, + { + "topic": "Topic2", + "questions": [ + { + "hint": "Wildcard", + "answer": "any", + "points": 1000 + }, + { + "hint": "foo", + "answer": "bar", + "points": 5 + }, + { + "hint": "foo", + "answer": "bar", + "points": 5 + } + ], + "color": { + "red": 34, + "green": 34, + "blue": 204 + } + }, + { + "topic": "Topic3", + "questions": [ + { + "hint": "Wildcard", + "answer": "any", + "points": 1000 + }, + { + "hint": "foo", + "answer": "bar", + "points": 5 + }, + { + "hint": "foo", + "answer": "bar", + "points": 5 + } + ] + }, + { + "topic": "Topic4", + "questions": [ + { + "hint": "Some", + "answer": "thing", + "points": 1000 + }, + { + "hint": "Other", + "answer": "Thing", + "points": 5 + } + ] + } + ], + "players": [ + { + "name": "P1" + }, + { + "name": "P2" + }, + { + "name": "P3" + } + ], + "doubleAfter": 2, + "endGameAfter": 5 +} diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 68f24ec..f7aff8a 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -2,134 +2,44 @@ import androidx.compose.material.MaterialTheme import androidx.compose.runtime.* import androidx.compose.ui.window.Window import androidx.compose.ui.window.application +import com.github.ajalt.clikt.core.CliktCommand +import com.github.ajalt.clikt.parameters.options.default +import com.github.ajalt.clikt.parameters.options.option +import com.github.ajalt.clikt.parameters.types.file import components.EndCard import components.QuestionResolution import data.* import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.decodeFromString -import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +import kotlin.io.path.Path -val gameData = Game( - title = "j-EP-ardy!", - doubleAfter = 2, - endGameAfter = 5, - players = listOf( - Player(name = "Oli"), - Player(name = "Gesina"), - Player(name = "Siggi") - ), - topics = listOf( - Topic( - color = ColorData( - red = 0x44, - green = 0x44, - blue = 0xAA - ), - topic = "Wer?", - questions = listOf( - QuestionData( - hint = "Mack", - answer = "Thomas", - points = 100u, - isDeferredDouble = true - ), - QuestionData( - hint = "Mack", - answer = "Michael", - points = 200u - ), - QuestionData( - hint = "Mack", - answer = "Ann-Kathrin", - points = 300u - ) - ) - ), - Topic( - color = ColorData( - red = 0x22, - green = 0x22, - blue = 0xCC - ), - topic = "Topic2", - questions = listOf( - QuestionData( - hint = "Wildcard", - answer = "any", - points = 1000u - ), - QuestionData( - hint = "foo", - answer = "bar", - points = 5u - ), - QuestionData( - hint = "foo", - answer = "bar", - points = 5u - ) - ) - ), - Topic( - topic = "Topic3", - questions = listOf( - QuestionData( - hint = "Wildcard", - answer = "any", - points = 1000u - ), - QuestionData( - hint = "foo", - answer = "bar", - points = 5u - ), - QuestionData( - hint = "foo", - answer = "bar", - points = 5u - ) - ) - ), - Topic( - topic = "Topic4", - questions = listOf( - QuestionData( - hint = "Some", - answer = "thing", - points = 1000u - ), - QuestionData( - hint = "Other", - answer = "Thing", - points = 5u - ) - ) - ) - ) -) +fun main(args: Array) = App().main(args) -@OptIn(ExperimentalSerializationApi::class) -val gameJson = Json.encodeToString(gameData) +class App : CliktCommand() { + private val gameFile by option("-g", "-f", "--game", help = "Path to Game Json File").file( + mustExist = true, + canBeDir = false, + mustBeReadable = true + ).default(Path("game.json").toFile()) -fun main() { - graphicalApplication() + override fun run() { + graphicalApplication(gameFile.readText()) + } } @OptIn(ExperimentalSerializationApi::class) -fun graphicalApplication() = application { - // TODO: Read Game from JSON - println(gameJson) +fun graphicalApplication(gameDataJson: String) = application { Window( onCloseRequest = ::exitApplication, title = "J-EP-ardy" ) { - val loadedGameJson = gameJson - val loadedGame = Json.decodeFromString(loadedGameJson) + val loadedGame = Json.decodeFromString(gameDataJson) MaterialTheme { - val playerPointMap: MutableMap = + val playerPointMap: MutableMap = remember { loadedGame.players.map { it to 0L }.toMutableStateMap() + } val questionsResolved: MutableMap = remember { loadedGame.topics diff --git a/src/main/kotlin/components/Question.kt b/src/main/kotlin/components/Question.kt index 7a42264..93c1f32 100644 --- a/src/main/kotlin/components/Question.kt +++ b/src/main/kotlin/components/Question.kt @@ -8,6 +8,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.pointer.pointerMoveFilter import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.em import components.questiondialog.QuestionDialogue import data.Player import data.QuestionData @@ -79,6 +80,7 @@ fun Question( ) { Text( text = "${questionData.actualDisplayPoints(secondRoundDouble)}", + fontSize = 3.em, color = if (pointsButtonActive) Color.Gray else Color.LightGray ) } diff --git a/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt index b89d7b1..62cff7a 100644 --- a/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt +++ b/src/main/kotlin/components/questiondialog/QuestionDialogContent.kt @@ -32,7 +32,7 @@ fun QuestionDialogButtons( Box( modifier = Modifier.fillMaxHeight().fillMaxWidth() .border( - border = BorderStroke(150.dp, topicColor.toColor()) + border = BorderStroke(50.dp, topicColor.toColor()) ) .padding(150.dp), contentAlignment = Alignment.Center, diff --git a/src/main/kotlin/components/questiondialog/assets/HintText.kt b/src/main/kotlin/components/questiondialog/assets/HintText.kt index 5895269..e86f411 100644 --- a/src/main/kotlin/components/questiondialog/assets/HintText.kt +++ b/src/main/kotlin/components/questiondialog/assets/HintText.kt @@ -1,7 +1,12 @@ package components.questiondialog.assets +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.compose.ui.unit.em @Composable @@ -13,10 +18,16 @@ fun HintText( deferredDouble: Boolean = false, doubleJeopardy: Boolean = false ) { - Text( - text = """"$topicName" for $points Pts.""", - fontSize = 2.em - ) + Row( + verticalAlignment = Alignment.Top, + horizontalArrangement = Arrangement.Start, + modifier = Modifier.fillMaxWidth() + ) { + Text( + text = """"$topicName" for $points Pts.""", + fontSize = 2.em + ) + } if (deferredDouble) { Text( text = """Deferred Double!""", diff --git a/src/main/kotlin/components/questiondialog/buttons/DismissButton.kt b/src/main/kotlin/components/questiondialog/buttons/DismissButton.kt index 1d4e7eb..2074390 100644 --- a/src/main/kotlin/components/questiondialog/buttons/DismissButton.kt +++ b/src/main/kotlin/components/questiondialog/buttons/DismissButton.kt @@ -1,11 +1,11 @@ package components.questiondialog.buttons -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.* import androidx.compose.material.Button import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.TextUnit @@ -13,15 +13,16 @@ import androidx.compose.ui.unit.TextUnit @Composable fun DismissButton(onResolve: () -> Unit, fontSize: TextUnit) { Row( - horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.CenterVertically + horizontalArrangement = Arrangement.End, + verticalAlignment = Alignment.Bottom, + modifier = Modifier.fillMaxWidth() ) { Button( onClick = { onResolve() } ) { - Text("Dismiss Question", color = Color.LightGray, fontSize = fontSize) + Text("Dismiss", color = Color.LightGray, fontSize = fontSize) } } }