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"
|
||||
|
||||
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"))
|
||||
}
|
||||
|
||||
|
|
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.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<String>) = 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<Game>(loadedGameJson)
|
||||
val loadedGame = Json.decodeFromString<Game>(gameDataJson)
|
||||
|
||||
MaterialTheme {
|
||||
val playerPointMap: MutableMap<Player, Long> =
|
||||
val playerPointMap: MutableMap<Player, Long> = remember {
|
||||
loadedGame.players.map { it to 0L }.toMutableStateMap()
|
||||
}
|
||||
|
||||
val questionsResolved: MutableMap<QuestionData, QuestionResolution> = remember {
|
||||
loadedGame.topics
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
@ -12,11 +17,17 @@ fun HintText(
|
|||
hint: String,
|
||||
deferredDouble: Boolean = false,
|
||||
doubleJeopardy: Boolean = false
|
||||
) {
|
||||
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!""",
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue