Proper Startup-Interface & template game.json
This commit is contained in:
parent
44d9e533af
commit
a1d9285f2f
7 changed files with 149 additions and 120 deletions
|
@ -12,7 +12,6 @@ group = "de.pheerai"
|
||||||
version = "1.0.0-SNAPSHOT"
|
version = "1.0.0-SNAPSHOT"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
google()
|
google()
|
||||||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
|
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
|
||||||
|
@ -21,6 +20,8 @@ repositories {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(compose.desktop.currentOs)
|
implementation(compose.desktop.currentOs)
|
||||||
implementation("org.jetbrains.kotlinx", "kotlinx-serialization-json", "1.2.2")
|
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"))
|
testImplementation(kotlin("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
104
game.json
Normal file
104
game.json
Normal file
|
@ -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
|
||||||
|
}
|
|
@ -2,134 +2,44 @@ import androidx.compose.material.MaterialTheme
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.window.Window
|
import androidx.compose.ui.window.Window
|
||||||
import androidx.compose.ui.window.application
|
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.EndCard
|
||||||
import components.QuestionResolution
|
import components.QuestionResolution
|
||||||
import data.*
|
import data.*
|
||||||
import kotlinx.serialization.ExperimentalSerializationApi
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
import kotlinx.serialization.encodeToString
|
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
import kotlin.io.path.Path
|
||||||
|
|
||||||
val gameData = Game(
|
fun main(args: Array<String>) = App().main(args)
|
||||||
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
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
@OptIn(ExperimentalSerializationApi::class)
|
class App : CliktCommand() {
|
||||||
val gameJson = Json.encodeToString(gameData)
|
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() {
|
override fun run() {
|
||||||
graphicalApplication()
|
graphicalApplication(gameFile.readText())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalSerializationApi::class)
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
fun graphicalApplication() = application {
|
fun graphicalApplication(gameDataJson: String) = application {
|
||||||
// TODO: Read Game from JSON
|
|
||||||
println(gameJson)
|
|
||||||
Window(
|
Window(
|
||||||
onCloseRequest = ::exitApplication,
|
onCloseRequest = ::exitApplication,
|
||||||
title = "J-EP-ardy"
|
title = "J-EP-ardy"
|
||||||
) {
|
) {
|
||||||
val loadedGameJson = gameJson
|
val loadedGame = Json.decodeFromString<Game>(gameDataJson)
|
||||||
val loadedGame = Json.decodeFromString<Game>(loadedGameJson)
|
|
||||||
|
|
||||||
MaterialTheme {
|
MaterialTheme {
|
||||||
val playerPointMap: MutableMap<Player, Long> =
|
val playerPointMap: MutableMap<Player, Long> = remember {
|
||||||
loadedGame.players.map { it to 0L }.toMutableStateMap()
|
loadedGame.players.map { it to 0L }.toMutableStateMap()
|
||||||
|
}
|
||||||
|
|
||||||
val questionsResolved: MutableMap<QuestionData, QuestionResolution> = remember {
|
val questionsResolved: MutableMap<QuestionData, QuestionResolution> = remember {
|
||||||
loadedGame.topics
|
loadedGame.topics
|
||||||
|
|
|
@ -8,6 +8,7 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.input.pointer.pointerMoveFilter
|
import androidx.compose.ui.input.pointer.pointerMoveFilter
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.em
|
||||||
import components.questiondialog.QuestionDialogue
|
import components.questiondialog.QuestionDialogue
|
||||||
import data.Player
|
import data.Player
|
||||||
import data.QuestionData
|
import data.QuestionData
|
||||||
|
@ -79,6 +80,7 @@ fun Question(
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "${questionData.actualDisplayPoints(secondRoundDouble)}",
|
text = "${questionData.actualDisplayPoints(secondRoundDouble)}",
|
||||||
|
fontSize = 3.em,
|
||||||
color = if (pointsButtonActive) Color.Gray else Color.LightGray
|
color = if (pointsButtonActive) Color.Gray else Color.LightGray
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ fun QuestionDialogButtons(
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.fillMaxHeight().fillMaxWidth()
|
modifier = Modifier.fillMaxHeight().fillMaxWidth()
|
||||||
.border(
|
.border(
|
||||||
border = BorderStroke(150.dp, topicColor.toColor())
|
border = BorderStroke(50.dp, topicColor.toColor())
|
||||||
)
|
)
|
||||||
.padding(150.dp),
|
.padding(150.dp),
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center,
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
package components.questiondialog.assets
|
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.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.unit.em
|
import androidx.compose.ui.unit.em
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -13,10 +18,16 @@ fun HintText(
|
||||||
deferredDouble: Boolean = false,
|
deferredDouble: Boolean = false,
|
||||||
doubleJeopardy: Boolean = false
|
doubleJeopardy: Boolean = false
|
||||||
) {
|
) {
|
||||||
Text(
|
Row(
|
||||||
text = """"$topicName" for $points Pts.""",
|
verticalAlignment = Alignment.Top,
|
||||||
fontSize = 2.em
|
horizontalArrangement = Arrangement.Start,
|
||||||
)
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = """"$topicName" for $points Pts.""",
|
||||||
|
fontSize = 2.em
|
||||||
|
)
|
||||||
|
}
|
||||||
if (deferredDouble) {
|
if (deferredDouble) {
|
||||||
Text(
|
Text(
|
||||||
text = """Deferred Double!""",
|
text = """Deferred Double!""",
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package components.questiondialog.buttons
|
package components.questiondialog.buttons
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
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
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.unit.TextUnit
|
import androidx.compose.ui.unit.TextUnit
|
||||||
|
|
||||||
|
@ -13,15 +13,16 @@ import androidx.compose.ui.unit.TextUnit
|
||||||
@Composable
|
@Composable
|
||||||
fun DismissButton(onResolve: () -> Unit, fontSize: TextUnit) {
|
fun DismissButton(onResolve: () -> Unit, fontSize: TextUnit) {
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.End,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.Bottom,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
onResolve()
|
onResolve()
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Text("Dismiss Question", color = Color.LightGray, fontSize = fontSize)
|
Text("Dismiss", color = Color.LightGray, fontSize = fontSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue