Refactor the character sheet edit.
This commit is contained in:
parent
edf58fd215
commit
eb7b653bd7
71 changed files with 3155 additions and 489 deletions
|
|
@ -19,6 +19,7 @@ import com.pixelized.shared.lwa.usecase.CharacterSheetUseCase
|
|||
import com.pixelized.shared.lwa.usecase.ExpressionUseCase
|
||||
import com.pixelized.shared.lwa.usecase.RollUseCase
|
||||
import com.pixelized.shared.lwa.usecase.SkillStepUseCase
|
||||
import com.pixelized.shared.lwa.usecase.SkillUseCase
|
||||
import kotlinx.serialization.json.Json
|
||||
import org.koin.core.module.dsl.factoryOf
|
||||
import org.koin.dsl.module
|
||||
|
|
@ -68,6 +69,7 @@ val parserDependencies
|
|||
val useCaseDependencies
|
||||
get() = module {
|
||||
factoryOf(::CharacterSheetUseCase)
|
||||
factoryOf(::SkillUseCase)
|
||||
factoryOf(::SkillStepUseCase)
|
||||
factoryOf(::RollUseCase)
|
||||
factoryOf(::ExpressionUseCase)
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ package com.pixelized.shared.lwa.model.characterSheet
|
|||
data class CharacterSheet(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val job: String,
|
||||
val portrait: String?,
|
||||
val thumbnail: String?,
|
||||
val externalLink: String?,
|
||||
val level: Int,
|
||||
val shouldLevelUp: Boolean,
|
||||
// characteristics
|
||||
|
|
@ -26,6 +28,8 @@ data class CharacterSheet(
|
|||
val magicSkills: List<Skill>,
|
||||
// actions
|
||||
val actions: List<Roll>,
|
||||
// tags
|
||||
val tags: List<String>,
|
||||
) {
|
||||
fun skill(id: String?): Skill? = commonSkills.firstOrNull { it.id == id }
|
||||
?: specialSkills.firstOrNull { it.id == id }
|
||||
|
|
|
|||
|
|
@ -6,8 +6,10 @@ import kotlinx.serialization.Serializable
|
|||
data class CharacterSheetJsonV1(
|
||||
override val id: String,
|
||||
override val name: String,
|
||||
val job: String?,
|
||||
val portrait: String?,
|
||||
val thumbnail: String?,
|
||||
val externalLink: String?,
|
||||
val level: Int,
|
||||
val shouldLevelUp: Boolean?,
|
||||
// characteristics
|
||||
|
|
@ -29,6 +31,8 @@ data class CharacterSheetJsonV1(
|
|||
val magics: List<Skill>,
|
||||
// actions
|
||||
val rolls: List<Roll>,
|
||||
// tags
|
||||
val tag: List<String>?,
|
||||
) : CharacterSheetJson {
|
||||
|
||||
@Serializable
|
||||
|
|
|
|||
|
|
@ -3,5 +3,8 @@ package com.pixelized.shared.lwa.model.characterSheet
|
|||
data class CharacterSheetPreview(
|
||||
val characterSheetId: String,
|
||||
val name: String,
|
||||
val job: String,
|
||||
val level: Int,
|
||||
val externalLink: String?,
|
||||
val tags: List<String>,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@ class CharacterSheetJsonFactory(
|
|||
val json = CharacterSheetJsonV1(
|
||||
id = sheet.id,
|
||||
name = sheet.name,
|
||||
job = sheet.job,
|
||||
portrait = sheet.portrait?.takeIf { it.isNotBlank() },
|
||||
thumbnail = sheet.thumbnail?.takeIf { it.isNotBlank() },
|
||||
externalLink = sheet.externalLink,
|
||||
level = sheet.level,
|
||||
shouldLevelUp = sheet.shouldLevelUp,
|
||||
strength = sheet.strength,
|
||||
|
|
@ -88,17 +90,34 @@ class CharacterSheetJsonFactory(
|
|||
critical = it.critical
|
||||
)
|
||||
},
|
||||
tag = sheet.tags,
|
||||
)
|
||||
return json
|
||||
}
|
||||
|
||||
suspend fun convertFromJson(
|
||||
fun convertToPreview(
|
||||
sheet: CharacterSheet,
|
||||
): CharacterSheetPreview {
|
||||
return CharacterSheetPreview(
|
||||
characterSheetId = sheet.id,
|
||||
name = sheet.name,
|
||||
job = sheet.job,
|
||||
level = sheet.level,
|
||||
externalLink = sheet.externalLink,
|
||||
tags = sheet.tags,
|
||||
)
|
||||
}
|
||||
|
||||
fun convertFromJson(
|
||||
json: CharacterPreviewJson,
|
||||
): CharacterSheetPreview {
|
||||
return CharacterSheetPreview(
|
||||
characterSheetId = json.id,
|
||||
name = json.name,
|
||||
job = json.job ?: "",
|
||||
level = json.level,
|
||||
externalLink = json.externalLink,
|
||||
tags = json.tags,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +129,10 @@ class CharacterSheetJsonFactory(
|
|||
portrait = sheet.portrait,
|
||||
thumbnail = sheet.thumbnail,
|
||||
name = sheet.name,
|
||||
job = sheet.job,
|
||||
level = sheet.level,
|
||||
externalLink = sheet.externalLink,
|
||||
tags = sheet.tags,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -13,8 +13,10 @@ class CharacterSheetJsonV1Factory(
|
|||
CharacterSheet(
|
||||
id = json.id,
|
||||
name = json.name,
|
||||
job = json.job ?: "",
|
||||
portrait = json.portrait,
|
||||
thumbnail = json.thumbnail,
|
||||
externalLink = json.externalLink,
|
||||
level = json.level,
|
||||
shouldLevelUp = json.shouldLevelUp ?: false,
|
||||
strength = json.strength,
|
||||
|
|
@ -75,6 +77,7 @@ class CharacterSheetJsonV1Factory(
|
|||
critical = it.critical,
|
||||
)
|
||||
},
|
||||
tags = json.tag ?: emptyList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -8,5 +8,8 @@ class CharacterPreviewJson(
|
|||
val portrait: String?,
|
||||
val thumbnail: String?,
|
||||
val name: String,
|
||||
val job: String?,
|
||||
val level: Int,
|
||||
val externalLink: String?,
|
||||
val tags: List<String>,
|
||||
)
|
||||
|
|
@ -7,6 +7,7 @@ import com.pixelized.shared.lwa.model.characterSheet.CharacterSheet
|
|||
import com.pixelized.shared.lwa.parser.expression.Expression
|
||||
import com.pixelized.shared.lwa.parser.expression.ExpressionParser
|
||||
import com.pixelized.shared.lwa.parser.word.Word
|
||||
import com.pixelized.shared.lwa.utils.floor5
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
|
|
@ -108,7 +109,7 @@ class ExpressionUseCase(
|
|||
}
|
||||
|
||||
is Expression.Floor5 -> {
|
||||
evaluate(expression.expression).let { it - it % 5 }
|
||||
evaluate(expression.expression).floor5()
|
||||
}
|
||||
|
||||
is Expression.Flat -> {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,71 @@
|
|||
package com.pixelized.shared.lwa.usecase
|
||||
|
||||
import com.pixelized.shared.lwa.utils.floor5
|
||||
import kotlin.math.max
|
||||
|
||||
class SkillUseCase {
|
||||
|
||||
fun combat(dexterity: Int): Int {
|
||||
return (dexterity * 2).floor5()
|
||||
}
|
||||
|
||||
fun dodge(dexterity: Int): Int {
|
||||
return (dexterity * 2).floor5()
|
||||
}
|
||||
|
||||
fun grab(strength: Int, height: Int): Int {
|
||||
return (strength + height).floor5()
|
||||
}
|
||||
|
||||
fun shoot(strength: Int, dexterity: Int): Int {
|
||||
return (strength + dexterity).floor5()
|
||||
}
|
||||
|
||||
fun athletics(strength: Int, constitution: Int): Int {
|
||||
return (strength + constitution * 2).floor5()
|
||||
}
|
||||
|
||||
fun acrobatics(dexterity: Int, constitution: Int): Int {
|
||||
return (dexterity + constitution * 2).floor5()
|
||||
}
|
||||
|
||||
fun perception(intelligence: Int): Int {
|
||||
return (10 + intelligence * 2).floor5()
|
||||
}
|
||||
|
||||
fun search(intelligence: Int): Int {
|
||||
return (10 + intelligence * 2).floor5()
|
||||
}
|
||||
|
||||
fun empathy(charisma: Int, intelligence: Int): Int {
|
||||
return (charisma + intelligence).floor5()
|
||||
}
|
||||
|
||||
fun persuasion(charisma: Int): Int {
|
||||
return (charisma * 3).floor5()
|
||||
}
|
||||
|
||||
fun intimidation(charisma: Int, height: Int, power: Int): Int {
|
||||
return (charisma + max(height, power) * 2).floor5()
|
||||
}
|
||||
|
||||
fun spiel(charisma: Int, intelligence: Int): Int {
|
||||
return (charisma * 2 + intelligence).floor5()
|
||||
}
|
||||
|
||||
fun bargain(charisma: Int): Int {
|
||||
return (charisma * 2).floor5()
|
||||
}
|
||||
|
||||
fun discretion(charisma: Int, dexterity: Int, height: Int): Int {
|
||||
return (charisma + dexterity * 2 - height).floor5()
|
||||
}
|
||||
|
||||
fun sleightOfHand(dexterity: Int): Int {
|
||||
return (dexterity * 2).floor5()
|
||||
}
|
||||
|
||||
fun aid(intelligence: Int, dexterity: Int): Int {
|
||||
return (intelligence + dexterity).floor5()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
package com.pixelized.shared.lwa.utils
|
||||
|
||||
fun Int.floor5(): Int = this - this % 5
|
||||
Loading…
Add table
Add a link
Reference in a new issue