-
-
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.
# Adds the "Key" item to the inventory and makes it the current selected item (this changes the cursor)
I.add_item_as_active('Key')
I.remove_item('Card')
# Call the "_say_something" method once an item is added to the inventory
I.connect('item_add_done', self, '_say_something')
⬇️ Since version 1.9.0 ⬇️
# Add the DeckOfCards item to the inventory. Out of an E.run([])
I.DeckOfCards.add_now(false)
# Add the Key item to the inventory and make it the selected item. Inside an E.run([])
I.Key.add_as_active()
# Remove the Card item from the inventory. Inside an E.run([])
I.Card.remove()
-
inventory_show_requested( float time ). 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( PopochiuInventoryItem
item
, boolanimate
). 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( PopochiuInventoryItem
item
). 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( PopochiuInventoryItem
item
). 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( PopochiuInventoryItem
item
). You can connect to this signal to know when a PopochiuInventoryItem was successfully removed from the inventory. This signal is emitted by Inventory.gd.
-
active PopochiuInventoryItem. Default
null
. The inventory item that is currently selected. -
items Array. Default
[]
. The instances of the PopochiuInventoryItem that are currently in the inventory. -
items_states Dictionary. Default
{}
. Stores thestate
of each PopochiuInventoryItem in memory. Used for saving/loading the game too.
-
_item_instances Array. Default
[]
. Stores the instances of the PopochiuInventoryItem that were once added to the inventory.
-
add_item( String
item_name = ''
, boolis_in_queue = true
, boolanimate = true
) voidAdds the PopochiuInventoryItem with
script_name
equals toitem_name
to the inventory. If you want to use it outside a run, sendis_in_queue
asfalse
. Passanimate
asfalse
if you do not want the inventory to animate when the item is added. 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( String
item_name = ''
, boolis_in_queue = true
, boolanimate = true
) voidAdds the PopochiuInventoryItem with
script_name
equals toitem_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
. Passanimate
asfalse
if you do not want the inventory to animate when the item is added. 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( String
item_name
) boolReturns
true
if the PopochiuInventoryItem withscript_name
equals toitem_name
is in the inventory. -
remove_item( String
item_name = ''
, boolis_in_queue = true
, boolanimate = true
) voidRemoves the PopochiuInventoryItem with
script_name
equals toitem_name
from the inventory (its instance will be kept in the_item_instances
array). Passanimate
asfalse
if you do not want the inventory to animate when the item is added. If you want to use it outside a run, sendis_in_queue
asfalse
. Can be yield. -
set_active_item( PopochiuInventoryItem
item = null
) voidMakes the cursor use the texture of
item
. Call this method without parameters to make the cursor takes its default appeareance. -
show_inventory( float
time = 1.0
, boolis_in_queue: = 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)