Skip to content

Commit

Permalink
Update 'card' command to correctly display singe attributes and multi…
Browse files Browse the repository at this point in the history
…ple weaknesses

Fixes #2 and Fixes #3
  • Loading branch information
Ed George committed May 29, 2018
1 parent fd0da97 commit 62b2bff
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/main/kotlin/uk/breedrapps/command/SearchCardCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,43 @@ class SearchCardCommand : BaseCommand() {

it.text?.let {
it.forEachIndexed { index, text ->
builder.addField("Text ${index+1}", text, false)
builder.addField(
"Text".appendIndexSuffix(index, it),
text,
false
)
}
}

it.attacks?.let {
it.forEachIndexed { index, attack ->
builder.addField("Attack ${index+1}", attack.formattedAttack, false)
builder.addField(
"Attack".appendIndexSuffix(index, it),
attack.formattedAttack,
false
)
}
}

it.weaknesses?.let {
val emote = it.map { it.type.emote }
it.forEachIndexed { index, effect ->
val emote = it.map { effect.type.emote }.joinToString(" ")
builder.addField("Weakness ${index+1}", "$emote ${effect.value}", true)
builder.addField(
"Weakness".appendIndexSuffix(index, it),
"${emote[index]} ${effect.value}",
true
)
}
}

it.resistances?.let {
val emote = it.map { it.type.emote }
it.forEachIndexed { index, effect ->
val emote = it.map { effect.type.emote }.joinToString(" ")
builder.addField("Resistance", "$emote ${effect.value}", true)
builder.addField(
"Resistance".appendIndexSuffix(index, it),
"${emote[index]} ${effect.value}",
true
)
}
}

Expand All @@ -140,4 +156,9 @@ class SearchCardCommand : BaseCommand() {
}
}

}

// Helper method for appending a given index to a string
fun String.appendIndexSuffix(index: Int, collection: Collection<*>): String {
return if (collection.size > 1) "$this ${index + 1}" else this
}

0 comments on commit 62b2bff

Please sign in to comment.