alchemist: restore silhouetted recipes for unfound items and remove recipe tracking #245
- Commit
d2eeba326d1d66a8630c2f6e28d2f79180f1d2f2- Author
- Vayun Mathur <[email protected]>
- When
- 2026-06-24 02:38 UTC (5 months ago)
- Parents
89db699
Diff
games/alchemist/src/main/java/com/vayunmathur/games/alchemist/ui/ItemDetails.kt
diff --git a/games/alchemist/src/main/java/com/vayunmathur/games/alchemist/ui/ItemDetails.kt b/games/alchemist/src/main/java/com/vayunmathur/games/alchemist/ui/ItemDetails.ktindex 9fd78aede9..fd5816fd32 100644--- a/games/alchemist/src/main/java/com/vayunmathur/games/alchemist/ui/ItemDetails.kt+++ b/games/alchemist/src/main/java/com/vayunmathur/games/alchemist/ui/ItemDetails.kt@@ -34,7 +34,6 @@ import com.vayunmathur.games.alchemist.R import com.vayunmathur.games.alchemist.Route import com.vayunmathur.games.alchemist.data.AlchemyRecipe import com.vayunmathur.games.alchemist.util.AlchemistViewModel-import com.vayunmathur.games.alchemist.util.recipeKey import com.vayunmathur.library.ui.IconNavigation import com.vayunmathur.library.util.NavBackStack @@ -48,7 +47,6 @@ fun ItemDetailsScreen( val allItems by viewModel.allItems.collectAsState() val recipes by viewModel.recipes.collectAsState() val itemsIds by viewModel.itemIds.collectAsState()- val usedRecipes by viewModel.usedRecipes.collectAsState() val item = remember(allItems, itemId) { allItems.firstOrNull { it.id == itemId.toLong() } } @@ -115,34 +113,23 @@ fun ItemDetailsScreen( modifier = Modifier.padding(8.dp, 0.dp), verticalArrangement = Arrangement.spacedBy(8.dp) ) {- // all recipes that have this item as an output — only show used ones+ // all recipes that have this item as an output val makeThis = recipes.filter { item.id in it.outputs }- val knownMakeThis = makeThis.filter { recipeKey(it) in usedRecipes }- val lockedMakeThis = makeThis.size - knownMakeThis.size stickyHeader {- SectionHeader(stringResource(R.string.recipes, knownMakeThis.size))+ SectionHeader(stringResource(R.string.recipes, makeThis.size)) }- items(knownMakeThis, key = { "make-${it.inputs.joinToString(",")}->${it.outputs.joinToString(",")}" }) { recipe ->+ items(makeThis, key = { "make-${it.inputs.joinToString(",")}->${it.outputs.joinToString(",")}" }) { recipe -> RecipeCard(recipe, isItemDiscovered = { id -> id in itemsIds }) }- if (lockedMakeThis > 0) {- item {- RecipeCard(- AlchemyRecipe(emptyList(), emptyList()),- { false },- lockedCount = lockedMakeThis- )- }- } - // all recipes that have this item as an input — only show used ones+ // all recipes that have this item as an input val whereIHaveInput = recipes.filter { item.id in it.inputs }- val discovered = whereIHaveInput.filter { recipeKey(it) in usedRecipes }- val locked = whereIHaveInput.size - discovered.size+ val showers = whereIHaveInput.filter { r -> r.outputs.all { it in itemsIds } }+ val locked = whereIHaveInput.count { r -> r.outputs.all { it !in itemsIds } } stickyHeader { SectionHeader(stringResource(R.string.used_in, whereIHaveInput.size)) }- items(discovered, key = { "used-${it.inputs.joinToString(",")}->${it.outputs.joinToString(",")}" }) { recipe ->+ items(showers, key = { "used-${it.inputs.joinToString(",")}->${it.outputs.joinToString(",")}" }) { recipe -> RecipeCard(recipe, isItemDiscovered = { id -> id in itemsIds }) } if (locked > 0) {@@ -212,11 +199,18 @@ fun RecipeCard( horizontalArrangement = Arrangement.spacedBy(8.dp) ) { if (lockedCount > 0) {- Text(- stringResource(R.string.locked, lockedCount),- style = MaterialTheme.typography.bodyMedium,- fontWeight = FontWeight.Bold- )+ Column {+ Text(+ stringResource(R.string.locked, lockedCount),+ style = MaterialTheme.typography.bodyMedium,+ fontWeight = FontWeight.Bold+ )+ Text(+ stringResource(R.string.locked_description),+ style = MaterialTheme.typography.labelMedium,+ color = MaterialTheme.colorScheme.onSecondaryContainer.copy(alpha = 0.7f)+ )+ } return@Card }
games/alchemist/src/main/java/com/vayunmathur/games/alchemist/util/AlchemistViewModel.kt
diff --git a/games/alchemist/src/main/java/com/vayunmathur/games/alchemist/util/AlchemistViewModel.kt b/games/alchemist/src/main/java/com/vayunmathur/games/alchemist/util/AlchemistViewModel.ktindex ee87c78207..7d4ba6335c 100644--- a/games/alchemist/src/main/java/com/vayunmathur/games/alchemist/util/AlchemistViewModel.kt+++ b/games/alchemist/src/main/java/com/vayunmathur/games/alchemist/util/AlchemistViewModel.kt@@ -40,9 +40,6 @@ class AlchemistViewModel(application: Application) : AndroidViewModel(applicatio .map { set -> set.map { it.toLong() }.toSet() } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptySet()) - val usedRecipes: StateFlow<Set<String>> = ds.stringSetFlow("used_recipes")- .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptySet())- val availableItems: StateFlow<List<AlchemyItem>> = combine(_allItems, itemIds) { items, ids -> items.filter { it.id in ids }.sortedBy { it.name }@@ -60,7 +57,6 @@ class AlchemistViewModel(application: Application) : AndroidViewModel(applicatio _allItems.value = Alchemist.items _recipes.value = Alchemist.recipes seedInitialItemsIfEmpty()- backfillLegacyRecipes() } } @@ -71,38 +67,6 @@ class AlchemistViewModel(application: Application) : AndroidViewModel(applicatio } } - /**- * One-time migration for users who unlocked items before recipe logging existed.- * For every unlocked element that has no logged recipe creating it, add every recipe- * that creates it whose inputs are themselves only such pre-existing elements- * (unlocked with no logged recipe creating them).- */- private suspend fun backfillLegacyRecipes() {- if (ds.getBoolean("recipes_backfilled", false)) return-- val unlocked = ds.stringSetFlow("available_items").first()- .mapNotNull { it.toLongOrNull() }.toSet()- val usedKeys = ds.stringSetFlow("used_recipes").first()- val allRecipes = _recipes.value-- // Elements that already have a logged recipe creating them.- val createdByLog = allRecipes- .filter { recipeKey(it) in usedKeys }- .flatMap { it.outputs }- .toSet()-- // "Pre-existing" elements: unlocked but not created by any logged recipe.- val legacy = unlocked - createdByLog-- allRecipes.forEach { recipe ->- if (recipe.outputs.any { it in legacy } && recipe.inputs.all { it in legacy }) {- ds.addStringToSet("used_recipes", recipeKey(recipe))- }- }-- ds.setBoolean("recipes_backfilled", true)- }- fun unlockItem(id: Long) { if (id !in itemIds.value) { ds.addStringToSet("available_items", id.toString())@@ -151,9 +115,6 @@ class AlchemistViewModel(application: Application) : AndroidViewModel(applicatio val combined = listOf(movedItem.id, target.id).sorted() val recipe = _recipes.value.find { it.inputs.sorted() == combined } ?: return - // Record this recipe as used- ds.addStringToSet("used_recipes", recipeKey(recipe))- val toRemoveKeys = setOf(movedItem.key, target.key) val toAdd = recipe.outputs.map { PlacedItem(it, target.offset) } _placedElements.update { list ->@@ -216,6 +177,3 @@ class AlchemistViewModel(application: Application) : AndroidViewModel(applicatio private const val TIME_UNLOCK_THRESHOLD = 100 } }--fun recipeKey(recipe: AlchemyRecipe): String =- "${recipe.inputs.sorted().joinToString(",")}->${recipe.outputs.sorted().joinToString(",")}"
games/alchemist/src/main/res/values/strings.xml
diff --git a/games/alchemist/src/main/res/values/strings.xml b/games/alchemist/src/main/res/values/strings.xmlindex 69fbb34d01..42a44c167d 100644--- a/games/alchemist/src/main/res/values/strings.xml+++ b/games/alchemist/src/main/res/values/strings.xml@@ -6,7 +6,7 @@ <string name="counter">%1$d / %2$d</string> <string name="recipes">Recipes (%1$d)</string> <string name="used_in">Used in (%1$d)</string>- <string name="locked">+ %1$d unseen recipes</string>+ <string name="locked">+ %1$d locked recipes.</string> <string name="locked_description">Unlock all outputs of these recipes to see them.</string> <string name="collection">Collection</string> <string name="discovered_counter">%1$d / %2$d discovered</string>