Item void
This commit is contained in:
parent
788e42135f
commit
fa6212400b
7 changed files with 43 additions and 29 deletions
|
@ -1,16 +1,12 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://dpsrwmum6rbmi"]
|
||||
[gd_scene load_steps=6 format=3 uid="uid://dpsrwmum6rbmi"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/structure.gd" id="1_818vg"]
|
||||
[ext_resource type="Script" uid="uid://bd4ojfqrl8idm" path="res://scripts/inventory/inventory_slot.gd" id="2_y1ram"]
|
||||
[ext_resource type="Script" uid="uid://1scdy7mttx5h" path="res://scripts/inventory/storage.gd" id="3_lldoj"]
|
||||
[ext_resource type="Script" uid="uid://dwx8y8c6guldd" path="res://scripts/structures/trash_can.gd" id="4_mfdbk"]
|
||||
[ext_resource type="Script" uid="uid://conadqnb0asi0" path="res://scripts/inventory/void_inventory.gd" id="3_y1ram"]
|
||||
[ext_resource type="Texture2D" uid="uid://gfkhedfdi7ug" path="res://sprites/atlasses/Popekko.png" id="5_y1ram"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_fvoq6"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("3_lldoj")
|
||||
capacity = 1
|
||||
metadata/_custom_type_script = "uid://1scdy7mttx5h"
|
||||
[sub_resource type="Resource" id="Resource_818vg"]
|
||||
script = ExtResource("3_y1ram")
|
||||
metadata/_custom_type_script = "uid://conadqnb0asi0"
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_lldoj"]
|
||||
atlas = ExtResource("5_y1ram")
|
||||
|
@ -18,10 +14,7 @@ region = Rect2(80, 0, 16, 16)
|
|||
|
||||
[node name="TrashCan" type="Node2D"]
|
||||
script = ExtResource("1_818vg")
|
||||
inventory = SubResource("Resource_fvoq6")
|
||||
|
||||
[node name="Can" type="Node2D" parent="."]
|
||||
script = ExtResource("4_mfdbk")
|
||||
inventory = SubResource("Resource_818vg")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("AtlasTexture_lldoj")
|
||||
|
|
|
@ -20,6 +20,7 @@ class_name InventorySlot
|
|||
amount = 0
|
||||
return
|
||||
if held_item == null:
|
||||
amount = 0
|
||||
return
|
||||
if value > held_item.stack_size:
|
||||
amount = held_item.stack_size
|
||||
|
@ -66,7 +67,7 @@ func as_stack() -> Stack:
|
|||
func can_be_merged(item : Item) -> bool:
|
||||
if filter != null:
|
||||
return filter.is_equal(item)
|
||||
if amount == 0:
|
||||
if amount <= 0:
|
||||
return true
|
||||
return item == held_item
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ func add(stack: Stack, _context: InventoryContext = null) -> Stack:
|
|||
if stack.is_valid() == false:
|
||||
return null
|
||||
for i in range(len(internal_array)):
|
||||
if internal_array[i].held_item == null or internal_array[i].held_item == stack.held_item:
|
||||
if internal_array[i].can_be_merged(stack.held_item):
|
||||
stack_added.emit(stack,i)
|
||||
internal_array[i].merge_stack(stack)
|
||||
if stack.is_valid() == false:
|
||||
|
@ -54,13 +54,13 @@ func add(stack: Stack, _context: InventoryContext = null) -> Stack:
|
|||
func can_add(item : Item = null, _context: InventoryContext = null) -> bool:
|
||||
if item == null:
|
||||
for i in range(capacity):
|
||||
return internal_array[i].amount == 0
|
||||
if internal_array[i].can_be_merged(item):
|
||||
return true
|
||||
return false
|
||||
else:
|
||||
for i in range(capacity):
|
||||
if internal_array[i].amount == 0:
|
||||
return (internal_array[i].filter != null and internal_array[i].filter.is_equal(item)) or internal_array[i].filter == null
|
||||
return internal_array[i].held_item.is_equal(item)
|
||||
if internal_array[i].can_be_merged(item):
|
||||
return true
|
||||
return false
|
||||
|
||||
## Tries to take first item. Returns null if no items in inventory
|
||||
|
|
29
scripts/inventory/void_inventory.gd
Normal file
29
scripts/inventory/void_inventory.gd
Normal file
|
@ -0,0 +1,29 @@
|
|||
extends Inventory
|
||||
|
||||
## Base class for simple storages with no differentiation.
|
||||
|
||||
class_name VoidInventory
|
||||
|
||||
|
||||
## Tries to add an item into inventory. Returns not stored stack of item.
|
||||
func add(stack : Stack, context: InventoryContext = null) -> Stack:
|
||||
return null
|
||||
|
||||
## Returns if conditions of adding are met
|
||||
func can_add(item : Item = null, context: InventoryContext = null) -> bool:
|
||||
return true
|
||||
|
||||
## Tries to take first item. Returns null if no items in inventory
|
||||
func pop() -> Stack:
|
||||
return null
|
||||
|
||||
func peek() -> Stack:
|
||||
return null
|
||||
|
||||
## Tries to take certain item from inventory. Returns null if no item found
|
||||
func take(item : Item,amount: int) -> Stack:
|
||||
return null
|
||||
|
||||
## Finds first entry of item. Returns -1 if no item found
|
||||
func find(item : Item) -> int:
|
||||
return -1
|
1
scripts/inventory/void_inventory.gd.uid
Normal file
1
scripts/inventory/void_inventory.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://conadqnb0asi0
|
|
@ -1,9 +0,0 @@
|
|||
extends StructureBehaviour
|
||||
|
||||
@onready var inventory : Storage = structure_parent.inventory
|
||||
|
||||
func _ready() -> void:
|
||||
inventory.stack_added.connect(on_stack_added)
|
||||
|
||||
func on_stack_added(_stack : Stack, _position: int) -> void:
|
||||
inventory.internal_array[0].amount = 0
|
|
@ -1 +0,0 @@
|
|||
uid://dwx8y8c6guldd
|
Loading…
Add table
Add a link
Reference in a new issue