Answers for "get_drag_data from Inventory in GDScript"

0

get_drag_data from Inventory in GDScript

func get_drag_data(_position):
    var itemIndex = get_index()
    var item = inventory.items[itemIndex]
    var dragPreview
    var data = {}
    if item != null:
        # Notify specific Objects that an Item has been picked up
        # so they stop working
        if Inventories.getFurnaceInventoryByID(inventory.id) != null:
            Inventories.notifyMoving(true)
        dragPreview = TextureRect.new()
        dragPreview.texture = item.texture
        dragPreview.set_scale(Vector2(5, 5))
        print(dragPreview)
        data.id = inventory.id
        data.name = item.name
        data.previousAmount = item.amount
        # Set unhandled data in case the Item doesn't get dropped anywhere
        Inventories.setUnhandledData(inventory, item, item.amount, itemIndex)
        # For half-splitting Item Stacks
        if Input.is_action_pressed("ctrl"):
            if item is Item:
                item.amount /= 2
                data.item = item.duplicate()
                inventory.emit_signal("items_changed", inventory.id, itemIndex)
                data.itemIndex = itemIndex
                data.split = true
                set_drag_preview(dragPreview)
                print(inventory)
                return data
        # For moving Items
        else:
            item = inventory.remove(itemIndex)
            if item is Item:
                data.item = item
                data.itemIndex = itemIndex
                set_drag_preview(dragPreview)
                return data
Posted by: Guest on June-17-2021

Browse Popular Code Answers by Language