Call it inventory_slot.gd
Godot has built-in functions for dragging and dropping
Create the get drag data function
If the slot is empty exit the function
Setup a preview texture
Create a new Control node
Add a texture rect as child of this node
Move the texture to the centre of the mouse cursor
Pass the icon we made to the built-in set_drag_preview function
Return the data so that we can swap items later
Create a function to check
If data being dropped is valid
It has to be an origin node
Think of the drag-and-drop system as a conversation between two slots: the Source Slot (where you pick up the item) and the Target Slot (where you drop it).
We actually don't "move" the items. We swap them.
We look at the slot we came from.
We take whatever is in our hand and put it down.
We take whatever was on the table and throw it back to where we came from.
If the table was empty, we just threw "nothing" back to the origin, effectively clearing it.