feat: add dark mode with toggle in top bar

- Created UnoTheme.kt with light/dark color schemes
- Added dark mode toggle (moon/sun icon) in GameInfoBar
- Wrapped all entry points (Desktop, Android, Web) with UnoTheme
- Fixed Web entry point to use CanvasBasedWindow
- Fixed Math.random() for WASM compatibility
This commit is contained in:
2026-08-02 18:52:25 +02:00
parent a7fb6ff94c
commit 8732c4142c
5 changed files with 140 additions and 68 deletions
@@ -4,26 +4,25 @@ import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.CanvasBasedWindow
import com.uno.game.GameEngine
import com.uno.game.model.*
import com.uno.shared.UnoGameScreen
import kotlinx.browser.document
import com.uno.shared.UnoTheme
import kotlinx.coroutines.delay
import org.w3c.dom.HTMLElement
@OptIn(ExperimentalComposeUiApi::class)
fun main() {
val root = document.getElementById("root") as HTMLElement
root.innerHTML = ""
val container = document.createElement("div")
container.id = "app"
root.appendChild(container)
composeWebRoot()
CanvasBasedWindow(canvasElementId = "ComposeTarget") {
UnoApp()
}
}
@Composable
fun composeWebRoot() {
fun UnoApp() {
val engine = remember { GameEngine() }
var gameState by remember { mutableStateOf(engine.startGame()) }
var gameStarted by remember { mutableStateOf(false) }
@@ -45,31 +44,33 @@ fun composeWebRoot() {
}
}
if (!gameStarted) {
WebStartScreen(onStartGame = { playerCount ->
gameState = engine.startGame(playerCount)
gameStarted = true
})
} else {
UnoGameScreen(
state = gameState,
onPlayCard = { card, color ->
gameState = engine.playCard(gameState, 0, card, color)
},
onDrawCard = {
gameState = engine.drawCard(gameState, 0)
},
onCallUno = { gameState = engine.callUno(gameState, 0) }
)
if (gameState.isFinished) {
WebGameOverScreen(
winner = gameState.winner,
onPlayAgain = {
gameState = engine.startGame()
gameStarted = false
}
UnoTheme {
if (!gameStarted) {
WebStartScreen(onStartGame = { playerCount ->
gameState = engine.startGame(playerCount)
gameStarted = true
})
} else {
UnoGameScreen(
state = gameState,
onPlayCard = { card, color ->
gameState = engine.playCard(gameState, 0, card, color)
},
onDrawCard = {
gameState = engine.drawCard(gameState, 0)
},
onCallUno = { gameState = engine.callUno(gameState, 0) }
)
if (gameState.isFinished) {
WebGameOverScreen(
winner = gameState.winner,
onPlayAgain = {
gameState = engine.startGame()
gameStarted = false
}
)
}
}
}
}