very simple prototype

This commit is contained in:
Tabby 2026-01-10 23:17:55 +11:00
parent aee93b8d10
commit 76c957236b
11 changed files with 261 additions and 190 deletions

View file

@ -0,0 +1,16 @@
extends ItemSlot
# broken experiement, do not use in current state
var duplicate_item : ItemData
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if item and not duplicate_item:
duplicate_item = item
if duplicate_item:
item = duplicate_item

View file

@ -0,0 +1 @@
uid://dtstlahhdlaqy

View file

@ -1,8 +1,16 @@
extends PanelContainer
class_name Inventory
@export var inventory_name : String = "Inventory"
@export var slots : Array[ItemSlot]
@export_group("Node References")
@export var grid : GridContainer
@export var inv_label : Label
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
slots.assign(grid.get_children())
inv_label.text = inventory_name
pass # Replace with function body.
@ -20,3 +28,15 @@ func _notification(what: int) -> void:
if data_bk:
data_bk.icon.show()
data_bk = null
#attempts to add the provided item to the inventory, returns true on success
func add_item(item : ItemData) -> bool:
for slot in slots:
if slot.item == null:
slot.item = item
slot.update_ui()
return true # item placed successfully
return false # theres no space to add the item

View file

@ -1,4 +1,5 @@
extends Panel
class_name ItemSlot
@export var icon : TextureRect
@export var item: ItemData

23
inv_system/item_slot.tscn Normal file
View file

@ -0,0 +1,23 @@
[gd_scene load_steps=3 format=3 uid="uid://dgqs20xf7l8c"]
[ext_resource type="Script" uid="uid://cpd04flfh5nlc" path="res://inv_system/item_slot.gd" id="1_m11ft"]
[ext_resource type="Texture2D" uid="uid://b7jp850fqpa0j" path="res://icon.svg" id="3_0tnt0"]
[node name="ItemSlot" type="Panel" node_paths=PackedStringArray("icon")]
custom_minimum_size = Vector2(64, 64)
script = ExtResource("1_m11ft")
icon = NodePath("Icon")
[node name="Icon" type="TextureRect" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.1
anchor_top = 0.1
anchor_right = 0.8
anchor_bottom = 0.9
offset_right = 6.4000015
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("3_0tnt0")
expand_mode = 3
stretch_mode = 4