not craftable items (due to lack of items) are filtered on crafting recipe list

This commit is contained in:
minjaesong
2023-09-10 23:44:11 +09:00
parent a40f044cb3
commit 20a9d32de0
3 changed files with 53 additions and 28 deletions

View File

@@ -7,6 +7,7 @@ import net.torvald.terrarum.UIItemInventoryCatBar
import net.torvald.terrarum.ceilToInt
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.itemproperties.CraftingCodex
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
/**
* Created by minjaesong on 2022-06-28.
@@ -44,12 +45,19 @@ class UIItemCraftingCandidateGrid(
}
}
private fun isCraftable(player: FixtureInventory, recipe: CraftingCodex.CraftingRecipe, nearbyCraftingStations: List<String>): Boolean {
return UICrafting.recipeToIngredientRecord(player, recipe, nearbyCraftingStations).none { it.howManyPlayerHas <= 0L || !it.craftingStationAvailable }
}
override fun rebuild(filter: Array<String>) {
// TODO test fill craftingRecipes with every possible recipes in the game
// filtering policy: if the player have all the ingredient item (regardless of the amount!), make the recipe visible
craftingRecipes.clear()
CraftingRecipeCodex.props.forEach { (_, recipes) -> craftingRecipes.addAll(recipes) }
// end of test fill
CraftingRecipeCodex.props.forEach { (_, recipes) ->
recipes.forEach {
// TODO check for nearby crafting stations
if (isCraftable((parentUI as UICrafting).getPlayerInventory(), it, listOf(/*todo: nearby crafting stations*/))) craftingRecipes.add(it)
}
}
recipesSortList.clear() // kinda like the output list