Skip to content

Commit 22d7905

Browse files
authored
Merge pull request #19 from joreilly/dependency_updates
dependency updates
2 parents 30a301c + f4e6876 commit 22d7905

File tree

13 files changed

+391
-78
lines changed

13 files changed

+391
-78
lines changed

.junie/guidelines.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Project Guidelines
2+
3+
## Project Structure
4+
This is a Kotlin Multiplatform project with Compose Multiplatform that includes:
5+
* `composeApp` - Shared Kotlin code with Compose UI
6+
* `iosApp` - iOS application
7+
8+
## Building the Project
9+
When building this project, Junie should use the following Gradle task:
10+
```
11+
:shared:compileDebugSources
12+
```

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@ Any updates to `boardStatus` or `boardGuesses` will trigger our SwiftUI UI to be
7777
* StarWars (https://github.com/joreilly/StarWars)
7878
* WordMasterKMP (https://github.com/joreilly/WordMasterKMP)
7979
* Chip-8 (https://github.com/joreilly/chip-8)
80+
* FirebaseAILogicKMPSample (https://github.com/joreilly/FirebaseAILogicKMPSample)

androidApp/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ android {
3131
sourceCompatibility = JavaVersion.VERSION_17
3232
targetCompatibility = JavaVersion.VERSION_17
3333
}
34-
35-
kotlinOptions {
36-
jvmTarget = "17"
37-
}
3834
}
3935

4036

androidApp/src/main/java/dev/johnoreilly/wordmaster/androidApp/MainActivity.kt

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.compose.material3.Scaffold
1717
import androidx.compose.material3.Text
1818
import androidx.compose.material3.TextField
1919
import androidx.compose.material3.TextFieldDefaults
20+
import androidx.compose.material3.MaterialTheme
2021
import androidx.compose.material3.TopAppBar
2122
import androidx.compose.runtime.*
2223
import androidx.compose.ui.Alignment
@@ -29,8 +30,17 @@ import androidx.compose.ui.platform.LocalContext
2930
import androidx.compose.ui.platform.LocalFocusManager
3031
import androidx.compose.ui.text.TextStyle
3132
import androidx.compose.ui.text.style.TextAlign
33+
import androidx.compose.ui.text.input.KeyboardCapitalization
34+
import androidx.compose.ui.text.input.ImeAction
35+
import androidx.compose.foundation.text.KeyboardOptions
36+
import androidx.compose.foundation.text.KeyboardActions
3237
import androidx.compose.ui.unit.dp
3338
import androidx.compose.ui.unit.sp
39+
import androidx.compose.ui.input.key.onKeyEvent
40+
import androidx.compose.ui.input.key.Key
41+
import androidx.compose.ui.input.key.KeyEventType
42+
import androidx.compose.ui.input.key.key
43+
import androidx.compose.ui.input.key.type
3444
import dev.johnoreilly.wordmaster.shared.LetterStatus
3545
import dev.johnoreilly.wordmaster.shared.WordMasterService
3646
import dev.johnoreilly.wordmaster.androidApp.theme.WordMasterTheme
@@ -55,7 +65,7 @@ fun MainLayout() {
5565
Scaffold(
5666
topBar = { WordMasterTopAppBar("WordMaster KMP") }
5767
) { innerPadding ->
58-
WordMasterView(Modifier.padding(innerPadding))
68+
WordMasterView(Modifier.padding(innerPadding).imePadding())
5969
}
6070
}
6171

@@ -71,18 +81,20 @@ fun WordMasterView(padding: Modifier) {
7181

7282
val boardGuesses by wordMasterService.boardGuesses.collectAsState()
7383
val boardStatus by wordMasterService.boardStatus.collectAsState()
84+
val revealedAnswer by wordMasterService.revealedAnswer.collectAsState()
85+
val lastGuessCorrect by wordMasterService.lastGuessCorrect.collectAsState()
7486

7587
val focusManager = LocalFocusManager.current
7688
val focusRequester = remember { FocusRequester() }
7789

78-
Row(padding.fillMaxSize().padding(16.dp), horizontalArrangement = Center) {
90+
Row(padding.fillMaxSize().padding(16.dp), horizontalArrangement = Center, verticalAlignment = Alignment.CenterVertically) {
7991

8092
Column(horizontalAlignment = Alignment.CenterHorizontally) {
8193
for (guessAttempt in 0 until WordMasterService.MAX_NUMBER_OF_GUESSES) {
82-
Row(horizontalArrangement = Arrangement.SpaceBetween) {
94+
Row(horizontalArrangement = Arrangement.Center) {
8395
for (character in 0 until WordMasterService.NUMBER_LETTERS) {
8496
Column(
85-
Modifier.padding(4.dp).background(Color.White).border(1.dp, Color.Black),
97+
Modifier.padding(4.dp),
8698
horizontalAlignment = Alignment.CenterHorizontally
8799
) {
88100

@@ -100,14 +112,64 @@ fun WordMasterView(padding: Modifier) {
100112
character,
101113
it.uppercase()
102114
)
103-
focusManager.moveFocus(FocusDirection.Next)
115+
if (it.isNotEmpty() && character < WordMasterService.NUMBER_LETTERS - 1) {
116+
// Only move within the same row; don't advance to the next row until the guess is submitted
117+
focusManager.moveFocus(FocusDirection.Next)
118+
}
104119
}
105120
},
106-
modifier = modifier,
121+
modifier = modifier.onKeyEvent {
122+
if (it.type == KeyEventType.KeyUp && (it.key == Key.Enter || it.key == Key.NumPadEnter)) {
123+
if (guessAttempt == wordMasterService.currentGuessAttempt) {
124+
var filled = true
125+
for (c in 0 until WordMasterService.NUMBER_LETTERS) {
126+
if (boardGuesses[guessAttempt][c].isEmpty()) { filled = false; break }
127+
}
128+
if (filled) {
129+
wordMasterService.checkGuess()
130+
// After submitting a guess, move focus to the next row's first cell
131+
focusManager.moveFocus(FocusDirection.Next)
132+
return@onKeyEvent true
133+
}
134+
}
135+
}
136+
false
137+
}
138+
.border(1.dp, Color.Black.copy(alpha = 0.6f), androidx.compose.foundation.shape.RoundedCornerShape(10.dp)),
139+
singleLine = true,
140+
keyboardOptions = KeyboardOptions(
141+
capitalization = KeyboardCapitalization.Characters,
142+
imeAction = ImeAction.Done
143+
),
144+
keyboardActions = KeyboardActions(
145+
onDone = {
146+
if (guessAttempt == wordMasterService.currentGuessAttempt) {
147+
var filled = true
148+
for (c in 0 until WordMasterService.NUMBER_LETTERS) {
149+
if (boardGuesses[guessAttempt][c].isEmpty()) { filled = false; break }
150+
}
151+
if (filled) {
152+
wordMasterService.checkGuess()
153+
// After submitting a guess, move focus to the next row's first cell
154+
focusManager.moveFocus(FocusDirection.Next)
155+
}
156+
}
157+
}
158+
),
107159
textStyle = TextStyle(fontSize = 14.sp, textAlign = TextAlign.Center),
160+
shape = androidx.compose.foundation.shape.RoundedCornerShape(10.dp),
108161
colors = TextFieldDefaults.colors(
162+
focusedTextColor = mapLetterStatusToTextColor(boardStatus[guessAttempt][character]),
109163
unfocusedTextColor = mapLetterStatusToTextColor(boardStatus[guessAttempt][character]),
164+
disabledTextColor = mapLetterStatusToTextColor(boardStatus[guessAttempt][character]),
165+
cursorColor = mapLetterStatusToTextColor(boardStatus[guessAttempt][character]),
166+
focusedContainerColor = mapLetterStatusToBackgroundColor(boardStatus[guessAttempt][character]),
110167
unfocusedContainerColor = mapLetterStatusToBackgroundColor(boardStatus[guessAttempt][character]),
168+
disabledContainerColor = mapLetterStatusToBackgroundColor(boardStatus[guessAttempt][character]),
169+
focusedIndicatorColor = Color.Transparent,
170+
unfocusedIndicatorColor = Color.Transparent,
171+
disabledIndicatorColor = Color.Transparent,
172+
errorIndicatorColor = Color.Transparent,
111173
),
112174
)
113175

@@ -121,9 +183,28 @@ fun WordMasterView(padding: Modifier) {
121183
}
122184

123185
Spacer(Modifier.height(16.dp))
186+
187+
if (revealedAnswer != null) {
188+
Text(
189+
text = "Answer: $revealedAnswer",
190+
style = TextStyle(fontSize = 18.sp, color = MaterialTheme.colorScheme.onSurface)
191+
)
192+
Spacer(Modifier.height(12.dp))
193+
}
194+
124195
Row(horizontalArrangement = Arrangement.Center) {
125196
Button(onClick = {
126-
wordMasterService.checkGuess()
197+
// Only submit and advance focus if the current row is filled
198+
val current = wordMasterService.currentGuessAttempt
199+
var filled = true
200+
for (c in 0 until WordMasterService.NUMBER_LETTERS) {
201+
if (boardGuesses[current][c].isEmpty()) { filled = false; break }
202+
}
203+
if (filled) {
204+
wordMasterService.checkGuess()
205+
// Move focus to next row's first cell
206+
focusManager.moveFocus(FocusDirection.Next)
207+
}
127208
}) {
128209
Text("Guess")
129210
}
@@ -135,6 +216,23 @@ fun WordMasterView(padding: Modifier) {
135216
Text("New Game")
136217
}
137218
}
219+
220+
if (lastGuessCorrect) {
221+
androidx.compose.material3.AlertDialog(
222+
onDismissRequest = { /* keep dialog until OK pressed */ },
223+
title = { Text("You win!") },
224+
text = { Text("Great job guessing the word.") },
225+
confirmButton = {
226+
Button(onClick = {
227+
wordMasterService.resetGame()
228+
// Re-focus first cell after reset
229+
focusRequester.requestFocus()
230+
}) {
231+
Text("OK")
232+
}
233+
}
234+
)
235+
}
138236
}
139237
}
140238

0 commit comments

Comments
 (0)