PopochiuIInventory

Inherits: Node

Description

Provides access to PopochiuInventoryItem instances through the singleton I (for example: I.Key.add()).

Use this interface to manage the game's inventory. Its script is i_inventory.gd.

Capabilities include:

  • Add or remove items from the inventory.

  • Change the cursor to an inventory item's texture.

  • Notify the GUI when items are added or removed.

Use examples:

# Add the DeckOfCards item to the inventory.
I.DeckOfCards.add()

# Add the Key item to the inventory and make it the selected one.
I.Key.add_as_active()

# Remove the Card item from the inventory.
I.Card.remove()

# Add the ToyCar item after some dialog lines.
E.queue([
    "Player: Oh, is the toy car I need",
    I.ToyCar.queue_add(),
    "Player: Now I will be able to enter the private club",
])

Properties

Type Name Default
PopochiuInventoryItem active set_active
PopochiuInventoryItem clicked
Variant items []
Variant items_states {}

Methods

Return Type Method
void clean_inventory(in_bg = false)
void deselect_active()
PopochiuInventoryItem get_instance(script_name: String)
PopochiuInventoryItem get_item_instance(item_name: String)
bool has_item_been_collected(item_name: String)
void hide_inventory(use_anim = true)
bool is_full()
bool is_item_in_inventory(item_name: String)
Callable queue_hide_inventory(use_anim = true)
Callable queue_show_inventory(time = 1.0)
void set_active(value: PopochiuInventoryItem)
void set_active_item(item: PopochiuInventoryItem = null)
void show_inventory(time = 1.0)

Signals


Signal Descriptions

inventory_hide_requested

signal inventory_hide_requested(use_anim: bool)

Emitted when the inventory is requested to hide. use_anim indicates whether the GUI should use an animation.


inventory_show_requested

signal inventory_show_requested(time: float)

Emitted when the inventory is requested to be shown. time sets how long it should remain visible (in seconds).


inventory_shown

signal inventory_shown()

Emitted when the inventory-show animation has finished.


item_add_done

signal item_add_done(item: PopochiuInventoryItem)

Emitted when the item has finished entering the inventory (GUI animation completed).


item_added

signal item_added(item: PopochiuInventoryItem, animate: bool)

Emitted when item is added to the inventory. animate may be used by the GUI to animate the item entering the inventory.


item_discarded

signal item_discarded(item: PopochiuInventoryItem)

Emitted when the item has been discarded (GUI animation finished).


item_remove_done

signal item_remove_done(item: PopochiuInventoryItem)

Emitted when the item has finished leaving the inventory (GUI animation completed).


item_removed

signal item_removed(item: PopochiuInventoryItem, animate: bool)

Emitted when item is removed from the inventory. animate may be used by the GUI to animate the item leaving the inventory.


item_replace_done

signal item_replace_done()

Emitted when an item replacement has finished.


item_replaced

signal item_replaced(item: PopochiuInventoryItem, new_item: PopochiuInventoryItem)

Emitted when item is replaced in the inventory by new_item. Useful for implementing item combinations.


item_selected

signal item_selected(item: PopochiuInventoryItem)

Emitted when item is selected in the inventory.


Property Descriptions

active

var active : PopochiuInventoryItem = set_active
  • Setter: set_active

Provides access to the inventory item that is currently selected.


clicked

var clicked : PopochiuInventoryItem

Provides access to the inventory item that was clicked.


items

var items = []

Array containing instances of the currently held PopochiuInventoryItems.


items_states

var items_states = {}

Stores per-item state data for each PopochiuInventoryItem in the project. The key for each entry is the item's script_name.


Method Descriptions

clean_inventory

func clean_inventory(in_bg = false) -> void

Removes all items currently in the inventory. If in_bg is true, items are removed in background without calling discard().


deselect_active

func deselect_active() -> void

Deselects the active item.


get_instance

func get_instance(script_name: String) -> PopochiuInventoryItem

Instantiates and returns the PopochiuInventoryItem resource referenced by script_name from project data. Logs an error and returns null if not found.


get_item_instance

func get_item_instance(item_name: String) -> PopochiuInventoryItem

Returns the instance of the PopochiuInventoryItem identified by item_name, or null if it does not exist.

Used by res://game/autoloads/i.gd to instantiate item variables at runtime for autocompletion.


has_item_been_collected

func has_item_been_collected(item_name: String) -> bool

Returns true if the item identified by item_name has ever been collected.


hide_inventory

func hide_inventory(use_anim = true) -> void

Hides the inventory. If use_anim is true, the GUI may play an animation.


is_full

func is_full() -> bool

Returns true if the inventory has reached the inventory limit configured in the project settings.


is_item_in_inventory

func is_item_in_inventory(item_name: String) -> bool

Returns true if the item identified by item_name is currently in the inventory.


queue_hide_inventory

func queue_hide_inventory(use_anim = true) -> Callable

Hides the inventory. If use_anim is true, the GUI may play an animation.

This method is intended to be used inside a queue() of instructions.


queue_show_inventory

func queue_show_inventory(time = 1.0) -> Callable

Shows the inventory for time seconds.

This method is intended to be used inside a queue() of instructions.


set_active

func set_active(value: PopochiuInventoryItem) -> void

set_active_item

func set_active_item(item: PopochiuInventoryItem = null) -> void

Sets the cursor to use the texture of item.


show_inventory

func show_inventory(time = 1.0) -> void

Shows the inventory for time seconds.