Skip to content

Commit 3c66452

Browse files
Fixed selection related errors regarding UnitsProperties
1 parent a0d3712 commit 3c66452

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

composeApp/src/jvmMain/kotlin/ua/valeriishymchuk/lobmapeditor/ui/component/project/unit/UnitsPropertiesConfig.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fun UnitsPropertiesConfig() {
7878
val currentText = when {
7979
selection.isEmpty() -> ""
8080
isXPositionMixed -> ""
81-
else -> selection.map { it.position.x }.distinct().first().toString()
81+
else -> selection.map { it.position.x }.distinct().firstOrNull()?.toString() ?: ""
8282
}
8383
TextFieldValue(
8484
text = currentText,
@@ -106,7 +106,7 @@ fun UnitsPropertiesConfig() {
106106
val currentText = when {
107107
selection.isEmpty() -> ""
108108
isYPositionMixed -> ""
109-
else -> selection.map { it.position.y }.distinct().first().toString()
109+
else -> selection.map { it.position.y }.distinct().firstOrNull()?.toString() ?: ""
110110
}
111111
TextFieldValue(
112112
text = currentText,
@@ -142,7 +142,7 @@ fun UnitsPropertiesConfig() {
142142
isRotationMixed -> ""
143143
else -> selection.map {
144144
org.joml.Math.toDegrees(it.rotationRadians)
145-
}.distinct().first().toString()
145+
}.distinct().firstOrNull()?.toString() ?: ""
146146
}
147147

148148
TextFieldValue(
@@ -182,7 +182,7 @@ fun UnitsPropertiesConfig() {
182182
val currentText = when {
183183
selection.isEmpty() -> ""
184184
selection.map { it.name }.distinct().size > 1 -> ""
185-
else -> selection.map { it.name }.distinct().first() ?: ""
185+
else -> selection.map { it.name }.distinct().firstOrNull() ?: ""
186186
}
187187
TextFieldValue(
188188
text = currentText,
@@ -220,7 +220,7 @@ fun UnitsPropertiesConfig() {
220220
Text("Owner:")
221221
ComboBox(
222222
labelText = if (isOwnerMixed) "Mixed" else let {
223-
val owner = selection.map { it.owner }.distinct().first()
223+
val owner = selection.map { it.owner }.distinct().firstOrNull() ?: return@let ""
224224
"${owner.key + 1} ${scenario!!.players[owner.key].team}"
225225
},
226226
popupManager = ownerPopupManager,
@@ -258,7 +258,7 @@ fun UnitsPropertiesConfig() {
258258
Text("Type:")
259259
ComboBox(
260260
labelText = if (isUnitTypeMixed) "Mixed" else let {
261-
val unityType = selection.map { it.type }.distinct().first()
261+
val unityType = selection.map { it.type }.distinct().firstOrNull() ?: return@let ""
262262
"$unityType"
263263
},
264264
popupManager = unityTypePopupManager,
@@ -459,4 +459,4 @@ fun UnitsPropertiesConfig() {
459459

460460
}
461461
}
462-
}
462+
}

0 commit comments

Comments
 (0)