val name = "$rune.name of $gesture.name" val mana = comps.sumOf it.rarity * when (it.type) ComponentType.RUNE -> 5 ComponentType.REAGENT -> 3 ComponentType.GESTURE -> 2
@Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insert(spell: SpellEntity)
// 2️⃣ Spell -------------------------------------------------------------- @Entity(tableName = "spells") data class SpellEntity( @PrimaryKey val spellId: String = UUID.randomUUID().toString(), val name: String, val description: String, val manaCost: Int, val componentIds: List<String>, // stored via TypeConverter val createdAt: Long = System.currentTimeMillis() )
The drag‑drop demo above is a minimal “metadata” trick; for a production‑ready solution use Accompanist‑drag‑drop or the new Compose Drag‑Drop API (Android 14+). 6.4 Spell Preview Card @Composable fun SpellPreviewCard(spell: SpellEntity?) Card( modifier = Modifier .fillMaxWidth() .padding(8.dp), colors = CardDefaults.cardColors(containerColor = Color(0xFF1B0B2D)) ) if (spell == null) Text( "Add components to craft a spell…", style = MaterialTheme.typography.bodyMedium, color = Color.LightGray, modifier = Modifier.padding(16.dp) ) else Column(modifier = Modifier.padding(16.dp)) Text(spell.name, style = MaterialTheme.typography.titleLarge, color = Color.Cyan) Spacer(Modifier.height(4.dp)) Text(spell.description, style = MaterialTheme.typography.bodyMedium, color = Color.White) Spacer(Modifier.height(8.dp)) Row(verticalAlignment = Alignment.CenterVertically) Icon(Icons.Default.Bolt, tint = Color.Yellow) Spacer(Modifier.width(4.dp)) Text("$spell.manaCost Mana", color = Color.Yellow) -18 - dawnhold Dark Magic 0.16.0 sahrab Android
@Composable fun AltarSlot( slotIndex: Int, filledComponent: ComponentEntity?, onDrop: (ComponentEntity) -> Unit, onClear: () -> Unit ) val background = if (filledComponent == null) Color.Black.copy(alpha = 0.2f) else Color.Transparent
// 3️⃣ Converters ------------------------------------------------------------ class Converters ") @TypeConverter fun toList(value: String) = if (value.isEmpty()) emptyList() else value.split("
val description = comps.joinToString("\n") "- $it.name: $itLore[it.id] ?: "…"" val name = "$rune
// 4️⃣ DAO -------------------------------------------------------------- @Dao interface ComponentDao @Query("SELECT * FROM components") suspend fun getAll(): List<ComponentEntity>
@Dao interface SpellDao @Query("SELECT * FROM spells ORDER BY createdAt DESC") fun observeAll(): Flow<List<SpellEntity>>
@Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertAll(components: List<ComponentEntity>) 5 ComponentType.REAGENT ->
// Insert locally + optional cloud suspend fun saveSpell(spell:
@Delete suspend fun delete(spell: SpellEntity)
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
Implementation (inside SpellCraftViewModel ):