Compare commits
No commits in common. "3af13d0a8be2efd69c68e81e5f92488ed2a5fa38" and "4bae29f29fc6bd80ba94b378c7fcce5e07c2fafb" have entirely different histories.
3af13d0a8b
...
4bae29f29f
33 changed files with 147 additions and 363 deletions
|
@ -1,15 +0,0 @@
|
|||
[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"
|
|
@ -1,15 +0,0 @@
|
|||
[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"
|
17
generic/items/dbg_item.tres
Normal file
17
generic/items/dbg_item.tres
Normal file
|
@ -0,0 +1,17 @@
|
|||
[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"
|
|
@ -1,15 +0,0 @@
|
|||
[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"
|
|
@ -1,31 +0,0 @@
|
|||
[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,18 +9,15 @@
|
|||
[sub_resource type="Resource" id="Resource_t4je2"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("3_ruvuk")
|
||||
capacity = 4
|
||||
capacity = 8
|
||||
progress_speed = 2.0
|
||||
pop_treshold = 0.95
|
||||
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,"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)
|
||||
, 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)
|
||||
internal_array = Array[ExtResource("2_54w8r")]([Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
||||
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
||||
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
||||
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
||||
])
|
||||
progress_array = Array[float]([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
|
||||
progress_array = Array[float]([0.0, 0.0, 0.0, 0.0])
|
||||
metadata/_custom_type_script = "uid://v0hkuo3gda1b"
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_54w8r"]
|
||||
|
|
|
@ -1,17 +1,7 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://dfatkxv6n55dw"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dfatkxv6n55dw"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/structure.gd" id="1_k5y3y"]
|
||||
[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"
|
||||
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="2_4befw"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_xh4eg"]
|
||||
atlas = ExtResource("2_4befw")
|
||||
|
@ -20,13 +10,7 @@ region = Rect2(32, 0, 32, 32)
|
|||
[node name="DebugAssembler" type="Node2D"]
|
||||
script = ExtResource("1_k5y3y")
|
||||
dimensions = Rect2i(0, 0, 2, 2)
|
||||
inventory = SubResource("Resource_kno0u")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("AtlasTexture_xh4eg")
|
||||
offset = Vector2(8, 8)
|
||||
|
||||
[node name="Assembler" type="Node2D" parent="."]
|
||||
position = Vector2(16, 16)
|
||||
script = ExtResource("5_0x00x")
|
||||
selected_recipe = ExtResource("6_wqoim")
|
||||
|
|
|
@ -16,6 +16,5 @@ metadata/_custom_type_script = "uid://bbd7o2st8kmgl"
|
|||
self_modulate = Color(1, 0, 0, 1)
|
||||
texture = SubResource("AtlasTexture_wxqk4")
|
||||
|
||||
[node name="ItemDeposit" type="Node2D" parent="."]
|
||||
[node name="ItemDeposit" type="Node" parent="."]
|
||||
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
|
||||
func find(item : Item) -> int:
|
||||
for i in range(capacity):
|
||||
if internal_array[i].can_be_merged(item):
|
||||
if internal_array[i].held_item == item:
|
||||
return i
|
||||
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 add(stack)
|
||||
|
||||
func can_add(_item : Item = null) -> bool:
|
||||
func can_add() -> bool:
|
||||
return internal_array[0].amount == 0
|
||||
|
||||
func can_add_from_side(ang_diff : float, item : Item = null) -> bool:
|
||||
func can_add_from_side(ang_diff : float) -> bool:
|
||||
if is_equal_approx(abs(ang_diff),PI/2):
|
||||
return internal_array[capacity/2].amount == 0
|
||||
elif is_equal_approx(abs(ang_diff),PI):
|
||||
return internal_array[capacity-1].amount == 0
|
||||
return can_add(item)
|
||||
return can_add()
|
||||
|
||||
## Tries to take first item. Returns null if no items in inventory
|
||||
func pop() -> Stack:
|
||||
|
@ -77,13 +77,6 @@ func pop() -> Stack:
|
|||
stack_taken.emit(internal_array[capacity-1], capacity-1)
|
||||
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:
|
||||
var progress_flag : bool = false
|
||||
for i in range(capacity):
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
@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 +0,0 @@
|
|||
uid://m6b6vawdqgqb
|
|
@ -18,17 +18,14 @@ func add_from_side(stack : Stack, ang_diff : float) -> Stack
|
|||
|
||||
## Returns if conditions of adding are met
|
||||
@abstract
|
||||
func can_add(item : Item = null) -> bool
|
||||
func can_add() -> bool
|
||||
@abstract
|
||||
func can_add_from_side(ang_diff : float, item : Item = null) -> bool
|
||||
func can_add_from_side(ang_diff : float) -> bool
|
||||
|
||||
## Tries to take first item. Returns null if no items in inventory
|
||||
@abstract
|
||||
func pop() -> Stack
|
||||
|
||||
@abstract
|
||||
func peek() -> Stack
|
||||
|
||||
## Tries to take certain item from inventory. Returns null if no item found
|
||||
@abstract
|
||||
func take(item : Item,amount: int) -> Stack
|
||||
|
|
|
@ -28,8 +28,6 @@ class_name InventorySlot
|
|||
get:
|
||||
return amount
|
||||
|
||||
@export_storage var filter : Comparable
|
||||
|
||||
## Get some amount of items from slot. Returns null if slot is empty
|
||||
func extract_stack(extract_amount: int) -> Stack:
|
||||
if amount == 0:
|
||||
|
@ -55,26 +53,9 @@ func extract() -> 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
|
||||
func merge_stack(stack: Stack) -> Stack:
|
||||
if held_item == null:
|
||||
if filter != null and filter.is_equal(stack.held_item) == false:
|
||||
return stack
|
||||
held_item = stack.held_item
|
||||
amount = stack.amount
|
||||
return null
|
||||
|
|
81
scripts/inventory/queue.gd
Normal file
81
scripts/inventory/queue.gd
Normal file
|
@ -0,0 +1,81 @@
|
|||
@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
scripts/inventory/queue.gd.uid
Normal file
1
scripts/inventory/queue.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://q2gbtqfi32d
|
|
@ -21,9 +21,6 @@ class_name Storage
|
|||
|
||||
func _init() -> void:
|
||||
super()
|
||||
deferred_init.call_deferred()
|
||||
|
||||
func deferred_init():
|
||||
internal_array.resize(capacity)
|
||||
for i in range(capacity):
|
||||
internal_array[i] = InventorySlot.new()
|
||||
|
@ -54,20 +51,14 @@ func add(stack: Stack) -> 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(internal_array):
|
||||
return internal_array[i].amount == 0
|
||||
return false
|
||||
else:
|
||||
for i in range(internal_array):
|
||||
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)
|
||||
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,item : Item = null) -> bool:
|
||||
return can_add(item)
|
||||
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:
|
||||
|
@ -78,13 +69,6 @@ func pop() -> Stack:
|
|||
return extracted
|
||||
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
|
||||
func take(item: Item,amount: int) -> Stack:
|
||||
var found = find(item)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
extends Comparable
|
||||
extends Resource
|
||||
|
||||
## Base unit of manipulated objects
|
||||
|
||||
|
@ -14,10 +14,3 @@ class_name Item
|
|||
@export var stack_size : int
|
||||
|
||||
@export var scene : PackedScene
|
||||
|
||||
func is_equal(to: Comparable) -> bool:
|
||||
if to is Item:
|
||||
return to == self
|
||||
elif to is ItemTag:
|
||||
return self in to.items
|
||||
return false
|
||||
|
|
|
@ -17,6 +17,7 @@ func _input(event: InputEvent) -> void:
|
|||
selected_prototype = null
|
||||
|
||||
if event.is_action_pressed("plc_place") and delete_mode:
|
||||
print(delete_mode)
|
||||
var zone : PlacementZone = try_get_zone(global_position)
|
||||
if zone != null and zone.grid_controller.is_point_occupied(global_position):
|
||||
zone.grid_controller.destroy_at(global_position)
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
@abstract
|
||||
extends Resource
|
||||
|
||||
class_name Comparable
|
||||
|
||||
@abstract
|
||||
func is_equal(to: Comparable) -> bool
|
|
@ -1 +0,0 @@
|
|||
uid://bqcyt8qnxvonj
|
|
@ -1,12 +0,0 @@
|
|||
extends Comparable
|
||||
|
||||
class_name ItemTag
|
||||
|
||||
@export var items : Array[Item]
|
||||
|
||||
func is_equal(to: Comparable) -> bool:
|
||||
if to is Item:
|
||||
return to in self.items
|
||||
elif to is ItemTag:
|
||||
return to == self
|
||||
return false
|
|
@ -1 +0,0 @@
|
|||
uid://iasxpubh7f3i
|
|
@ -1,6 +0,0 @@
|
|||
extends Resource
|
||||
|
||||
class_name Recipe
|
||||
|
||||
@export var ingridients : Array[RecipePart]
|
||||
@export var result : RecipePart
|
|
@ -1 +0,0 @@
|
|||
uid://dl0i68ut0lw70
|
|
@ -1,22 +0,0 @@
|
|||
extends Resource
|
||||
|
||||
class_name RecipePart
|
||||
|
||||
@export var item : Comparable
|
||||
@export var amount : int
|
||||
|
||||
func is_stack_sufficient(stack: Stack) -> bool:
|
||||
return item.is_equal(stack.held_item) and stack.amount >= amount
|
||||
|
||||
func consume_stack(stack: Stack) -> bool:
|
||||
if is_stack_sufficient(stack) == false:
|
||||
return false
|
||||
stack.amount -= amount
|
||||
return true
|
||||
|
||||
func create_stack() -> Stack:
|
||||
if item is Item:
|
||||
return Stack.new(item,amount)
|
||||
elif item is ItemTag:
|
||||
return Stack.new(item.items[randi_range(0,len(item.items))],amount)
|
||||
return null
|
|
@ -1 +0,0 @@
|
|||
uid://w4v6jqv1ygqb
|
|
@ -1,5 +0,0 @@
|
|||
extends Node2D
|
||||
|
||||
class_name StructureBehaviour
|
||||
|
||||
@onready var structure_parent : Structure = get_parent()
|
|
@ -1 +0,0 @@
|
|||
uid://iidfsh0lirc2
|
|
@ -1,19 +0,0 @@
|
|||
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 +0,0 @@
|
|||
uid://c7mx3uatj6ulm
|
|
@ -1,6 +1,7 @@
|
|||
extends StructureBehaviour
|
||||
extends Node2D
|
||||
|
||||
@onready var inventory : BeltInventory = structure_parent.inventory
|
||||
@onready var parent_structure : Structure = get_parent()
|
||||
@onready var inventory : BeltInventory = parent_structure.inventory
|
||||
@onready var animator : AnimationPlayer = $"../AnimationPlayer"
|
||||
|
||||
func _ready() -> void:
|
||||
|
@ -13,22 +14,23 @@ func _draw() -> void:
|
|||
for i in range(inventory.capacity):
|
||||
if inventory.internal_array[i].amount > 0:
|
||||
var calculated_position = calculate_position(i) - inventory.internal_array[i].held_item.preview.get_size()/2.0
|
||||
draw_texture(inventory.internal_array[i].held_item.preview,calculated_position)
|
||||
for j in range(inventory.internal_array[i].amount/10):
|
||||
draw_texture(inventory.internal_array[i].held_item.preview,calculated_position + Vector2(0,-j))
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
inventory.advance(delta)
|
||||
queue_redraw()
|
||||
var next : Structure = get_next()
|
||||
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:
|
||||
if next == null or next.inventory == null or next.inventory.can_add_from_side(Globals.facing_difference(next.facing,parent_structure.facing)) == false:
|
||||
return
|
||||
var popped = inventory.pop()
|
||||
if popped == null:
|
||||
return
|
||||
next.inventory.add_from_side(popped,Globals.facing_difference(next.facing,structure_parent.facing))
|
||||
next.inventory.add_from_side(popped,Globals.facing_difference(next.facing,parent_structure.facing))
|
||||
|
||||
func calculate_position(index: int) -> Vector2:
|
||||
var indexed_part = 16.0 / inventory.capacity
|
||||
match structure_parent.facing:
|
||||
match parent_structure.facing:
|
||||
Structure.Facing.RIGHT:
|
||||
return Vector2.LEFT*8 + Vector2.RIGHT * indexed_part * (index + inventory.progress_array[index])
|
||||
Structure.Facing.DOWN:
|
||||
|
@ -40,8 +42,16 @@ func calculate_position(index: int) -> Vector2:
|
|||
return Vector2.ZERO
|
||||
|
||||
func get_next() -> Structure:
|
||||
var faced_vector = Structure.facing_to_vector(structure_parent.facing)
|
||||
return structure_parent.get_relative(faced_vector)
|
||||
match parent_structure.facing:
|
||||
Structure.Facing.RIGHT:
|
||||
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:
|
||||
match to:
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
extends StructureBehaviour
|
||||
extends Node
|
||||
|
||||
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")
|
||||
const test_item :=preload("res://generic/items/dbg_item.tres")
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
try_add(Vector2.UP,Stack.new(inp1,1))
|
||||
try_add(Vector2.DOWN,Stack.new(inp2,1))
|
||||
try_add(Vector2.RIGHT,Stack.new(out,1))
|
||||
|
||||
func try_add(dir: Vector2,stack : Stack):
|
||||
var found = structure_parent.get_relative(dir)
|
||||
if found != null:
|
||||
found.inventory.add(stack)
|
||||
for point in [Vector2(-1,0),Vector2(1,0),Vector2(0,1),Vector2(0,-1)]:
|
||||
var found_structure :Structure = get_parent().get_relative(point)
|
||||
if found_structure and found_structure.inventory:
|
||||
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))
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.5 KiB |
Loading…
Add table
Add a link
Reference in a new issue