peter-kish / gloot

A universal inventory system for the Godot game engine.
MIT License
658 stars 28 forks source link

add create_item(prototype_id) to inventory #229

Closed LeeWannacott closed 3 months ago

LeeWannacott commented 3 months ago

Adds a method to create_item(protoset_id) with protoset_id, but NOT add the item to inventory;

Use case: I want to create the item for a loot drop (which might have some unique properties set), but only add the item to inventory when the user presses a key/interacts with the loot drop.

Note: I also use loot drop for the player dropping their own inventory on the ground which sets inventory_item_drop; in which case I just add_item back if they interact with it...

Example:

@onready var inventory_item_drop:InventoryItem

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
    # utils.setup_node(self,"loot")
    if inventory_item_drop == null:
        inventory_item_drop= InventoryItem.new()
        inventory_item_drop = grid.create_item("bear_cape")
        # set unique item props

    pass # Replace with function body.

@onready var grid =  player.player_inventory.get_node("%character_inventory_grid") 
func _input(event: InputEvent) -> void:
    if Input.is_action_pressed("interact"):
        if item_loot_area.overlaps_body(player):
            if inventory_item_drop != null:
                if grid.can_add_item(inventory_item_drop):
                    grid.add_item(inventory_item_drop)
                    queue_free()
snipercup commented 3 months ago

Thank you for making this. I also support this function. My use case is that I have a custom equipment slot and I want to create a new item at the start of the game and put it in my custom slot instead of an inventory.

LeeWannacott commented 3 months ago

Can you please also update docs/inventory.md?

Done.

I don't know why its saying I added protoset_changed() to the last line of the docs though? Weird, I used the online editor.