Skip to content

Commit

Permalink
Merge pull request #282 from fmasa/hardy-flag-removal
Browse files Browse the repository at this point in the history
Remove deprecated Hardy flag
  • Loading branch information
fmasa authored May 25, 2024
2 parents d488013 + d28eee8 commit bb8cf07
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import cz.frantisekmasa.wfrp_master.common.Str
import cz.frantisekmasa.wfrp_master.common.character.CharacterScreenModel
import cz.frantisekmasa.wfrp_master.common.core.domain.character.Character
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.CheckboxWithText
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.FormScreen
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.HydratedFormData
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.InputValue
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.Rules
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.TextInput
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.inputValue
import cz.frantisekmasa.wfrp_master.common.core.ui.primitives.UserTip
import cz.frantisekmasa.wfrp_master.common.core.ui.primitives.UserTipCard
import dev.icerock.moko.resources.compose.stringResource

@Composable
Expand All @@ -35,7 +29,7 @@ fun MaxWoundsSection(
title = stringResource(Str.points_wounds),
formData = formData,
onSave = { data ->
screenModel.update { it.updateMaxWounds(data.maxWounds, data.hardyTalent) }
screenModel.update { it.updateMaxWounds(data.maxWounds) }
},
) { validate ->
Column(Modifier.padding(top = 20.dp)) {
Expand All @@ -51,37 +45,22 @@ fun MaxWoundsSection(
validate = validate,
placeholder = stringResource(Str.points_auto_max_wounds_placeholder),
)

if (character.hasHardyTalent) {
if (formData.hardyTalent.value) {
UserTipCard(UserTip.HARDY_TALENTS)
}

CheckboxWithText(
text = stringResource(Str.points_label_hardy),
checked = formData.hardyTalent.value,
onCheckedChange = { formData.hardyTalent.value = it },
)
}
}
}
}

private data class WoundsData(
val maxWounds: Int?,
val hardyTalent: Boolean,
)

private data class WoundsFormData(
val maxWounds: InputValue,
val hardyTalent: MutableState<Boolean>,
) : HydratedFormData<WoundsData> {
override fun isValid(): Boolean = maxWounds.isValid()

override fun toValue(): WoundsData =
WoundsData(
maxWounds.value.toIntOrNull(),
hardyTalent.value,
)

companion object {
Expand All @@ -93,7 +72,6 @@ private data class WoundsFormData(
character.points.maxWounds?.toString() ?: "",
Rules.ifNotBlank(Rules.PositiveInteger()),
),
hardyTalent = rememberSaveable { mutableStateOf(character.hasHardyTalent) },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ object CoreRulebook :
specialLores =
mapOf(
"Petty Spells" to setOf(SpellLore.PETTY),
"Arcane Spells" to SpellLore.values().toSet() - SpellLore.PETTY,
"Arcane Spells" to SpellLore.entries.toSet() - SpellLore.PETTY,
),
).import(document, this, sequenceOf(240..257))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ data class Character(
val conditions: CurrentConditions = CurrentConditions.none(),
val mutation: String = "",
val note: String = "",
@SerialName("hardyTalent") val hasHardyTalent: Boolean = false,
val woundsModifiers: WoundsModifiers = WoundsModifiers(),
val encumbranceBonus: Encumbrance = Encumbrance.Zero,
@SerialName("archived") val isArchived: Boolean = false,
Expand All @@ -53,7 +52,7 @@ data class Character(
val wounds: Wounds get() =
Wounds(
points.wounds,
calculateMaxWounds(size ?: race?.size, points, hasHardyTalent, woundsModifiers, characteristics),
calculateMaxWounds(size ?: race?.size, points, woundsModifiers, characteristics),
)

val maxEncumbrance: Encumbrance
Expand Down Expand Up @@ -82,7 +81,6 @@ data class Character(
calculateMaxWounds(
size ?: race?.size,
points,
hasHardyTalent,
woundsModifiers,
characteristics,
)
Expand Down Expand Up @@ -110,7 +108,6 @@ data class Character(
calculateMaxWounds(
size ?: race?.size,
points,
hasHardyTalent,
woundsModifiers,
base + advances,
),
Expand All @@ -129,7 +126,6 @@ data class Character(
calculateMaxWounds(
size ?: race?.size,
points,
hasHardyTalent,
woundsModifiers,
characteristics,
),
Expand All @@ -148,7 +144,6 @@ data class Character(
calculateMaxWounds(
size ?: race?.size,
points,
hasHardyTalent,
woundsModifiers,
characteristics,
),
Expand Down Expand Up @@ -190,26 +185,20 @@ data class Character(
calculateMaxWounds(
size ?: race?.size,
points,
hasHardyTalent,
woundsModifiers,
characteristics,
),
),
)

fun updateMaxWounds(
maxWounds: Int?,
hasHardyTalent: Boolean,
): Character {
fun updateMaxWounds(maxWounds: Int?): Character {
val newPoints = points.copy(maxWounds = maxWounds)
return copy(
hasHardyTalent = hasHardyTalent,
points =
newPoints.coerceWoundsAtMost(
calculateMaxWounds(
size ?: race?.size,
newPoints,
hasHardyTalent,
woundsModifiers,
characteristics,
),
Expand Down Expand Up @@ -298,19 +287,13 @@ data class Character(
private fun calculateMaxWounds(
size: Size?,
points: Points,
hasHardyTalent: Boolean,
modifiers: WoundsModifiers,
characteristics: Stats,
): Int {
val manualMaxWounds = points.maxWounds
val toughnessBonus = characteristics.toughnessBonus

if (manualMaxWounds != null) {
// TODO: Remove support for hasHardyTalent flag
if (hasHardyTalent) {
return manualMaxWounds + toughnessBonus
}

return manualMaxWounds
}

Expand All @@ -326,11 +309,7 @@ data class Character(
characteristics.willPowerBonus
},
)
return (
baseWounds +
modifiers.extraToughnessBonusMultiplier * toughnessBonus +
(if (hasHardyTalent) toughnessBonus else 0)
) *
return (baseWounds + modifiers.extraToughnessBonusMultiplier * toughnessBonus) *
modifiers.afterMultiplier
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,5 @@ fun UserTipCard(

enum class UserTip(override val translatableName: StringResource) : NamedEnum {
ARMOUR_TRAPPINGS(Str.armour_tip_trappings),
HARDY_TALENTS(Str.talents_tip_hardy_talent_checkbox),
COMPENDIUM_LINK_MOVED(Str.parties_messages_compendium_card_moved),
}
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ class EffectManagerTest {
sin = 0,
experience = 0,
spentExperience = 0,
hardyWoundsBonus = 0,
),
motivation = "",
psychology = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CharacterTest {
race = Race.HALFLING,
characteristicsBase = Stats(20, 40, 2, 4, 80, 5, 5, 4, 0, 10),
characteristicsAdvances = Stats(20, 40, 2, 4, 80, 5, 5, 4, 0, 10),
points = Points(0, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0),
points = Points(0, 4, 4, 5, 5, 0, 0, 0, 0, 0),
)

@Test
Expand Down Expand Up @@ -67,7 +67,7 @@ class CharacterTest {
race = Race.HALFLING,
characteristicsBase = Stats(20, 40, 2, 4, 80, 5, 5, 4, 0, 10),
characteristicsAdvances = Stats(20, 40, 2, 4, 80, 5, 5, 4, 0, 10),
points = Points(0, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0),
points = Points(0, 4, 4, 5, 5, 0, 0, 0, 0, 0),
)

val playerCharacter = character.turnIntoPlayerCharacter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class HardyWoundsModificationTest {
sin = 0,
experience = 0,
spentExperience = 0,
hardyWoundsBonus = 0,
),
socialClass = "Warriors",
race = Race.HUMAN,
Expand Down
2 changes: 0 additions & 2 deletions firebase/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export interface Character {
resilience: number,
resolve: number,
sin: number,
hardyWoundsBonus: number
},
woundsModifiers: {
afterMultiplier: number,
Expand All @@ -105,7 +104,6 @@ export interface Character {
money: {
pennies: number,
},
hardyTalent: boolean,
note: string,
conditions: Conditions,
archived: boolean,
Expand Down
4 changes: 2 additions & 2 deletions firebase/firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ service cloud.firestore {
&& areMoneyValid(character.money)
&& areAmbitionsValid(character.ambitions)
&& character.note is string && character.note.size() <= 2000
&& character.hardyTalent is bool
&& (! ("hardyTalent" in character) || character.hardyTalent is bool)
&& (
character.hiddenTabs is list &&
character.hiddenTabs.toSet().size() == character.hiddenTabs.size() &&
Expand Down Expand Up @@ -642,7 +642,7 @@ service cloud.firestore {
&& points.wounds is int
&& points.experience is int
&& (! ("spentExperience" in points) || points.experience is int)
&& points.hardyWoundsBonus is int;
&& (! ("hardyWoundsBonus " in points) || points.hardyWoundsBonus is int);
}

function areStatsValid(stats) {
Expand Down
3 changes: 1 addition & 2 deletions firebase/tests/Parties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,8 @@ class Parties extends Suite {

await firebase.assertSucceeds(document.set({points: {resilience: 10}}, {merge: true}));
await firebase.assertSucceeds(document.update("note", "a".repeat(400)));
await firebase.assertSucceeds(document.update("hardyTalent", true));
await firebase.assertSucceeds(
document.update("points", {...this.validCharacter(userId).points, hardyWoundsBonus: 3})
document.update("points", {...this.validCharacter(userId).points, corruption: 3})
);
await firebase.assertSucceeds(document.update("hiddenTabs", ["ATTRIBUTES"]))
}
Expand Down
2 changes: 0 additions & 2 deletions firebase/tests/Suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export abstract class Suite {
resilience: 10,
resolve: 5,
sin: 4,
hardyWoundsBonus: 0,
},
ambitions: {
shortTerm: 'Kill monsters!',
Expand All @@ -123,7 +122,6 @@ export abstract class Suite {
pennies: 1000,
},
note: "",
hardyTalent: false,
conditions: {
conditions: {}
},
Expand Down

0 comments on commit bb8cf07

Please sign in to comment.