more crafting ui wip

This commit is contained in:
minjaesong
2022-06-28 00:57:40 +09:00
parent d56fb81bcf
commit 8ee2a2f56d
3 changed files with 18 additions and 6 deletions

View File

@@ -11,5 +11,12 @@
"ingredients": [
[5, 1, "$ROCKWOOD"]
]
},
"basegame:161": {
"workbench": "",
"ingredients": [
[4, 1, "$WOOD"]
]
}
}

View File

@@ -10,7 +10,7 @@ import net.torvald.terrarum.utils.forEachSiblingsIndexed
*/
class CraftingCodex {
@Transient internal val props = HashMap<ItemID, ArrayList<CraftingRecipe>>()
@Transient internal val props = HashMap<ItemID, ArrayList<CraftingRecipe>>() // 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<CraftingRecipe>? = 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<ItemID>): List<Pair<ItemID, CraftingRecipe>> {
fun getRecipesUsingTheseItems(items: List<ItemID>): List<CraftingRecipe> {
TODO()
}
/**
* @return list of itemIDs and corresponding recipes
*/
fun getRecipesForIngredients(ingredients: List<Pair<ItemID, Long>>): List<Pair<ItemID, CraftingRecipe>> {
fun getRecipesForIngredients(ingredients: List<Pair<ItemID, Long>>): List<CraftingRecipe> {
TODO()
}
data class CraftingRecipe(val workbench: String, val ingredients: Array<CraftingIngredients>, val moq: Long, val addedBy: String)
data class CraftingRecipe(val workbench: String, val ingredients: Array<CraftingIngredients>, 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 }
}

View File

@@ -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,