-
-
Notifications
You must be signed in to change notification settings - Fork 19
IInventory
Use it to handle the inventory. Is the shortcut for IInventory.gd, and can be used (from any script) with I (E.g. I.add_item('Card')
).
Some things you can do with it:
- Add and remove items in the inventory.
- Make the cursor take the appeareance of an inventory item.
- Know when an item has been added or removed.
Examples
I.add_item_as_active('Key') # Adds the "Key" item to the inventory and makes it the current selected item (this changes the cursor)
I.remove_item('Card')
I.connect('item_add_done', self, '_say_something') # Call the "_say_something" method once an item is added to the inventory
- active PopochiuInventoryItem The inventory item that is currently selected.
-
add_item(
item_name: String, is_in_queue: bool = true, animate: bool = true
) voidAdds the PopochiuInventoryItem with script_name equals to
item_name
to the inventory. If you want to use it outside a run, sendis_in_queue
asfalse
. If you don't want the inventory to animate when the item is added, passanimate
asfalse
. If success, it will return the PopochiuInventoryItem of the item added, otherwise it will returnNull
(might be that the item was not found or that the inventory is already full). Can be yield.
var ii: PopochiuInventoryItem = yield(I.add_item('Key', false, false), 'completed')
if ii:
prints(ii.in_inventory) # Prints true
else:
prints('Something went wrong')
-
add_item_as_active(
item_name: String, is_in_queue: bool = true, animate: bool = true
) voidAdds the PopochiuInventoryItem with script_name equals to
item_name
to the inventory and makes it the current selected item (the cursor will look like the item's texture). If you want to use it outside a run, sendis_in_queue
asfalse
. If you don't want the inventory to animate when the item is added, passanimate
asfalse
. If success, it will return the PopochiuInventoryItem of the item added, otherwise it will returnNull
(might be that the item was not found or that the inventory is already full). Can be yield.
func on_interact() -> void:
# The Inventory will animate because the 3rd parameter is true by default
var ii: PopochiuInventoryItem = yield(I.add_item_as_active('Key', false), 'completed')
-
is_full() bool
Returns
true
if the inventory is full. This depends of the propertyE.inventory_limit
. -
is_item_in_inventory(
item_name: String
) boolReturns
true
if the PopochiuInventoryItem with script_name equals toitem_name
is in the inventory. -
remove_item(
item_name: String, is_in_queue: bool = true
) voidRemoves the PopochiuInventoryItem with script_name equals to
item_name
from the inventory (its instance will be kept in the _item_instances array). If you want to use it outside a run, sendis_in_queue
asfalse
. Can be yield. -
set_active_item(
item: PopochiuInventoryItem = null
)Makes the cursor use the texture of
item
. Call this method without parameters tomake the cursor takes its default appeareance. -
show_inventory(
time: float = 1.0, is_in_queue: bool = true
) voidMakes the inventory to show for
time
seconds and then hide. If you want to use it outside a E.run(), sendis_in_queue
asfalse
. Can be yield.Useful to show where the inventory is during a tutorial.
func on_interact() -> void:
# Make the inventory to show for 3 seconds
I.show_inventory(3.0, false)
-
inventory_show_requested( time: float )
Emitted when show_inventory() is called. Inventory.gd connects to this signal in order to show and hide itself.
-
inventory_shown
The signal that is emitted when the show and hide animation that shows the inventory has finished. Inventory.gd emitts this signal in its _show_and_hide() method.
-
item_added( item: PopochiuInventoryItem, animate: bool )
Emitted by this class in the add_item method to notify the Graphic Interface that an item was added to the inventory. This is what makes the item to appear in the inventory (Inventory.tscn).
-
item_add_done( item: PopochiuInventoryItem )
You can connect to this signal to know when a PopochiuInventoryItem was successfully added to the inventory. This signal is emitted by Inventory.gd.
-
item_removed( item: PopochiuInventoryItem )
Emitted by this class in the remove_item method to notify the Graphic Interface that an item was removed from the inventory. This is what makes the item to disappear in the inventory (Inventory.tscn).
-
item_remove_done( item: PopochiuInventoryItem )
You can connect to this signal to know when a PopochiuInventoryItem was successfully removed from the inventory. This signal is emitted by Inventory.gd.