2026-07-29 00:05:40 +02:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
|
|
@export_category("Inventory")
|
|
|
|
|
@export var INVENTORY_MAX = 3 ##max number of items that can be in the player's inventory
|
|
|
|
|
@export var INVENTORY_ITEMS: Array = [] ##the items in the player's inventory
|
2026-07-29 13:52:14 +02:00
|
|
|
@onready var ui_handler: Node = %UiHandler
|
|
|
|
|
|
|
|
|
|
|
2026-07-29 00:05:40 +02:00
|
|
|
|
|
|
|
|
var stamina: float = 100.0
|
|
|
|
|
var selected_item: int = 0
|
|
|
|
|
var stamina_recharge: bool = true
|
2026-07-29 13:52:14 +02:00
|
|
|
var inventory: Array[PackedScene] = []
|
2026-07-29 00:05:40 +02:00
|
|
|
|
2026-07-29 13:52:14 +02:00
|
|
|
signal selected_item_changed
|
|
|
|
|
|
|
|
|
|
func next_item():
|
|
|
|
|
if selected_item + 1 > INVENTORY_MAX - 1:
|
|
|
|
|
selected_item = 0
|
|
|
|
|
else:
|
|
|
|
|
selected_item += 1
|
|
|
|
|
select_item(selected_item)
|
|
|
|
|
|
|
|
|
|
func prev_item():
|
|
|
|
|
if selected_item - 1 < 0:
|
|
|
|
|
selected_item = INVENTORY_MAX - 1
|
|
|
|
|
else:
|
|
|
|
|
selected_item -= 1
|
|
|
|
|
select_item(selected_item)
|
2026-07-29 00:05:40 +02:00
|
|
|
|
|
|
|
|
func select_item(index:int):
|
|
|
|
|
selected_item = index
|
2026-07-29 13:52:14 +02:00
|
|
|
ui_handler.update_inventory_ui()
|
|
|
|
|
emit_signal("selected_item_changed")
|
2026-07-29 00:05:40 +02:00
|
|
|
|
2026-07-29 13:52:14 +02:00
|
|
|
func get_selected_item() -> PackedScene:
|
|
|
|
|
return inventory[selected_item]
|
|
|
|
|
|
|
|
|
|
func stamina_recharge_off():
|
|
|
|
|
stamina_recharge = false
|
2026-07-29 00:05:40 +02:00
|
|
|
|
|
|
|
|
func _on_stamina_reset_timeout() -> void:
|
|
|
|
|
stamina_recharge = true
|
2026-07-29 13:52:14 +02:00
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
select_item(0)
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
if stamina_recharge:
|
|
|
|
|
stamina = move_toward(stamina, 100, .5)
|
|
|
|
|
|
|
|
|
|
if Input.is_action_just_pressed("next_item"):
|
|
|
|
|
next_item()
|
|
|
|
|
|
|
|
|
|
if Input.is_action_just_pressed("prev_item"):
|
|
|
|
|
prev_item()
|
|
|
|
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
|
|
|
if Input.is_action_just_pressed("select_item_1"):
|
|
|
|
|
select_item(0)
|
|
|
|
|
|
|
|
|
|
if Input.is_action_just_pressed("select_item_2"):
|
|
|
|
|
select_item(1)
|
|
|
|
|
|
|
|
|
|
if Input.is_action_just_pressed("select_item_3"):
|
|
|
|
|
select_item(2)
|