PopochiuIInventory
Inherits: Node
Description
Provides access to PopochiuInventoryItem instances through the singleton I
(for example: I.Key.add()).
Use this interface to manage each character's inventory. Its script is i_inventory.gd.
Each PopochiuCharacter has its own inventory dictionary.
Methods on this interface accept an optional character parameter; when omitted,
they default to the current player character (C.player).
Capabilities include:
-
Add or remove items from a character's 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 player's inventory.
I.DeckOfCards.add()
# Add the Key item to Popsy's inventory and make it the selected one.
I.Key.add_as_active(1, C.Popsy)
# Remove the Card item from the player's 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 | is_restoring | false |
| Array | items deprecated | _set_items, get = _get_items |
| Variant | items_states | {} |
Methods
| Return Type | Method |
|---|---|
| void | add_item(item: PopochiuInventoryItem, quantity = 1, character: PopochiuCharacter = null) |
| void | clean_inventory(character: PopochiuCharacter = null) |
| void | clean_inventory_bg(character: PopochiuCharacter = null) |
| void | deselect_active() |
| PopochiuInventoryItem | get_instance(script_name: String) |
| PopochiuInventoryItem | get_item_instance(item_name: String) |
| int | get_item_quantity(item_name: String, character: PopochiuCharacter = null) |
| bool | has_item_been_collected(item_name: String) |
| void | hide_inventory(use_anim = true) |
| bool | is_full(character: PopochiuCharacter = null) |
| bool | is_item_in_any_inventory(item_name: String) |
| bool | is_item_in_inventory(item_name: String, character: PopochiuCharacter = null) |
| Callable | queue_hide_inventory(use_anim = true) |
| Callable | queue_show_inventory(time = 1.0) |
| void | register_existing_item(item: PopochiuInventoryItem, character: PopochiuCharacter = null) |
| void | remove_item(item: PopochiuInventoryItem, quantity: int = 0, character: PopochiuCharacter = null) |
| void | replace_item(item: PopochiuInventoryItem, new_item: PopochiuInventoryItem, character: PopochiuCharacter = null) |
| void | set_active(value: PopochiuInventoryItem) |
| void | set_active_item(item: PopochiuInventoryItem = null) |
| void | set_item_in_inventory_bg(item: PopochiuInventoryItem, value: bool, character: PopochiuCharacter = null) |
| void | show_inventory(time = 1.0) |
Signals
- inventory_hide_requested(use_anim: bool)
- inventory_show_requested(time: float)
- inventory_shown()
- item_add_done(item: PopochiuInventoryItem, character: PopochiuCharacter)
- item_added(item: PopochiuInventoryItem, character: PopochiuCharacter)
- item_discarded(item: PopochiuInventoryItem)
- item_quantity_updated()
- item_remove_done(item: PopochiuInventoryItem, character: PopochiuCharacter)
- item_removed(item: PopochiuInventoryItem, character: PopochiuCharacter)
- item_replace_done()
- item_replaced()
- item_selected(item: PopochiuInventoryItem)
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, character: PopochiuCharacter)
Emitted when the item has finished entering character's inventory (GUI
animation completed).
item_added
signal item_added(item: PopochiuInventoryItem, character: PopochiuCharacter)
Emitted when item is added to character's inventory.
item_discarded
signal item_discarded(item: PopochiuInventoryItem)
Emitted when the item has been discarded (GUI animation finished).
item_quantity_updated
signal item_quantity_updated()
Emitted when the quantity of item changes in character's inventory without the
item being added to or removed from the inventory (i.e., when stacking or partially removing).
new_quantity is the updated count.
item_remove_done
signal item_remove_done(item: PopochiuInventoryItem, character: PopochiuCharacter)
Emitted when the item has finished leaving character's inventory (GUI
animation completed).
item_removed
signal item_removed(item: PopochiuInventoryItem, character: PopochiuCharacter)
Emitted when item is removed from character's inventory.
item_replace_done
signal item_replace_done()
Emitted when an item replacement has finished.
item_replaced
signal item_replaced()
Emitted when item is replaced in character's 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.
is_restoring
var is_restoring = false
When true, the inventory is being restored from a save file. GUI components
should skip entrance/exit animations during restore.
items
var items : Array = _set_items, get = _get_items
- Getter:
_get_items - Setter:
_set_items
Deprecated
Use inventory instead.
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
add_item
func add_item(item: PopochiuInventoryItem, quantity = 1, character: PopochiuCharacter = null) -> void
Adds quantity of item to character's inventory (default:
player) and waits until any GUI transition has finished.
Inventory capacity is slot-based: stacked quantities still occupy a single slot and
count as 1 against the inventory limit.
clean_inventory
func clean_inventory(character: PopochiuCharacter = null) -> void
Removes all items from character's inventory (default: player).
When items are removed the GUI lifecycle gets triggered once for each item, so the GUI may play
animations if necessary.
clean_inventory_bg
func clean_inventory_bg(character: PopochiuCharacter = null) -> void
Removes all items from character's inventory (default: player)
without triggering GUI lifecycle (useful during scene transitions).
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.
get_item_quantity
func get_item_quantity(item_name: String, character: PopochiuCharacter = null) -> int
Returns the number of item_name currently owned by character (default:
player).
Returns 0 if the item is not in the inventory.
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
by any character.
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(character: PopochiuCharacter = null) -> bool
Returns true if character's inventory (default:
player) has reached the inventory limit configured in the
project settings. The limit counts occupied slots, not total owned quantity, so a stacked item
still occupies a single slot and counts as 1.
is_item_in_any_inventory
func is_item_in_any_inventory(item_name: String) -> bool
Returns true if the item identified by item_name is in any character's
inventory. Used for props with link_to_item.
is_item_in_inventory
func is_item_in_inventory(item_name: String, character: PopochiuCharacter = null) -> bool
Returns true if the item identified by item_name is currently in
character's inventory (default: player).
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.
register_existing_item
func register_existing_item(item: PopochiuInventoryItem, character: PopochiuCharacter = null) -> void
Registers an inventory item that is already present in a GUI scene without running the full
add-item flow. Associates it with character's inventory (default:
player).
remove_item
func remove_item(item: PopochiuInventoryItem, quantity: int = 0, character: PopochiuCharacter = null) -> void
Removes quantity of item from character's inventory (default:
player) and waits until any GUI transition has finished.
Use 0 to remove the full stack.
replace_item
func replace_item(item: PopochiuInventoryItem, new_item: PopochiuInventoryItem, character: PopochiuCharacter = null) -> void
Replaces item in character's inventory (default:
player) with new_item and waits until the GUI swap has
finished. Replacing removes the whole collected quantity of item and adds exactly one
quantity of new_item.
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.
set_item_in_inventory_bg
func set_item_in_inventory_bg(item: PopochiuInventoryItem, value: bool, character: PopochiuCharacter = null) -> void
Applies the deprecated in_inventory setter semantics without
emitting inventory signals or awaiting GUI transitions. Use add_item() and
remove_item() for normal gameplay flow.
show_inventory
func show_inventory(time = 1.0) -> void
Shows the inventory for time seconds.