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))
|
_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 {
|
val objects = async {
|
||||||
try {
|
try {
|
||||||
objectActionRepository.fetchObjectAction()
|
objectActionRepository.fetchObjectAction()
|
||||||
|
|
@ -152,14 +160,6 @@ class LauncherViewModel @Inject constructor(
|
||||||
_error.emit(FetchErrorUio.Structure(type = Type.SPELL))
|
_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(order, lexicon, location, quest)
|
||||||
awaitAll(description, inventory, equipment, alteration, action, objects, spell, skill)
|
awaitAll(description, inventory, equipment, alteration, action, objects, spell, skill)
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ class AttackParser @Inject constructor(
|
||||||
value.forEachRowIndexed { index, row ->
|
value.forEachRowIndexed { index, row ->
|
||||||
when (index) {
|
when (index) {
|
||||||
0 -> updateStructure(row = row, columns = COLUMNS)
|
0 -> updateStructure(row = row, columns = COLUMNS)
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
// Assume that the name is the first column.
|
// Assume that the name is the first column.
|
||||||
val characterSheet = charactersSheets[row.parse(CHARACTER)]
|
val characterSheet = charactersSheets[row.parse(CHARACTER)]
|
||||||
|
|
@ -47,7 +48,7 @@ class AttackParser @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseType(value: String?): Attack.Type = try {
|
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) {
|
} catch (exception: Exception) {
|
||||||
Log.e("ActionParser", exception.message, exception)
|
Log.e("ActionParser", exception.message, exception)
|
||||||
null
|
null
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.pixelized.rplexicon.data.parser
|
package com.pixelized.rplexicon.data.parser
|
||||||
|
|
||||||
import com.google.api.services.sheets.v4.model.ValueRange
|
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.model.Skill
|
||||||
import com.pixelized.rplexicon.data.parser.roll.ThrowParser
|
import com.pixelized.rplexicon.data.parser.roll.ThrowParser
|
||||||
import com.pixelized.rplexicon.utilitary.exceptions.IncompatibleSheetStructure
|
import com.pixelized.rplexicon.utilitary.exceptions.IncompatibleSheetStructure
|
||||||
|
|
@ -10,16 +11,20 @@ class SkillParser @Inject constructor(
|
||||||
private val throwParser: ThrowParser,
|
private val throwParser: ThrowParser,
|
||||||
) {
|
) {
|
||||||
@Throws(IncompatibleSheetStructure::class)
|
@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>>()
|
val skills = hashMapOf<String, MutableList<Skill>>()
|
||||||
|
|
||||||
sheet.forEachRowIndexed { index, row ->
|
sheet.forEachRowIndexed { index, row ->
|
||||||
when (index) {
|
when (index) {
|
||||||
0 -> updateStructure(row = row, columns = COLUMNS)
|
0 -> updateStructure(row = row, columns = COLUMNS)
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
val character = row[0] as? String
|
val characterSheet = charactersSheets[row.parse(CHARACTER)]
|
||||||
val name = row.parse(column = NAME)
|
val name = row.parse(column = NAME)
|
||||||
if (character?.isNotBlank() == true && name != null) {
|
if (characterSheet != null && name != null) {
|
||||||
val skill = Skill(
|
val skill = Skill(
|
||||||
name = name,
|
name = name,
|
||||||
amount = row.parse(column = AMOUNT)?.toIntOrNull(),
|
amount = row.parse(column = AMOUNT)?.toIntOrNull(),
|
||||||
|
|
@ -27,7 +32,7 @@ class SkillParser @Inject constructor(
|
||||||
cost = row.parse(column = COST),
|
cost = row.parse(column = COST),
|
||||||
effect = throwParser.parse(row.parse(column = EFFECT)),
|
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 {
|
companion object {
|
||||||
|
private val CHARACTER = column("")
|
||||||
private val NAME = column("Nom")
|
private val NAME = column("Nom")
|
||||||
private val AMOUNT = column("Quantité")
|
private val AMOUNT = column("Quantité")
|
||||||
private val REST = column("Récupération")
|
private val REST = column("Récupération")
|
||||||
private val COST = column("Coût")
|
private val COST = column("Coût")
|
||||||
private val EFFECT = column("Effect")
|
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
|
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.model.Skill
|
||||||
import com.pixelized.rplexicon.data.parser.SkillParser
|
import com.pixelized.rplexicon.data.parser.SkillParser
|
||||||
import com.pixelized.rplexicon.data.repository.CharacterBinder
|
import com.pixelized.rplexicon.data.repository.CharacterBinder
|
||||||
|
|
@ -27,10 +28,13 @@ class SkillRepository @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IncompatibleSheetStructure::class, Exception::class)
|
@Throws(IncompatibleSheetStructure::class, Exception::class)
|
||||||
suspend fun fetchSkills() {
|
suspend fun fetchSkills(characters: Map<String, CharacterSheet>) {
|
||||||
googleRepository.fetch { sheet ->
|
googleRepository.fetch { sheet ->
|
||||||
val request = sheet.get(CharacterBinder.ID, CharacterBinder.SKILL)
|
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)
|
_skills.emit(skills)
|
||||||
lastSuccessFullUpdate = Update.currentTime()
|
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 {
|
val objects = async {
|
||||||
if (force || objectRepository.lastSuccessFullUpdate.shouldUpdate()) {
|
if (force || objectRepository.lastSuccessFullUpdate.shouldUpdate()) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -146,17 +156,7 @@ class CharacterSheetViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val skill = async {
|
awaitAll(description, alterations, inventory, equipment, actions, objects, spells, skills)
|
||||||
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)
|
|
||||||
_isLoading.value = false
|
_isLoading.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue