// 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() )
7.1 Repository Skeleton @Singleton class SpellRepository @Inject constructor( private val spellDao: SpellDao, private val componentDao: ComponentDao, private val api: SpellApi, @ApplicationContext private val ctx: Context ) { // Local flow val allSpells: Flow<List<SpellEntity>> = spellDao.observeAll()
// 4️⃣ DAO -------------------------------------------------------------- @Dao interface ComponentDao @Query("SELECT * FROM components") suspend fun getAll(): List<ComponentEntity> -18 - dawnhold Dark Magic 0.16.0 sahrab Android
@Delete suspend fun delete(spell: SpellEntity)
Box( modifier = Modifier .size(96.dp) .clip(CircleShape) .background(background) .border(2.dp, Color.Magenta, CircleShape) .pointerInput(Unit) detectDragGestures( onDragStart = /* ignore */ , onDragEnd = /* ignore */ , onDragCancel = /* ignore */ , onDrag = change, _ -> // Accept only if dragged composable carries a ComponentEntity tag val comp = change.consumeAllChanges().metadata?.get<ComponentEntity>() comp?.let onDrop(it) ) ) if (filledComponent != null) Icon(painterResource(filledComponent.iconRes), contentDescription = filledComponent.name) IconButton(onClick = onClear, modifier = Modifier.align(Alignment.TopEnd)) Icon(Icons.Default.Close, tint = Color.White) else Icon(Icons.Default.Add, tint = Color.White.copy(alpha = 0.5f)) | | No duplicate component IDs | Each slot must be unique
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)
return SpellEntity( name = name, description = description, manaCost = mana, componentIds = comps.map it.id ) | | Description | Auto‑generated from component lore
| Rule | Explanation | |------|-------------| | Rarity Sum ≤ 10 | Prevent “over‑powered” spells. | | At least one RUNE | Guarantees a magical core. | | No duplicate component IDs | Each slot must be unique. | | Mana Cost = (Rarity × 10) + (type‑bonus) | Runes × 5, Reagents × 3, Gestures × 2. | | Name Generation | <Rune.name> + “ of ” + <Gesture.name> (fallback to generic). | | Description | Auto‑generated from component lore strings. |