Fix the skill parsing method that made impossible to add blank lines
This commit is contained in:
parent
676cbf242c
commit
b443b57eec
5 changed files with 38 additions and 27 deletions
|
|
@ -136,6 +136,14 @@ class LauncherViewModel @Inject constructor(
|
|||
_error.emit(FetchErrorUio.Structure(type = Type.ACTION))
|
||||
}
|
||||
}
|
||||
val skill = async {
|
||||
try {
|
||||
skillRepository.fetchSkills(characters = characterSheetRepository.data.value)
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.SKILL))
|
||||
}
|
||||
}
|
||||
val objects = async {
|
||||
try {
|
||||
objectActionRepository.fetchObjectAction()
|
||||
|
|
@ -152,14 +160,6 @@ class LauncherViewModel @Inject constructor(
|
|||
_error.emit(FetchErrorUio.Structure(type = Type.SPELL))
|
||||
}
|
||||
}
|
||||
val skill = async {
|
||||
try {
|
||||
skillRepository.fetchSkills()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.SKILL))
|
||||
}
|
||||
}
|
||||
|
||||
awaitAll(order, lexicon, location, quest)
|
||||
awaitAll(description, inventory, equipment, alteration, action, objects, spell, skill)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ class AttackParser @Inject constructor(
|
|||
value.forEachRowIndexed { index, row ->
|
||||
when (index) {
|
||||
0 -> updateStructure(row = row, columns = COLUMNS)
|
||||
|
||||
else -> {
|
||||
// Assume that the name is the first column.
|
||||
val characterSheet = charactersSheets[row.parse(CHARACTER)]
|
||||
|
|
@ -47,7 +48,7 @@ class AttackParser @Inject constructor(
|
|||
}
|
||||
|
||||
private fun parseType(value: String?): Attack.Type = try {
|
||||
Attack.Type.values().firstOrNull { it.key == value }
|
||||
Attack.Type.entries.firstOrNull { it.key == value }
|
||||
} catch (exception: Exception) {
|
||||
Log.e("ActionParser", exception.message, exception)
|
||||
null
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.pixelized.rplexicon.data.parser
|
||||
|
||||
import com.google.api.services.sheets.v4.model.ValueRange
|
||||
import com.pixelized.rplexicon.data.model.CharacterSheet
|
||||
import com.pixelized.rplexicon.data.model.Skill
|
||||
import com.pixelized.rplexicon.data.parser.roll.ThrowParser
|
||||
import com.pixelized.rplexicon.utilitary.exceptions.IncompatibleSheetStructure
|
||||
|
|
@ -10,16 +11,20 @@ class SkillParser @Inject constructor(
|
|||
private val throwParser: ThrowParser,
|
||||
) {
|
||||
@Throws(IncompatibleSheetStructure::class)
|
||||
fun parse(sheet: ValueRange): Map<String, List<Skill>> = parserScope {
|
||||
fun parse(
|
||||
sheet: ValueRange,
|
||||
charactersSheets: Map<String, CharacterSheet>,
|
||||
): Map<String, List<Skill>> = parserScope {
|
||||
val skills = hashMapOf<String, MutableList<Skill>>()
|
||||
|
||||
sheet.forEachRowIndexed { index, row ->
|
||||
when (index) {
|
||||
0 -> updateStructure(row = row, columns = COLUMNS)
|
||||
|
||||
else -> {
|
||||
val character = row[0] as? String
|
||||
val characterSheet = charactersSheets[row.parse(CHARACTER)]
|
||||
val name = row.parse(column = NAME)
|
||||
if (character?.isNotBlank() == true && name != null) {
|
||||
if (characterSheet != null && name != null) {
|
||||
val skill = Skill(
|
||||
name = name,
|
||||
amount = row.parse(column = AMOUNT)?.toIntOrNull(),
|
||||
|
|
@ -27,7 +32,7 @@ class SkillParser @Inject constructor(
|
|||
cost = row.parse(column = COST),
|
||||
effect = throwParser.parse(row.parse(column = EFFECT)),
|
||||
)
|
||||
skills.getOrPut(character) { mutableListOf() }.add(skill)
|
||||
skills.getOrPut(characterSheet.name) { mutableListOf() }.add(skill)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -37,12 +42,13 @@ class SkillParser @Inject constructor(
|
|||
}
|
||||
|
||||
companion object {
|
||||
private val CHARACTER = column("")
|
||||
private val NAME = column("Nom")
|
||||
private val AMOUNT = column("Quantité")
|
||||
private val REST = column("Récupération")
|
||||
private val COST = column("Coût")
|
||||
private val EFFECT = column("Effect")
|
||||
|
||||
private val COLUMNS get() = listOf(NAME, AMOUNT, REST, COST, EFFECT)
|
||||
private val COLUMNS get() = listOf(CHARACTER, NAME, AMOUNT, REST, COST, EFFECT)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.pixelized.rplexicon.data.repository.character
|
||||
|
||||
import com.pixelized.rplexicon.data.model.CharacterSheet
|
||||
import com.pixelized.rplexicon.data.model.Skill
|
||||
import com.pixelized.rplexicon.data.parser.SkillParser
|
||||
import com.pixelized.rplexicon.data.repository.CharacterBinder
|
||||
|
|
@ -27,10 +28,13 @@ class SkillRepository @Inject constructor(
|
|||
}
|
||||
|
||||
@Throws(IncompatibleSheetStructure::class, Exception::class)
|
||||
suspend fun fetchSkills() {
|
||||
suspend fun fetchSkills(characters: Map<String, CharacterSheet>) {
|
||||
googleRepository.fetch { sheet ->
|
||||
val request = sheet.get(CharacterBinder.ID, CharacterBinder.SKILL)
|
||||
val skills = skillParser.parse(sheet = request.execute())
|
||||
val skills = skillParser.parse(
|
||||
sheet = request.execute(),
|
||||
charactersSheets = characters,
|
||||
)
|
||||
|
||||
_skills.emit(skills)
|
||||
lastSuccessFullUpdate = Update.currentTime()
|
||||
|
|
|
|||
|
|
@ -126,6 +126,16 @@ class CharacterSheetViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
val skills = async {
|
||||
if (force || skillRepository.lastSuccessFullUpdate.shouldUpdate()) {
|
||||
try {
|
||||
skillRepository.fetchSkills(characters = characterRepository.data.value)
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.SKILL))
|
||||
}
|
||||
}
|
||||
}
|
||||
val objects = async {
|
||||
if (force || objectRepository.lastSuccessFullUpdate.shouldUpdate()) {
|
||||
try {
|
||||
|
|
@ -146,17 +156,7 @@ class CharacterSheetViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
val skill = async {
|
||||
if (force || skillRepository.lastSuccessFullUpdate.shouldUpdate()) {
|
||||
try {
|
||||
skillRepository.fetchSkills()
|
||||
} catch (exception: Exception) {
|
||||
Log.e(TAG, exception.message, exception)
|
||||
_error.emit(FetchErrorUio.Structure(type = Type.SKILL))
|
||||
}
|
||||
}
|
||||
}
|
||||
awaitAll(description, alterations, inventory, equipment, actions, objects, spells, skill)
|
||||
awaitAll(description, alterations, inventory, equipment, actions, objects, spells, skills)
|
||||
_isLoading.value = false
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue