Broken pos
This commit is contained in:
parent
11d928c4f3
commit
3af13d0a8b
24 changed files with 304 additions and 146 deletions
15
generic/items/dbg_input1.tres
Normal file
15
generic/items/dbg_input1.tres
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[gd_resource type="Resource" script_class="Item" load_steps=4 format=3 uid="uid://cpjlj1vm46t08"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://gfkhedfdi7ug" path="res://sprites/atlasses/Popekko.png" id="1_hmnnx"]
|
||||||
|
[ext_resource type="Script" uid="uid://p5327ibxtyfs" path="res://scripts/item.gd" id="2_t6mdl"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_h7cm1"]
|
||||||
|
atlas = ExtResource("1_hmnnx")
|
||||||
|
region = Rect2(0, 16, 4, 4)
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_t6mdl")
|
||||||
|
display_name = &"Input1"
|
||||||
|
preview = SubResource("AtlasTexture_h7cm1")
|
||||||
|
stack_size = 2
|
||||||
|
metadata/_custom_type_script = "uid://p5327ibxtyfs"
|
15
generic/items/dbg_input2.tres
Normal file
15
generic/items/dbg_input2.tres
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[gd_resource type="Resource" script_class="Item" load_steps=4 format=3 uid="uid://c23vqjqnyo6f3"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://gfkhedfdi7ug" path="res://sprites/atlasses/Popekko.png" id="1_7lekm"]
|
||||||
|
[ext_resource type="Script" uid="uid://p5327ibxtyfs" path="res://scripts/item.gd" id="2_50iur"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_7lekm"]
|
||||||
|
atlas = ExtResource("1_7lekm")
|
||||||
|
region = Rect2(4, 16, 4, 4)
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_50iur")
|
||||||
|
display_name = &"Input2"
|
||||||
|
preview = SubResource("AtlasTexture_7lekm")
|
||||||
|
stack_size = 2
|
||||||
|
metadata/_custom_type_script = "uid://p5327ibxtyfs"
|
|
@ -1,17 +0,0 @@
|
||||||
[gd_resource type="Resource" script_class="Item" load_steps=5 format=3 uid="uid://byn78mwy08ff"]
|
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://gfkhedfdi7ug" path="res://sprites/atlasses/Popekko.png" id="1_1hrh7"]
|
|
||||||
[ext_resource type="Script" uid="uid://p5327ibxtyfs" path="res://scripts/item.gd" id="1_2pbm1"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://bbh7akfbskq4u" path="res://scenes/debug_item.tscn" id="2_1hrh7"]
|
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_trycy"]
|
|
||||||
atlas = ExtResource("1_1hrh7")
|
|
||||||
region = Rect2(0, 0, 5, 5)
|
|
||||||
|
|
||||||
[resource]
|
|
||||||
script = ExtResource("1_2pbm1")
|
|
||||||
display_name = &"Test"
|
|
||||||
preview = SubResource("AtlasTexture_trycy")
|
|
||||||
stack_size = 100
|
|
||||||
scene = ExtResource("2_1hrh7")
|
|
||||||
metadata/_custom_type_script = "uid://p5327ibxtyfs"
|
|
15
generic/items/dbg_output.tres
Normal file
15
generic/items/dbg_output.tres
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[gd_resource type="Resource" script_class="Item" load_steps=4 format=3 uid="uid://c16fy6r43xlg1"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://gfkhedfdi7ug" path="res://sprites/atlasses/Popekko.png" id="1_r3jjm"]
|
||||||
|
[ext_resource type="Script" uid="uid://p5327ibxtyfs" path="res://scripts/item.gd" id="2_rkyi0"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_r3jjm"]
|
||||||
|
atlas = ExtResource("1_r3jjm")
|
||||||
|
region = Rect2(8, 16, 4, 4)
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_rkyi0")
|
||||||
|
display_name = &"Output"
|
||||||
|
preview = SubResource("AtlasTexture_r3jjm")
|
||||||
|
stack_size = 100
|
||||||
|
metadata/_custom_type_script = "uid://p5327ibxtyfs"
|
31
generic/recipes/test_recipe.tres
Normal file
31
generic/recipes/test_recipe.tres
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
[gd_resource type="Resource" script_class="Recipe" load_steps=9 format=3 uid="uid://d2lbc1qqkayaa"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://w4v6jqv1ygqb" path="res://scripts/recipe/recipe_part.gd" id="1_no0hw"]
|
||||||
|
[ext_resource type="Resource" uid="uid://cpjlj1vm46t08" path="res://generic/items/dbg_input1.tres" id="2_f53xa"]
|
||||||
|
[ext_resource type="Script" uid="uid://dl0i68ut0lw70" path="res://scripts/recipe/recipe.gd" id="2_w6qf0"]
|
||||||
|
[ext_resource type="Resource" uid="uid://c23vqjqnyo6f3" path="res://generic/items/dbg_input2.tres" id="3_heoi8"]
|
||||||
|
[ext_resource type="Resource" uid="uid://c16fy6r43xlg1" path="res://generic/items/dbg_output.tres" id="4_0enwg"]
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id="Resource_q2e78"]
|
||||||
|
script = ExtResource("1_no0hw")
|
||||||
|
item = ExtResource("2_f53xa")
|
||||||
|
amount = 1
|
||||||
|
metadata/_custom_type_script = "uid://w4v6jqv1ygqb"
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id="Resource_ry6el"]
|
||||||
|
script = ExtResource("1_no0hw")
|
||||||
|
item = ExtResource("3_heoi8")
|
||||||
|
amount = 1
|
||||||
|
metadata/_custom_type_script = "uid://w4v6jqv1ygqb"
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id="Resource_ek2yb"]
|
||||||
|
script = ExtResource("1_no0hw")
|
||||||
|
item = ExtResource("4_0enwg")
|
||||||
|
amount = 5
|
||||||
|
metadata/_custom_type_script = "uid://w4v6jqv1ygqb"
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("2_w6qf0")
|
||||||
|
ingridients = Array[ExtResource("1_no0hw")]([SubResource("Resource_q2e78"), SubResource("Resource_ry6el")])
|
||||||
|
result = SubResource("Resource_ek2yb")
|
||||||
|
metadata/_custom_type_script = "uid://dl0i68ut0lw70"
|
|
@ -9,15 +9,18 @@
|
||||||
[sub_resource type="Resource" id="Resource_t4je2"]
|
[sub_resource type="Resource" id="Resource_t4je2"]
|
||||||
resource_local_to_scene = true
|
resource_local_to_scene = true
|
||||||
script = ExtResource("3_ruvuk")
|
script = ExtResource("3_ruvuk")
|
||||||
capacity = 8
|
capacity = 4
|
||||||
progress_speed = 2.0
|
|
||||||
pop_treshold = 0.95
|
pop_treshold = 0.95
|
||||||
internal_array = Array[ExtResource("2_54w8r")]([Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
internal_array = Array[ExtResource("2_54w8r")]([Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0,"filter":null)
|
||||||
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0,"filter":null)
|
||||||
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0,"filter":null)
|
||||||
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0,"filter":null)
|
||||||
|
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0,"filter":null)
|
||||||
|
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0,"filter":null)
|
||||||
|
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0,"filter":null)
|
||||||
|
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0,"filter":null)
|
||||||
])
|
])
|
||||||
progress_array = Array[float]([0.0, 0.0, 0.0, 0.0])
|
progress_array = Array[float]([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
|
||||||
metadata/_custom_type_script = "uid://v0hkuo3gda1b"
|
metadata/_custom_type_script = "uid://v0hkuo3gda1b"
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_54w8r"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_54w8r"]
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
[gd_scene load_steps=4 format=3 uid="uid://dfatkxv6n55dw"]
|
[gd_scene load_steps=9 format=3 uid="uid://dfatkxv6n55dw"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/structure.gd" id="1_k5y3y"]
|
[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/structure.gd" id="1_k5y3y"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="2_4befw"]
|
[ext_resource type="Texture2D" uid="uid://gfkhedfdi7ug" path="res://sprites/atlasses/Popekko.png" id="2_4befw"]
|
||||||
|
[ext_resource type="Script" uid="uid://bd4ojfqrl8idm" path="res://scripts/inventory/inventory_slot.gd" id="2_p1cyh"]
|
||||||
|
[ext_resource type="Script" uid="uid://m6b6vawdqgqb" path="res://scripts/inventory/in_out_inventory.gd" id="3_wqoim"]
|
||||||
|
[ext_resource type="Script" uid="uid://c7mx3uatj6ulm" path="res://scripts/structures/assembler.gd" id="5_0x00x"]
|
||||||
|
[ext_resource type="Resource" uid="uid://d2lbc1qqkayaa" path="res://generic/recipes/test_recipe.tres" id="6_wqoim"]
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id="Resource_kno0u"]
|
||||||
|
script = ExtResource("3_wqoim")
|
||||||
|
input_capacity = 2
|
||||||
|
output_capacity = 1
|
||||||
|
metadata/_custom_type_script = "uid://m6b6vawdqgqb"
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_xh4eg"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_xh4eg"]
|
||||||
atlas = ExtResource("2_4befw")
|
atlas = ExtResource("2_4befw")
|
||||||
|
@ -10,7 +20,13 @@ region = Rect2(32, 0, 32, 32)
|
||||||
[node name="DebugAssembler" type="Node2D"]
|
[node name="DebugAssembler" type="Node2D"]
|
||||||
script = ExtResource("1_k5y3y")
|
script = ExtResource("1_k5y3y")
|
||||||
dimensions = Rect2i(0, 0, 2, 2)
|
dimensions = Rect2i(0, 0, 2, 2)
|
||||||
|
inventory = SubResource("Resource_kno0u")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
texture = SubResource("AtlasTexture_xh4eg")
|
texture = SubResource("AtlasTexture_xh4eg")
|
||||||
offset = Vector2(8, 8)
|
offset = Vector2(8, 8)
|
||||||
|
|
||||||
|
[node name="Assembler" type="Node2D" parent="."]
|
||||||
|
position = Vector2(16, 16)
|
||||||
|
script = ExtResource("5_0x00x")
|
||||||
|
selected_recipe = ExtResource("6_wqoim")
|
||||||
|
|
|
@ -16,5 +16,6 @@ metadata/_custom_type_script = "uid://bbd7o2st8kmgl"
|
||||||
self_modulate = Color(1, 0, 0, 1)
|
self_modulate = Color(1, 0, 0, 1)
|
||||||
texture = SubResource("AtlasTexture_wxqk4")
|
texture = SubResource("AtlasTexture_wxqk4")
|
||||||
|
|
||||||
[node name="ItemDeposit" type="Node" parent="."]
|
[node name="ItemDeposit" type="Node2D" parent="."]
|
||||||
script = ExtResource("5_nh3xp")
|
script = ExtResource("5_nh3xp")
|
||||||
|
metadata/_custom_type_script = "uid://iidfsh0lirc2"
|
||||||
|
|
|
@ -34,7 +34,7 @@ func deferred_init():
|
||||||
## Finds first entry of item. Returns -1 if no item found
|
## Finds first entry of item. Returns -1 if no item found
|
||||||
func find(item : Item) -> int:
|
func find(item : Item) -> int:
|
||||||
for i in range(capacity):
|
for i in range(capacity):
|
||||||
if internal_array[i].held_item == item:
|
if internal_array[i].can_be_merged(item):
|
||||||
return i
|
return i
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
@ -58,15 +58,15 @@ func add_from_side(stack : Stack, ang_diff : float) -> Stack:
|
||||||
return internal_array[capacity-1].merge_stack(stack)
|
return internal_array[capacity-1].merge_stack(stack)
|
||||||
return add(stack)
|
return add(stack)
|
||||||
|
|
||||||
func can_add() -> bool:
|
func can_add(_item : Item = null) -> bool:
|
||||||
return internal_array[0].amount == 0
|
return internal_array[0].amount == 0
|
||||||
|
|
||||||
func can_add_from_side(ang_diff : float) -> bool:
|
func can_add_from_side(ang_diff : float, item : Item = null) -> bool:
|
||||||
if is_equal_approx(abs(ang_diff),PI/2):
|
if is_equal_approx(abs(ang_diff),PI/2):
|
||||||
return internal_array[capacity/2].amount == 0
|
return internal_array[capacity/2].amount == 0
|
||||||
elif is_equal_approx(abs(ang_diff),PI):
|
elif is_equal_approx(abs(ang_diff),PI):
|
||||||
return internal_array[capacity-1].amount == 0
|
return internal_array[capacity-1].amount == 0
|
||||||
return can_add()
|
return can_add(item)
|
||||||
|
|
||||||
## Tries to take first item. Returns null if no items in inventory
|
## Tries to take first item. Returns null if no items in inventory
|
||||||
func pop() -> Stack:
|
func pop() -> Stack:
|
||||||
|
@ -77,6 +77,13 @@ func pop() -> Stack:
|
||||||
stack_taken.emit(internal_array[capacity-1], capacity-1)
|
stack_taken.emit(internal_array[capacity-1], capacity-1)
|
||||||
return internal_array[capacity-1].extract()
|
return internal_array[capacity-1].extract()
|
||||||
|
|
||||||
|
func peek() -> Stack:
|
||||||
|
if internal_array[capacity-1].amount == 0:
|
||||||
|
return null
|
||||||
|
if progress_array[capacity-1] < pop_treshold:
|
||||||
|
return null
|
||||||
|
return internal_array[capacity-1].as_stack()
|
||||||
|
|
||||||
func advance(delta : float) -> void:
|
func advance(delta : float) -> void:
|
||||||
var progress_flag : bool = false
|
var progress_flag : bool = false
|
||||||
for i in range(capacity):
|
for i in range(capacity):
|
||||||
|
|
94
scripts/inventory/in_out_inventory.gd
Normal file
94
scripts/inventory/in_out_inventory.gd
Normal file
|
@ -0,0 +1,94 @@
|
||||||
|
@tool
|
||||||
|
extends Inventory
|
||||||
|
|
||||||
|
class_name InOutInventory
|
||||||
|
|
||||||
|
@export var input_capacity : int
|
||||||
|
@export var output_capacity : int
|
||||||
|
|
||||||
|
@export_storage var input_array : Array[InventorySlot]
|
||||||
|
@export_storage var output_array : Array[InventorySlot]
|
||||||
|
|
||||||
|
func resize() -> void:
|
||||||
|
input_array.resize(input_capacity)
|
||||||
|
output_array.resize(output_capacity)
|
||||||
|
for i in range(input_capacity):
|
||||||
|
input_array[i] = InventorySlot.new()
|
||||||
|
for i in range(output_capacity):
|
||||||
|
output_array[i] = InventorySlot.new()
|
||||||
|
|
||||||
|
func _init() -> void:
|
||||||
|
super()
|
||||||
|
resize.call_deferred()
|
||||||
|
|
||||||
|
func add(stack : Stack) -> Stack:
|
||||||
|
var found_index : int = find_input(stack.held_item)
|
||||||
|
if found_index != -1:
|
||||||
|
stack_added.emit(stack,found_index)
|
||||||
|
stack = input_array[found_index].merge_stack(stack)
|
||||||
|
if stack == null:
|
||||||
|
return null
|
||||||
|
for i in range(input_capacity):
|
||||||
|
if input_array[i].can_be_merged(stack.held_item):
|
||||||
|
stack_added.emit(stack,i)
|
||||||
|
stack = input_array[i].merge_stack(stack)
|
||||||
|
if stack == null:
|
||||||
|
return null
|
||||||
|
return stack
|
||||||
|
|
||||||
|
func add_from_side(stack : Stack, _ang_diff : float) -> Stack:
|
||||||
|
return add(stack)
|
||||||
|
|
||||||
|
func can_add(item : Item = null) -> bool:
|
||||||
|
if item == null:
|
||||||
|
for i in range(input_capacity):
|
||||||
|
return input_array[i].amount == 0
|
||||||
|
return false
|
||||||
|
else:
|
||||||
|
for i in range(input_capacity):
|
||||||
|
print(input_array[i].filter)
|
||||||
|
if input_array[i].can_be_merged(item):
|
||||||
|
print(input_array[i].filter)
|
||||||
|
return true
|
||||||
|
#return true
|
||||||
|
return false
|
||||||
|
|
||||||
|
func can_add_from_side(_ang_diff : float,item: Item = null) -> bool:
|
||||||
|
return can_add(item)
|
||||||
|
|
||||||
|
## Tries to take first item. Returns null if no items in inventory
|
||||||
|
func pop() -> Stack:
|
||||||
|
for i in range(output_capacity):
|
||||||
|
if output_array[i].held_item != null:
|
||||||
|
var extracted = output_array[i].extract()
|
||||||
|
stack_taken.emit(extracted,i)
|
||||||
|
return extracted
|
||||||
|
return null
|
||||||
|
|
||||||
|
func peek() -> Stack:
|
||||||
|
for i in range(output_capacity):
|
||||||
|
if output_array[i].held_item != null:
|
||||||
|
var peeked = output_array[i].as_stack()
|
||||||
|
return peeked
|
||||||
|
return null
|
||||||
|
|
||||||
|
## Tries to take certain item from inventory. Returns null if no item found
|
||||||
|
func take(item: Item,amount: int) -> Stack:
|
||||||
|
var found = find(item)
|
||||||
|
if found == -1:
|
||||||
|
return null
|
||||||
|
var extracted = output_array[found].extract_stack(amount)
|
||||||
|
stack_taken.emit(extracted,found)
|
||||||
|
return extracted
|
||||||
|
|
||||||
|
func find_input(item : Item) -> int:
|
||||||
|
for i in range(input_capacity):
|
||||||
|
if input_array[i].held_item == item:
|
||||||
|
return i
|
||||||
|
return -1
|
||||||
|
|
||||||
|
func find(item : Item) -> int:
|
||||||
|
for i in range(output_capacity):
|
||||||
|
if output_array[i].held_item == item:
|
||||||
|
return i
|
||||||
|
return -1
|
1
scripts/inventory/in_out_inventory.gd.uid
Normal file
1
scripts/inventory/in_out_inventory.gd.uid
Normal file
|
@ -0,0 +1 @@
|
||||||
|
uid://m6b6vawdqgqb
|
|
@ -18,14 +18,17 @@ func add_from_side(stack : Stack, ang_diff : float) -> Stack
|
||||||
|
|
||||||
## Returns if conditions of adding are met
|
## Returns if conditions of adding are met
|
||||||
@abstract
|
@abstract
|
||||||
func can_add() -> bool
|
func can_add(item : Item = null) -> bool
|
||||||
@abstract
|
@abstract
|
||||||
func can_add_from_side(ang_diff : float) -> bool
|
func can_add_from_side(ang_diff : float, item : Item = null) -> bool
|
||||||
|
|
||||||
## Tries to take first item. Returns null if no items in inventory
|
## Tries to take first item. Returns null if no items in inventory
|
||||||
@abstract
|
@abstract
|
||||||
func pop() -> Stack
|
func pop() -> Stack
|
||||||
|
|
||||||
|
@abstract
|
||||||
|
func peek() -> Stack
|
||||||
|
|
||||||
## Tries to take certain item from inventory. Returns null if no item found
|
## Tries to take certain item from inventory. Returns null if no item found
|
||||||
@abstract
|
@abstract
|
||||||
func take(item : Item,amount: int) -> Stack
|
func take(item : Item,amount: int) -> Stack
|
||||||
|
|
|
@ -28,6 +28,8 @@ class_name InventorySlot
|
||||||
get:
|
get:
|
||||||
return amount
|
return amount
|
||||||
|
|
||||||
|
@export_storage var filter : Comparable
|
||||||
|
|
||||||
## Get some amount of items from slot. Returns null if slot is empty
|
## Get some amount of items from slot. Returns null if slot is empty
|
||||||
func extract_stack(extract_amount: int) -> Stack:
|
func extract_stack(extract_amount: int) -> Stack:
|
||||||
if amount == 0:
|
if amount == 0:
|
||||||
|
@ -53,9 +55,26 @@ func extract() -> Stack:
|
||||||
|
|
||||||
return return_stack
|
return return_stack
|
||||||
|
|
||||||
|
func as_stack() -> Stack:
|
||||||
|
if amount == 0:
|
||||||
|
return null
|
||||||
|
|
||||||
|
var return_stack : Stack = Stack.new(held_item,amount)
|
||||||
|
|
||||||
|
return return_stack
|
||||||
|
|
||||||
|
func can_be_merged(item : Item) -> bool:
|
||||||
|
if filter != null:
|
||||||
|
return filter.is_equal(item)
|
||||||
|
if amount == 0:
|
||||||
|
return true
|
||||||
|
return item == held_item
|
||||||
|
|
||||||
## Add provided stack's amount to this amount. Returns null if stack is empty or items arent matching
|
## Add provided stack's amount to this amount. Returns null if stack is empty or items arent matching
|
||||||
func merge_stack(stack: Stack) -> Stack:
|
func merge_stack(stack: Stack) -> Stack:
|
||||||
if held_item == null:
|
if held_item == null:
|
||||||
|
if filter != null and filter.is_equal(stack.held_item) == false:
|
||||||
|
return stack
|
||||||
held_item = stack.held_item
|
held_item = stack.held_item
|
||||||
amount = stack.amount
|
amount = stack.amount
|
||||||
return null
|
return null
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
@tool
|
|
||||||
|
|
||||||
extends Inventory
|
|
||||||
|
|
||||||
## Base class for FIFO inventories.
|
|
||||||
|
|
||||||
class_name Queue
|
|
||||||
|
|
||||||
## Amount of stacks that can be held in storage
|
|
||||||
@export var capacity : int:
|
|
||||||
set(value):
|
|
||||||
if value < 0:
|
|
||||||
return
|
|
||||||
if value == capacity:
|
|
||||||
return
|
|
||||||
capacity = value
|
|
||||||
get:
|
|
||||||
return capacity
|
|
||||||
|
|
||||||
## :3
|
|
||||||
@export_storage var internal_array : Array[InventorySlot] = []
|
|
||||||
|
|
||||||
|
|
||||||
func _init() -> void:
|
|
||||||
super()
|
|
||||||
internal_array.resize(capacity)
|
|
||||||
for i in range(capacity):
|
|
||||||
internal_array[i] = InventorySlot.new()
|
|
||||||
|
|
||||||
## Finds first entry of item. Returns -1 if no item found
|
|
||||||
func find(item : Item) -> int:
|
|
||||||
for i in range(len(internal_array)):
|
|
||||||
if internal_array[i].held_item == item:
|
|
||||||
return i
|
|
||||||
return -1
|
|
||||||
|
|
||||||
## Tries to add an item into inventory. Returns not stored stack of item.
|
|
||||||
func add(stack: Stack) -> Stack:
|
|
||||||
for i in range(len(internal_array)):
|
|
||||||
if internal_array[i].held_item == null or internal_array[i].held_item == stack.held_item:
|
|
||||||
stack_added.emit(stack,i)
|
|
||||||
stack = internal_array[i].merge_stack(stack)
|
|
||||||
if stack == null:
|
|
||||||
return null
|
|
||||||
return stack
|
|
||||||
|
|
||||||
func add_from_side(stack : Stack, _ang_diff : float) -> Stack:
|
|
||||||
return add(stack)
|
|
||||||
|
|
||||||
func can_add() -> bool:
|
|
||||||
for i in range(capacity):
|
|
||||||
if internal_array[i].amount == 0:
|
|
||||||
return true
|
|
||||||
return false
|
|
||||||
|
|
||||||
func can_add_from_side(_ang_diff : float) -> bool:
|
|
||||||
return can_add()
|
|
||||||
|
|
||||||
## Tries to take first item. Returns null if no items in inventory
|
|
||||||
func pop() -> Stack:
|
|
||||||
if internal_array[0].held_item == null:
|
|
||||||
return null
|
|
||||||
var stack_to_return = internal_array[0].extract()
|
|
||||||
stack_taken.emit(stack_to_return,0)
|
|
||||||
sort()
|
|
||||||
return stack_to_return
|
|
||||||
|
|
||||||
## Tries to take certain item from inventory. Returns null if no item found
|
|
||||||
func take(item: Item,amount: int) -> Stack:
|
|
||||||
var found = find(item)
|
|
||||||
if found == -1:
|
|
||||||
return null
|
|
||||||
var stack_to_return = internal_array[found].extract_stack(amount)
|
|
||||||
stack_taken.emit(stack_to_return,found)
|
|
||||||
sort()
|
|
||||||
return stack_to_return
|
|
||||||
|
|
||||||
func sort() -> void:
|
|
||||||
for i in range(len(internal_array)-1):
|
|
||||||
if internal_array[i] == null:
|
|
||||||
internal_array[i].merge_stack(internal_array[i+1].extract())
|
|
|
@ -1 +0,0 @@
|
||||||
uid://q2gbtqfi32d
|
|
|
@ -21,6 +21,9 @@ class_name Storage
|
||||||
|
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
super()
|
super()
|
||||||
|
deferred_init.call_deferred()
|
||||||
|
|
||||||
|
func deferred_init():
|
||||||
internal_array.resize(capacity)
|
internal_array.resize(capacity)
|
||||||
for i in range(capacity):
|
for i in range(capacity):
|
||||||
internal_array[i] = InventorySlot.new()
|
internal_array[i] = InventorySlot.new()
|
||||||
|
@ -51,14 +54,20 @@ func add(stack: Stack) -> Stack:
|
||||||
func add_from_side(stack : Stack, _ang_diff : float) -> Stack:
|
func add_from_side(stack : Stack, _ang_diff : float) -> Stack:
|
||||||
return add(stack)
|
return add(stack)
|
||||||
|
|
||||||
func can_add() -> bool:
|
func can_add(item : Item = null) -> bool:
|
||||||
for i in range(capacity):
|
if item == null:
|
||||||
|
for i in range(internal_array):
|
||||||
|
return internal_array[i].amount == 0
|
||||||
|
return false
|
||||||
|
else:
|
||||||
|
for i in range(internal_array):
|
||||||
if internal_array[i].amount == 0:
|
if internal_array[i].amount == 0:
|
||||||
return true
|
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)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
func can_add_from_side(_ang_diff : float) -> bool:
|
func can_add_from_side(_ang_diff : float,item : Item = null) -> bool:
|
||||||
return can_add()
|
return can_add(item)
|
||||||
|
|
||||||
## Tries to take first item. Returns null if no items in inventory
|
## Tries to take first item. Returns null if no items in inventory
|
||||||
func pop() -> Stack:
|
func pop() -> Stack:
|
||||||
|
@ -69,6 +78,13 @@ func pop() -> Stack:
|
||||||
return extracted
|
return extracted
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
func peek() -> Stack:
|
||||||
|
for i in range(len(internal_array)):
|
||||||
|
if internal_array[i].held_item != null:
|
||||||
|
var peeked = internal_array[i].as_stack()
|
||||||
|
return peeked
|
||||||
|
return null
|
||||||
|
|
||||||
## Tries to take certain item from inventory. Returns null if no item found
|
## Tries to take certain item from inventory. Returns null if no item found
|
||||||
func take(item: Item,amount: int) -> Stack:
|
func take(item: Item,amount: int) -> Stack:
|
||||||
var found = find(item)
|
var found = find(item)
|
||||||
|
|
|
@ -17,7 +17,6 @@ func _input(event: InputEvent) -> void:
|
||||||
selected_prototype = null
|
selected_prototype = null
|
||||||
|
|
||||||
if event.is_action_pressed("plc_place") and delete_mode:
|
if event.is_action_pressed("plc_place") and delete_mode:
|
||||||
print(delete_mode)
|
|
||||||
var zone : PlacementZone = try_get_zone(global_position)
|
var zone : PlacementZone = try_get_zone(global_position)
|
||||||
if zone != null and zone.grid_controller.is_point_occupied(global_position):
|
if zone != null and zone.grid_controller.is_point_occupied(global_position):
|
||||||
zone.grid_controller.destroy_at(global_position)
|
zone.grid_controller.destroy_at(global_position)
|
||||||
|
|
5
scripts/structure_behaviour.gd
Normal file
5
scripts/structure_behaviour.gd
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
class_name StructureBehaviour
|
||||||
|
|
||||||
|
@onready var structure_parent : Structure = get_parent()
|
1
scripts/structure_behaviour.gd.uid
Normal file
1
scripts/structure_behaviour.gd.uid
Normal file
|
@ -0,0 +1 @@
|
||||||
|
uid://iidfsh0lirc2
|
19
scripts/structures/assembler.gd
Normal file
19
scripts/structures/assembler.gd
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
extends StructureBehaviour
|
||||||
|
|
||||||
|
@export var selected_recipe : Recipe
|
||||||
|
@onready var inventory : InOutInventory = get_parent().inventory
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
await get_tree().process_frame
|
||||||
|
switch_recipe(selected_recipe)
|
||||||
|
await get_tree().process_frame
|
||||||
|
for i in len(selected_recipe.ingridients):
|
||||||
|
inventory.input_array[i].filter = selected_recipe.ingridients[i].item
|
||||||
|
print(inventory.input_array[i].filter)
|
||||||
|
|
||||||
|
func switch_recipe(recipe: Recipe) -> void:
|
||||||
|
selected_recipe = recipe
|
||||||
|
inventory.input_capacity = len(selected_recipe.ingridients)
|
||||||
|
inventory.resize()
|
||||||
|
for i in len(selected_recipe.ingridients):
|
||||||
|
inventory.input_array[i].filter = selected_recipe.ingridients[i].item
|
1
scripts/structures/assembler.gd.uid
Normal file
1
scripts/structures/assembler.gd.uid
Normal file
|
@ -0,0 +1 @@
|
||||||
|
uid://c7mx3uatj6ulm
|
|
@ -1,7 +1,6 @@
|
||||||
extends Node2D
|
extends StructureBehaviour
|
||||||
|
|
||||||
@onready var parent_structure : Structure = get_parent()
|
@onready var inventory : BeltInventory = structure_parent.inventory
|
||||||
@onready var inventory : BeltInventory = parent_structure.inventory
|
|
||||||
@onready var animator : AnimationPlayer = $"../AnimationPlayer"
|
@onready var animator : AnimationPlayer = $"../AnimationPlayer"
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
@ -14,23 +13,22 @@ func _draw() -> void:
|
||||||
for i in range(inventory.capacity):
|
for i in range(inventory.capacity):
|
||||||
if inventory.internal_array[i].amount > 0:
|
if inventory.internal_array[i].amount > 0:
|
||||||
var calculated_position = calculate_position(i) - inventory.internal_array[i].held_item.preview.get_size()/2.0
|
var calculated_position = calculate_position(i) - inventory.internal_array[i].held_item.preview.get_size()/2.0
|
||||||
for j in range(inventory.internal_array[i].amount/10):
|
draw_texture(inventory.internal_array[i].held_item.preview,calculated_position)
|
||||||
draw_texture(inventory.internal_array[i].held_item.preview,calculated_position + Vector2(0,-j))
|
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
inventory.advance(delta)
|
inventory.advance(delta)
|
||||||
queue_redraw()
|
queue_redraw()
|
||||||
var next : Structure = get_next()
|
var next : Structure = get_next()
|
||||||
if next == null or next.inventory == null or next.inventory.can_add_from_side(Globals.facing_difference(next.facing,parent_structure.facing)) == false:
|
if next == null or next.inventory == null or next.inventory.can_add_from_side(Globals.facing_difference(next.facing,structure_parent.facing),inventory.internal_array[inventory.capacity-1].held_item) == false:
|
||||||
return
|
return
|
||||||
var popped = inventory.pop()
|
var popped = inventory.pop()
|
||||||
if popped == null:
|
if popped == null:
|
||||||
return
|
return
|
||||||
next.inventory.add_from_side(popped,Globals.facing_difference(next.facing,parent_structure.facing))
|
next.inventory.add_from_side(popped,Globals.facing_difference(next.facing,structure_parent.facing))
|
||||||
|
|
||||||
func calculate_position(index: int) -> Vector2:
|
func calculate_position(index: int) -> Vector2:
|
||||||
var indexed_part = 16.0 / inventory.capacity
|
var indexed_part = 16.0 / inventory.capacity
|
||||||
match parent_structure.facing:
|
match structure_parent.facing:
|
||||||
Structure.Facing.RIGHT:
|
Structure.Facing.RIGHT:
|
||||||
return Vector2.LEFT*8 + Vector2.RIGHT * indexed_part * (index + inventory.progress_array[index])
|
return Vector2.LEFT*8 + Vector2.RIGHT * indexed_part * (index + inventory.progress_array[index])
|
||||||
Structure.Facing.DOWN:
|
Structure.Facing.DOWN:
|
||||||
|
@ -42,16 +40,8 @@ func calculate_position(index: int) -> Vector2:
|
||||||
return Vector2.ZERO
|
return Vector2.ZERO
|
||||||
|
|
||||||
func get_next() -> Structure:
|
func get_next() -> Structure:
|
||||||
match parent_structure.facing:
|
var faced_vector = Structure.facing_to_vector(structure_parent.facing)
|
||||||
Structure.Facing.RIGHT:
|
return structure_parent.get_relative(faced_vector)
|
||||||
return parent_structure.get_relative(Vector2(1,0))
|
|
||||||
Structure.Facing.DOWN:
|
|
||||||
return parent_structure.get_relative(Vector2(0,1))
|
|
||||||
Structure.Facing.LEFT:
|
|
||||||
return parent_structure.get_relative(Vector2(-1,0))
|
|
||||||
Structure.Facing.UP:
|
|
||||||
return parent_structure.get_relative(Vector2(0,-1))
|
|
||||||
return null
|
|
||||||
|
|
||||||
func _on_conveyor_switched_facing(to: Structure.Facing) -> void:
|
func _on_conveyor_switched_facing(to: Structure.Facing) -> void:
|
||||||
match to:
|
match to:
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
extends Node
|
extends StructureBehaviour
|
||||||
|
|
||||||
const test_item :=preload("res://generic/items/dbg_item.tres")
|
const inp1 := preload("res://generic/items/dbg_input1.tres")
|
||||||
|
const inp2 := preload("res://generic/items/dbg_input2.tres")
|
||||||
|
const out := preload("res://generic/items/dbg_output.tres")
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
for point in [Vector2(-1,0),Vector2(1,0),Vector2(0,1),Vector2(0,-1)]:
|
try_add(Vector2.UP,Stack.new(inp1,1))
|
||||||
var found_structure :Structure = get_parent().get_relative(point)
|
try_add(Vector2.DOWN,Stack.new(inp2,1))
|
||||||
if found_structure and found_structure.inventory:
|
try_add(Vector2.RIGHT,Stack.new(out,1))
|
||||||
found_structure.inventory.add_from_side(Stack.new(test_item,randi_range(1,test_item.stack_size)),Structure.facing_to_vector(found_structure.facing).angle_to(point))
|
|
||||||
|
func try_add(dir: Vector2,stack : Stack):
|
||||||
|
var found = structure_parent.get_relative(dir)
|
||||||
|
if found != null:
|
||||||
|
found.inventory.add(stack)
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.6 KiB |
Loading…
Add table
Add a link
Reference in a new issue