Skip to content

Commit 77c11bd

Browse files
authored
Merge pull request #261 from fmasa/max-times-taken
Add max times taken to Character talents
2 parents 92f7f4d + 9d2b75e commit 77c11bd

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

common/src/commonMain/kotlin/cz/frantisekmasa/wfrp_master/common/character/talents/dialog/NonCompendiumTalentForm.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ internal fun NonCompendiumTalentForm(
7474
maxLength = CompendiumTalent.TESTS_MAX_LENGTH,
7575
)
7676

77+
TextInput(
78+
label = stringResource(Str.talents_label_max_times_taken),
79+
value = formData.maxTimesTaken,
80+
validate = validate,
81+
maxLength = Talent.MAX_TIMES_TAKEN_MAX_LENGTH,
82+
)
83+
7784
TextInput(
7885
label = stringResource(Str.talents_label_description),
7986
value = formData.description,
@@ -89,6 +96,7 @@ private class NonCompendiumTalentFormData(
8996
val id: Uuid,
9097
val name: InputValue,
9198
val tests: InputValue,
99+
val maxTimesTaken: InputValue,
92100
val description: InputValue,
93101
val taken: MutableState<Int>,
94102
) : HydratedFormData<Talent> {
@@ -98,6 +106,7 @@ private class NonCompendiumTalentFormData(
98106
id = remember { talent?.id ?: uuid4() },
99107
name = inputValue(talent?.name ?: "", Rules.NotBlank()),
100108
tests = inputValue(talent?.tests ?: ""),
109+
maxTimesTaken = inputValue(talent?.maxTimesTaken ?: ""),
101110
description = inputValue(talent?.description ?: ""),
102111
taken = rememberSaveable { mutableStateOf(talent?.taken ?: 1) },
103112
)
@@ -108,6 +117,7 @@ private class NonCompendiumTalentFormData(
108117
compendiumId = null,
109118
name = name.value,
110119
tests = tests.value,
120+
maxTimesTaken = maxTimesTaken.value,
111121
description = description.value.trim(),
112122
taken = taken.value,
113123
)

common/src/commonMain/kotlin/cz/frantisekmasa/wfrp_master/common/character/talents/dialog/TalentDetail.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fun TalentDetail(
3737
subheadBar()
3838

3939
TalentDetailBody(
40-
maxTimesTaken = null,
40+
maxTimesTaken = talent.maxTimesTaken,
4141
tests = talent.tests,
4242
description = talent.description,
4343
)
@@ -47,14 +47,12 @@ fun TalentDetail(
4747

4848
@Composable
4949
fun TalentDetailBody(
50-
maxTimesTaken: String?,
50+
maxTimesTaken: String,
5151
tests: String,
5252
description: String,
5353
) {
5454
Column(Modifier.padding(Spacing.bodyPadding)) {
55-
if (maxTimesTaken != null) {
56-
SingleLineTextValue(stringResource(Str.talents_label_max_times_taken), maxTimesTaken)
57-
}
55+
SingleLineTextValue(stringResource(Str.talents_label_max_times_taken), maxTimesTaken)
5856

5957
if (tests.isNotBlank()) {
6058
SingleLineTextValue(stringResource(Str.talents_label_tests), tests)

common/src/commonMain/kotlin/cz/frantisekmasa/wfrp_master/common/core/domain/talents/Talent.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ data class Talent(
2525
@Contextual override val compendiumId: Uuid? = null,
2626
val name: String,
2727
val tests: String = "", // TODO: Remove default value in 3.0
28+
val maxTimesTaken: String = "", // TODO: Remove default value in 3.0
2829
val description: String,
2930
val taken: Int
3031
) : CharacterItem<Talent, CompendiumTalent>, EffectSource {
@@ -61,6 +62,7 @@ data class Talent(
6162
companion object {
6263
const val NAME_MAX_LENGTH = 50
6364
const val DESCRIPTION_MAX_LENGTH = 1500
65+
const val MAX_TIMES_TAKEN_MAX_LENGTH = CompendiumTalent.MAX_TIMES_TAKEN_MAX_LENGTH
6466

6567
fun fromCompendium(compendiumTalent: CompendiumTalent, timesTaken: Int): Talent {
6668
return Talent(
@@ -69,6 +71,7 @@ data class Talent(
6971
name = compendiumTalent.name,
7072
tests = compendiumTalent.tests,
7173
description = compendiumTalent.description,
74+
maxTimesTaken = compendiumTalent.maxTimesTaken,
7275
taken = timesTaken,
7376
)
7477
}

common/src/commonTest/kotlin/cz/frantisekmasa/wfrp_master/common/character/effects/EffectManagerTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class EffectManagerTest {
5151
id = uuid4(),
5252
compendiumId = null,
5353
name = "Hardy",
54+
maxTimesTaken = "",
5455
tests = "",
5556
description = "",
5657
taken = 2,
@@ -105,6 +106,7 @@ class EffectManagerTest {
105106
compendiumId = null,
106107
name = "Hardy",
107108
tests = "",
109+
maxTimesTaken = "",
108110
description = "",
109111
taken = 2,
110112
)
@@ -163,6 +165,7 @@ class EffectManagerTest {
163165
compendiumId = null,
164166
name = "Savvy",
165167
tests = "",
168+
maxTimesTaken = "",
166169
description = "",
167170
taken = 2,
168171
)
@@ -297,6 +300,7 @@ class EffectManagerTest {
297300
compendiumId = null,
298301
name = "Hardy",
299302
tests = "",
303+
maxTimesTaken = "",
300304
description = "",
301305
taken = 2,
302306
),
@@ -313,6 +317,7 @@ class EffectManagerTest {
313317
compendiumId = null,
314318
name = "Savvy (IT)",
315319
tests = "",
320+
maxTimesTaken = "",
316321
description = "",
317322
taken = 2,
318323
),

firebase/firestore.rules

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ service cloud.firestore {
368368
allow delete: if canEditCharacter();
369369

370370
function isValidTalent(talent) {
371-
return ["id", "name", "description", "taken", "compendiumId", "tests"].hasAll(talent.keys())
371+
return ["id", "name", "description", "taken", "compendiumId", "tests", "maxTimesTaken"].hasAll(talent.keys())
372372
&& talent.id is string && talent.id == talentId && isValidUuid(talent.id)
373373
&& talent.name is string && isNotBlank(talent.name) && talent.name.size() <= 50
374374
&& talent.description is string && talent.description.size() <= 1500
@@ -379,7 +379,8 @@ service cloud.firestore {
379379
|| (talent.compendiumId is string && exists(/databases/$(database)/documents/parties/$(partyId)/talents/$(talent.compendiumId)))
380380
)
381381
)
382-
&& (! ("tests" in talent) || (talent.tests is string && talent.tests.size() <= 200));
382+
&& (! ("tests" in talent) || (talent.tests is string && talent.tests.size() <= 200))
383+
&& (! ("maxTimesTaken" in talent) || (talent.maxTimesTaken is string && talent.maxTimesTaken.size() <= 100));
383384
}
384385
}
385386

0 commit comments

Comments
 (0)