-18 - Dawnhold Dark Magic - 0.16.0 Sahrab Android
// 3️⃣ Converters ------------------------------------------------------------ class Converters ") @TypeConverter fun toList(value: String) = if (value.isEmpty()) emptyList() else value.split("
Implementation (inside SpellCraftViewModel ): -18 - dawnhold Dark Magic 0.16.0 sahrab Android
private fun synthesizeSpell(): SpellEntity require(canSynthesize()) val rune = currentComponents.first it?.type == ComponentType.RUNE !! val gesture = currentComponents.first it?.type == ComponentType.GESTURE !! return SpellEntity( name = name
@Dao interface SpellDao @Query("SELECT * FROM spells ORDER BY createdAt DESC") fun observeAll(): Flow<List<SpellEntity>> description = description
return SpellEntity( name = name, description = description, manaCost = mana, componentIds = comps.map it.id )
@Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertAll(components: List<ComponentEntity>)
private fun canSynthesize(): Boolean val comps = currentComponents.filterNotNull() if (comps.size != 3) return false if (comps.distinctBy it.id .size != 3) return false if (comps.none it.type == ComponentType.RUNE ) return false if (comps.sumOf it.rarity > 10) return false return true
