diff --git a/assets/mods/basegame/crafting/testrecipe.json b/assets/mods/basegame/crafting/testrecipe.json index 7ab898244..f5c6bd7c5 100644 --- a/assets/mods/basegame/crafting/testrecipe.json +++ b/assets/mods/basegame/crafting/testrecipe.json @@ -11,5 +11,12 @@ "ingredients": [ [5, 1, "$ROCKWOOD"] ] + }, + + "basegame:161": { + "workbench": "", + "ingredients": [ + [4, 1, "$WOOD"] + ] } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/itemproperties/CraftingCodex.kt b/src/net/torvald/terrarum/itemproperties/CraftingCodex.kt index bebb81a8e..834e25567 100644 --- a/src/net/torvald/terrarum/itemproperties/CraftingCodex.kt +++ b/src/net/torvald/terrarum/itemproperties/CraftingCodex.kt @@ -10,7 +10,7 @@ import net.torvald.terrarum.utils.forEachSiblingsIndexed */ class CraftingCodex { - @Transient internal val props = HashMap>() + @Transient internal val props = HashMap>() // the key ItemID and value.product must be equal fun addFromJson(json: JsonValue, moduleName: String, fileName:String) { @@ -59,7 +59,7 @@ class CraftingCodex { qtys[i] )) } - recipes.add(CraftingRecipe(workbenchStr, ingredients.toTypedArray(), moq, "$moduleName/$fileName")) + recipes.add(CraftingRecipe(workbenchStr, ingredients.toTypedArray(), moq, itemName, "$moduleName/$fileName")) } // register to the main props @@ -75,27 +75,27 @@ class CraftingCodex { * this function is guaranteed to return null. */ fun getRecipesFor(itemID: ItemID): List? = props[itemID]?.toList()?.let { - return if (it.isNotEmpty()) it else null + return it.ifEmpty { null } } /** * @return list of itemIDs and corresponding recipes */ - fun getRecipesUsingTheseItems(items: List): List> { + fun getRecipesUsingTheseItems(items: List): List { TODO() } /** * @return list of itemIDs and corresponding recipes */ - fun getRecipesForIngredients(ingredients: List>): List> { + fun getRecipesForIngredients(ingredients: List>): List { TODO() } - data class CraftingRecipe(val workbench: String, val ingredients: Array, val moq: Long, val addedBy: String) + data class CraftingRecipe(val workbench: String, val ingredients: Array, val moq: Long, val product: ItemID, val addedBy: String) data class CraftingIngredients(val key: String, val keyMode: CraftingItemKeyMode, val qty: Long) enum class CraftingItemKeyMode { VERBATIM, TAG } } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt index 2d2030441..9ce802125 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/UICrafting.kt @@ -70,6 +70,11 @@ class UICrafting(val full: UIInventoryFull) : UICanvas( val buttonWidth = (UIItemInventoryElemWide.height + listGap) * 3 - listGap - 2 // crafting list to the left + // TODO This UIItem need to be custom-built version of UIItemInventoryItemGrid, with requirements: + // - Takes list of [net.torvald.terrarum.itemproperties.CraftingRecipe] as an "inventory" + // - Displays `CraftingRecipe.product` as an "inventory cell" + // - When clicked, the cell is activated and displays its `ingredients` to the itemListIngredients + // - The clicked status must be recorded and be accessible to this very class itemListCraftable = UIItemInventoryItemGrid( this, catBar,