Skip to content

Commit 246ba8b

Browse files
- Strings added to resources.
- Fix for saved data on desktop. - Clicking on a selected word will reset words selection. - New isQ extension
1 parent 84162a2 commit 246ba8b

9 files changed

Lines changed: 51 additions & 18 deletions

File tree

composeApp/src/commonMain/composeResources/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@
1212
<string name="label_hint">Give me a hint</string>
1313
<string name="message_hint">Try with: %s</string>
1414
<string name="total_words">%1$d words</string>
15+
<string name="letter_q">Qu</string>
16+
<string name="word_counter_3">3</string>
17+
<string name="word_counter_4">4</string>
18+
<string name="word_counter_5">5</string>
19+
<string name="word_counter_6">6</string>
20+
<string name="word_counter_7">7</string>
21+
<string name="word_counter_more">8+</string>
1522
</resources>

composeApp/src/commonMain/kotlin/com/alejandrorios/bogglemultiplatform/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal fun App() {
4848
}
4949
}
5050

51-
var appStorage: String? = ""
51+
var appStorage: String = ""
5252

5353
enum class KotlinPlatform {
5454
ANDROID, IOS ,WASM, JS, DESKTOP;

composeApp/src/commonMain/kotlin/com/alejandrorios/bogglemultiplatform/ui/components/BoggleBoard.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.alejandrorios.bogglemultiplatform.ui.components
33
import androidx.compose.animation.core.FastOutLinearInEasing
44
import androidx.compose.animation.core.animateFloatAsState
55
import androidx.compose.animation.core.tween
6-
import androidx.compose.foundation.interaction.MutableInteractionSource
76
import androidx.compose.foundation.layout.Arrangement
87
import androidx.compose.foundation.layout.Box
98
import androidx.compose.foundation.layout.PaddingValues
@@ -36,8 +35,8 @@ import androidx.compose.ui.graphics.drawscope.scale
3635
import androidx.compose.ui.unit.dp
3736
import com.alejandrorios.bogglemultiplatform.currentPlatform
3837
import com.alejandrorios.bogglemultiplatform.ui.screen.BoggleUiState
39-
import com.alejandrorios.bogglemultiplatform.utils.boggleDieModifier
4038
import com.alejandrorios.bogglemultiplatform.utils.boggleBoardDragHandler
39+
import com.alejandrorios.bogglemultiplatform.utils.boggleDieModifier
4140

4241
@Composable
4342
fun BoggleBoard(
@@ -174,7 +173,6 @@ fun BoggleBoard(
174173
) {
175174
items(state.board.size, key = { it }) { index ->
176175
val selected = selectedIds.value.contains(index)
177-
val interactionSource = remember { MutableInteractionSource() }
178176

179177
BoggleDie(
180178
letter = state.board[index],
@@ -183,14 +181,14 @@ fun BoggleBoard(
183181
modifier = Modifier
184182
.rotate(dieRotationAngle)
185183
.boggleDieModifier(
186-
interactionSource = interactionSource,
187184
onClick = {
188-
selectedIds.value = if (selected) {
189-
selectedIds.value.minus(index)
185+
if (selected) {
186+
selectedIds.value = emptySet()
187+
updateKeys(emptyList(), true)
190188
} else {
191-
selectedIds.value.plus(index)
189+
selectedIds.value = selectedIds.value.plus(index)
190+
updateKeys(selectedIds.value.toList(), true)
192191
}
193-
updateKeys(selectedIds.value.toList(), true)
194192
},
195193
selectedKeys = selectedIds.value.toList(),
196194
index = index

composeApp/src/commonMain/kotlin/com/alejandrorios/bogglemultiplatform/ui/components/BoggleDie.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import androidx.compose.ui.text.font.FontWeight
1919
import androidx.compose.ui.text.style.TextAlign
2020
import androidx.compose.ui.unit.dp
2121
import androidx.compose.ui.unit.sp
22+
import com.alejandrorios.bogglemultiplatform.utils.isQ
2223

2324
@Composable
2425
fun BoggleDie(
@@ -65,7 +66,7 @@ fun BoggleDie(
6566
) {
6667
Text(
6768
text = letter,
68-
fontSize = if (letter == "Qu") 32.sp else 38.sp,
69+
fontSize = if (letter.isQ()) 32.sp else 38.sp,
6970
color = getLetterColor(selected),
7071
fontWeight = FontWeight.Bold,
7172
textAlign = TextAlign.Center,

composeApp/src/commonMain/kotlin/com/alejandrorios/bogglemultiplatform/ui/components/WordCounter.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.alejandrorios.bogglemultiplatform.ui.components
22

3+
import androidx.compose.animation.AnimatedVisibility
34
import androidx.compose.animation.core.animateFloatAsState
45
import androidx.compose.foundation.background
56
import androidx.compose.foundation.clickable
@@ -33,7 +34,9 @@ fun WordCounter(
3334
wordPair: WordPair,
3435
onWordClick: (String) -> Unit,
3536
) {
36-
if (wordPair.wordsTotal != 0) {
37+
AnimatedVisibility(
38+
visible = wordPair.wordsTotal != 0,
39+
) {
3740
val progress = wordPair.wordsFound.size / wordPair.wordsTotal.toFloat()
3841
val animatedProgress = animateFloatAsState(
3942
targetValue = progress,

composeApp/src/commonMain/kotlin/com/alejandrorios/bogglemultiplatform/ui/components/WordCounterRow.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ import androidx.compose.foundation.rememberScrollState
99
import androidx.compose.runtime.Composable
1010
import androidx.compose.ui.Modifier
1111
import androidx.compose.ui.unit.dp
12+
import boggle_multiplatform.composeapp.generated.resources.Res
13+
import boggle_multiplatform.composeapp.generated.resources.word_counter_3
14+
import boggle_multiplatform.composeapp.generated.resources.word_counter_4
15+
import boggle_multiplatform.composeapp.generated.resources.word_counter_5
16+
import boggle_multiplatform.composeapp.generated.resources.word_counter_6
17+
import boggle_multiplatform.composeapp.generated.resources.word_counter_7
18+
import boggle_multiplatform.composeapp.generated.resources.word_counter_more
1219
import com.alejandrorios.bogglemultiplatform.data.models.WordsCount
20+
import org.jetbrains.compose.resources.stringResource
1321

1422
@Composable
1523
fun WordCounterRow(
@@ -22,32 +30,32 @@ fun WordCounterRow(
2230
horizontalArrangement = Arrangement.Center
2331
) {
2432
WordCounter(
25-
numberOfLetters = "3",
33+
numberOfLetters = stringResource(Res.string.word_counter_3),
2634
wordPair = wordsCount.threeLetters,
2735
onWordClick = { onWordClick(it) },
2836
)
2937
WordCounter(
30-
numberOfLetters = "4",
38+
numberOfLetters = stringResource(Res.string.word_counter_4),
3139
wordPair = wordsCount.fourLetters,
3240
onWordClick = { onWordClick(it) },
3341
)
3442
WordCounter(
35-
numberOfLetters = "5",
43+
numberOfLetters = stringResource(Res.string.word_counter_5),
3644
wordPair = wordsCount.fiveLetters,
3745
onWordClick = { onWordClick(it) },
3846
)
3947
WordCounter(
40-
numberOfLetters = "6",
48+
numberOfLetters = stringResource(Res.string.word_counter_6),
4149
wordPair = wordsCount.sixLetters,
4250
onWordClick = { onWordClick(it) },
4351
)
4452
WordCounter(
45-
numberOfLetters = "7",
53+
numberOfLetters = stringResource(Res.string.word_counter_7),
4654
wordPair = wordsCount.sevenLetters,
4755
onWordClick = { onWordClick(it) },
4856
)
4957
WordCounter(
50-
numberOfLetters = "8+",
58+
numberOfLetters = stringResource(Res.string.word_counter_more),
5159
wordPair = wordsCount.moreThanSevenLetters,
5260
onWordClick = { onWordClick(it) },
5361
)

composeApp/src/commonMain/kotlin/com/alejandrorios/bogglemultiplatform/utils/Extensions.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ package com.alejandrorios.bogglemultiplatform.utils
22

33
import androidx.compose.foundation.lazy.grid.LazyGridItemInfo
44
import androidx.compose.foundation.lazy.grid.LazyGridState
5+
import androidx.compose.runtime.Composable
56
import androidx.compose.ui.geometry.Offset
67
import androidx.compose.ui.unit.round
78
import androidx.compose.ui.unit.toIntRect
89
import androidx.compose.ui.unit.toOffset
10+
import boggle_multiplatform.composeapp.generated.resources.Res
11+
import boggle_multiplatform.composeapp.generated.resources.letter_q
12+
import org.jetbrains.compose.resources.stringResource
913
import kotlin.math.abs
1014

1115
/**
@@ -47,3 +51,6 @@ fun LazyGridState.gridItemKeyAtPosition(hitPoint: Offset): LazyGridItemInfo? =
4751

4852
// Extension function to get the die key
4953
fun LazyGridItemInfo.dieKey(): Int = this.key as Int
54+
55+
@Composable
56+
fun String.isQ(): Boolean = this == stringResource(Res.string.letter_q)

composeApp/src/commonMain/kotlin/com/alejandrorios/bogglemultiplatform/utils/Modifiers.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import androidx.compose.foundation.clickable
44
import androidx.compose.foundation.gestures.detectDragGestures
55
import androidx.compose.foundation.interaction.MutableInteractionSource
66
import androidx.compose.foundation.lazy.grid.LazyGridState
7+
import androidx.compose.runtime.Composable
78
import androidx.compose.runtime.MutableState
9+
import androidx.compose.runtime.remember
810
import androidx.compose.ui.Modifier
911
import androidx.compose.ui.geometry.Offset
1012
import androidx.compose.ui.input.pointer.pointerInput
@@ -99,8 +101,9 @@ fun Modifier.boggleBoardDragHandler(
99101
* @param index The index of the die.
100102
* @return The modifier.
101103
*/
104+
@Composable
102105
fun Modifier.boggleDieModifier(
103-
interactionSource: MutableInteractionSource,
106+
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
104107
onClick: () -> Unit,
105108
selectedKeys: List<Int>,
106109
index: Int

composeApp/src/desktopMain/kotlin/main.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import androidx.compose.ui.window.application
55
import androidx.compose.ui.window.rememberWindowState
66
import com.alejandrorios.bogglemultiplatform.App
77
import com.alejandrorios.bogglemultiplatform.appStorage
8+
import kotlinx.io.files.Path
9+
import kotlinx.io.files.SystemFileSystem
810
import net.harawata.appdirs.AppDirsFactory
911

1012
fun main() {
@@ -13,6 +15,10 @@ fun main() {
1315
appStorage = AppDirsFactory.getInstance()
1416
.getUserDataDir("com.alejandrorios.bogglemultiplatform", "1.0.0", "alejandrorios")
1517

18+
with(SystemFileSystem) {
19+
if (!exists(Path(appStorage))) createDirectories(Path("${appStorage}/saved.json"))
20+
}
21+
1622
Window(
1723
title = "Boggle Multiplatform",
1824
state = windowState,

0 commit comments

Comments
 (0)