godot-wyvernbox-inventory icon indicating copy to clipboard operation
godot-wyvernbox-inventory copied to clipboard

Allow item-specific custom actions via scripts

Open don-tnowe opened this issue 1 year ago • 1 comments

Submitted by Discord user.

There's no custom actions on items! And there should be. Because so many games have logic tied to items. Some can even be possible to be activated from the inventory!

  • consume food/potion/other consumable
  • apply item to another item
  • turn item into other items
  • open item's own inventory

For that, ItemType should store a script that can override methods:

  • input_inside_inventory(item : ItemStack, event : InputEvent, inventory_view : InventoryView, item_stack_view : ItemStackView) -> bool, which is called when an input occurs on an ItemStackView holding an item of the type;
  • input_into_world(item : ItemStack, event : InputEvent, drop_at_node : Node) -> bool, which is called before an input that would drop the item into the world. drop_at_node is the node set in the Grabbed Stack node, normally the player character;
  • input_onto_inventory(item : ItemStack, event : InputEvent, inventory_view : InventoryView?, inventory_cell_under : Vector2) -> bool, which is called when an input occurs while an item of the type is grabbed. InventoryView can be null.

All must return true if the input has been handled - which can, for example, prevent item grabbing and dropping.

don-tnowe avatar Nov 04 '23 16:11 don-tnowe