feat(inventory): hotbar + inventory UI + 5 crafting recipes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
50
scripts/inventory/CraftingRecipes.gd
Normal file
50
scripts/inventory/CraftingRecipes.gd
Normal file
@@ -0,0 +1,50 @@
|
||||
class_name CraftingRecipes
|
||||
extends RefCounted
|
||||
|
||||
static var RECIPES: Array = [
|
||||
{
|
||||
"name": "Lampe bioluminescente",
|
||||
"inputs": [{"item_id": 5, "count": 2}, {"item_id": 6, "count": 1}],
|
||||
"output": {"item_id": 100, "count": 1}
|
||||
},
|
||||
{
|
||||
"name": "Harpon",
|
||||
"inputs": [{"item_id": 3, "count": 2}, {"item_id": 7, "count": 2}],
|
||||
"output": {"item_id": 101, "count": 1}
|
||||
},
|
||||
{
|
||||
"name": "Bulle d'air",
|
||||
"inputs": [{"item_id": 6, "count": 3}, {"item_id": 8, "count": 1}],
|
||||
"output": {"item_id": 102, "count": 1}
|
||||
},
|
||||
{
|
||||
"name": "Algue cuisinee",
|
||||
"inputs": [{"item_id": 6, "count": 2}],
|
||||
"output": {"item_id": 103, "count": 2}
|
||||
},
|
||||
{
|
||||
"name": "Armure ecailles",
|
||||
"inputs": [{"item_id": 4, "count": 4}, {"item_id": 7, "count": 2}],
|
||||
"output": {"item_id": 104, "count": 1}
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
static func find_available_recipes(inventory: Inventory) -> Array:
|
||||
var available: Array = []
|
||||
for i: int in range(RECIPES.size()):
|
||||
if inventory.has_items(RECIPES[i]["inputs"]):
|
||||
available.append(i)
|
||||
return available
|
||||
|
||||
|
||||
static func craft(inventory: Inventory, recipe_index: int) -> bool:
|
||||
if recipe_index < 0 or recipe_index >= RECIPES.size():
|
||||
return false
|
||||
var recipe: Dictionary = RECIPES[recipe_index]
|
||||
if not inventory.consume_items(recipe["inputs"]):
|
||||
return false
|
||||
var leftover: int = inventory.add_item(recipe["output"]["item_id"], recipe["output"]["count"])
|
||||
if leftover > 0:
|
||||
push_warning("CraftingRecipes: craft overflow — %d items lost" % leftover)
|
||||
return true
|
||||
Reference in New Issue
Block a user