mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
more crafting ui wip
This commit is contained in:
@@ -11,5 +11,12 @@
|
||||
"ingredients": [
|
||||
[5, 1, "$ROCKWOOD"]
|
||||
]
|
||||
},
|
||||
|
||||
"basegame:161": {
|
||||
"workbench": "",
|
||||
"ingredients": [
|
||||
[4, 1, "$WOOD"]
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user