Skip to content

Commit

Permalink
Merge pull request #392 from fmasa/wom-careers-fix
Browse files Browse the repository at this point in the history
Fix Winds of Magic career imports
  • Loading branch information
fmasa authored Jan 1, 2025
2 parents 0eeccd4 + e050a2f commit e3badf9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ object ArchivesOfTheEmpire2 : Book, CareerSource, SpellSource, TrappingSource {
override val tableFootnotesAsNormalText: Boolean = true

override fun importCareers(document: Document): List<Career> {
return CareerParser(convertTablesToText = true)
return CareerParser(
tokenMapper = {
when (it) {
is Token.BodyCellPart -> Token.NormalPart(it.text)
is Token.TableHeadCell -> Token.BoldPart(it.text)
else -> it
}
},
)
.import(
document,
this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ object SeaOfClaws : Book, SpellSource, TalentSource, CareerSource, MiracleSource
}

override fun importCareers(document: Document): List<Career> {
return CareerParser(convertTablesToText = true).import(
val tokenMapper: (Token) -> Token = {
when (it) {
is Token.BodyCellPart -> Token.NormalPart(it.text)
is Token.TableHeadCell -> Token.BoldPart(it.text)
else -> it
}
}

return CareerParser(tokenMapper = tokenMapper).import(
document,
this,
sequenceOf(
SocialClass.SEAFARERS to listOf(64, 68, 70, 72, 74, 76, 78, 90),
),
) +
CareerParser(convertTablesToText = true, hasAttributesInRightColumn = true).import(
CareerParser(tokenMapper = tokenMapper, hasAttributesInRightColumn = true).import(
document,
this,
sequenceOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ object UpInArms : Book, CareerSource, TalentSource, TrappingSource, JournalEntry
override val tokensSorted: Boolean = false

override fun importCareers(document: Document): List<Career> {
return CareerParser(convertTablesToText = true).import(
return CareerParser(
tokenMapper = {
when (it) {
is Token.BodyCellPart -> Token.NormalPart(it.text)
is Token.TableHeadCell -> Token.BoldPart(it.text)
else -> it
}
},
).import(
document,
this,
sequenceOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ object WindsOfMagic : Book, CareerSource, SpellSource, TrappingSource {
override val name = "Winds of Magic"

override fun importCareers(document: Document): List<Career> {
return CareerParser().import(
return CareerParser(
tokenMapper = {
when (it) {
is Token.BodyCellPart -> Token.NormalPart(it.text)
else -> it
}
},
).import(
document,
this,
sequenceOf(
SocialClass.WARRIORS to listOf(36),
SocialClass.ACADEMICS to listOf(38),
SocialClass.PEASANTS to listOf(42),
SocialClass.ACADEMICS to listOf(56, 68, 80, 92, 104, 116, 128, 140),
SocialClass.ACADEMICS to listOf(40, 56, 68, 80, 92, 104, 116, 128, 140),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import cz.frantisekmasa.wfrp_master.common.core.domain.character.Race
import cz.frantisekmasa.wfrp_master.common.core.domain.character.SocialStatus

class CareerParser(
private val convertTablesToText: Boolean = false,
private val hasAttributesInRightColumn: Boolean = false,
private val tokenMapper: (Token) -> Token = { it },
) {
fun import(
document: Document,
Expand Down Expand Up @@ -56,21 +56,7 @@ class CareerParser(
secondColumn: Sequence<Token>,
): Career {
val blockWithAttributes = if (hasAttributesInRightColumn) firstColumn + secondColumn else firstColumn
val stream =
TokenStream(
if (convertTablesToText) {
blockWithAttributes
.map {
when (it) {
is Token.BodyCellPart -> Token.NormalPart(it.text)
is Token.TableHeadCell -> Token.BoldPart(it.text)
else -> it
}
}.toList()
} else {
(blockWithAttributes).toList()
},
)
val stream = TokenStream(blockWithAttributes.map(tokenMapper).toList())

val name =
stream.consumeOneOfType<Token.Heading>().text
Expand Down
2 changes: 1 addition & 1 deletion common/src/jvmTest/kotlin/ImporterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ImporterTest {
withBook(WindsOfMagic) { document ->
val careers = WindsOfMagic.importCareers(document)

assertEquals(11, careers.size)
assertEquals(12, careers.size)
careers.forEach {
assertEquals(3, it.levels[0].characteristics.size)
assertEquals(1, it.levels[1].characteristics.size)
Expand Down

0 comments on commit e3badf9

Please sign in to comment.