Skip to content

Commit

Permalink
Winds of Magic: Fix import of skills, talents and trappigns for careers
Browse files Browse the repository at this point in the history
  • Loading branch information
fmasa committed Jan 1, 2025
1 parent 2c27b00 commit 84ae19d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 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,7 +23,14 @@ 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(
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

0 comments on commit 84ae19d

Please sign in to comment.