This commit is contained in:
Rendo 2025-10-14 21:55:24 +05:00
commit 222960a824
19 changed files with 282 additions and 22 deletions

View 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://dinyjq8853usn" 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 = 999
scene = ExtResource("2_1hrh7")
metadata/_custom_type_script = "uid://p5327ibxtyfs"

View file

@ -0,0 +1,11 @@
[gd_resource type="Resource" script_class="Prototype" load_steps=4 format=3 uid="uid://jhe8wtjoo6c6"]
[ext_resource type="Texture2D" uid="uid://ugbe4qcmgfw0" path="res://icon.svg" id="1_movbu"]
[ext_resource type="PackedScene" uid="uid://cteh8r405wqwk" path="res://scenes/debug_item_deposit.tscn" id="2_wp7ck"]
[ext_resource type="Script" uid="uid://c80sp6f77l5ha" path="res://scripts/prototype.gd" id="3_benq7"]
[resource]
script = ExtResource("3_benq7")
scene = ExtResource("2_wp7ck")
preview = ExtResource("1_movbu")
metadata/_custom_type_script = "uid://c80sp6f77l5ha"

View file

@ -1,11 +1,12 @@
[gd_scene load_steps=10 format=3 uid="uid://u7thalwj5742"]
[gd_scene load_steps=11 format=3 uid="uid://u7thalwj5742"]
[ext_resource type="PackedScene" uid="uid://b7du4vul4bmpq" path="res://scenes/player_platform.tscn" id="1_4ia00"]
[ext_resource type="Script" uid="uid://db37xmo8ygwhg" path="res://scripts/gui/construction_button.gd" id="2_27lod"]
[ext_resource type="Resource" uid="uid://dj524jjal1f0n" path="res://generic/constructibles/conveyor.tres" id="3_2crwe"]
[ext_resource type="Resource" uid="uid://dj524jjal1f0n" path="res://generic/prototypes/conveyor.tres" id="3_2crwe"]
[ext_resource type="Script" uid="uid://b4nkk0ndqcto" path="res://scripts/placement_manager.gd" id="4_i7yte"]
[ext_resource type="PackedScene" uid="uid://bac552xgua68e" path="res://scenes/other_platform.tscn" id="5_mnxrb"]
[ext_resource type="Resource" uid="uid://yn1iesx30nfu" path="res://generic/constructibles/dbg_assembler.tres" id="5_ymyc2"]
[ext_resource type="Resource" uid="uid://yn1iesx30nfu" path="res://generic/prototypes/dbg_assembler.tres" id="5_ymyc2"]
[ext_resource type="Resource" uid="uid://jhe8wtjoo6c6" path="res://generic/prototypes/dbg_item_deposit.tres" id="6_bq5r8"]
[sub_resource type="Animation" id="Animation_bq5r8"]
length = 0.001
@ -85,20 +86,32 @@ constructible = ExtResource("3_2crwe")
[node name="AssemblerButton" type="Button" parent="GUI/Panel"]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.008
anchor_top = 0.086
anchor_right = 0.1
anchor_bottom = 0.88600004
offset_left = 50.904
offset_top = -0.01999998
offset_right = 50.8
offset_bottom = -0.020004272
anchor_left = 0.107421875
anchor_top = 0.08571429
anchor_right = 0.19921875
anchor_bottom = 0.8857143
size_flags_horizontal = 3
theme_type_variation = &"CRT"
icon_alignment = 1
expand_icon = true
script = ExtResource("2_27lod")
constructible = ExtResource("5_ymyc2")
metadata/_edit_use_anchors_ = true
[node name="SpawnerButton" type="Button" parent="GUI/Panel"]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.20898438
anchor_top = 0.08571429
anchor_right = 0.30078125
anchor_bottom = 0.8857143
size_flags_horizontal = 3
theme_type_variation = &"CRT"
icon_alignment = 1
expand_icon = true
script = ExtResource("2_27lod")
constructible = ExtResource("6_bq5r8")
metadata/_edit_use_anchors_ = true
[node name="Placer" type="Node2D" parent="."]
script = ExtResource("4_i7yte")

View file

@ -1,7 +1,17 @@
[gd_scene load_steps=4 format=3 uid="uid://b0h8dd82b3ox5"]
[gd_scene load_steps=8 format=3 uid="uid://b0h8dd82b3ox5"]
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="1_kqxj7"]
[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/structure.gd" id="1_y326v"]
[ext_resource type="Script" uid="uid://bd4ojfqrl8idm" path="res://scripts/inventory/inventory_slot.gd" id="2_54w8r"]
[ext_resource type="Script" uid="uid://v0hkuo3gda1b" path="res://scripts/inventory/conveyor_inventory.gd" id="3_ruvuk"]
[ext_resource type="Script" uid="uid://bp341eiwvfvyl" path="res://scripts/structures/conveyor.gd" id="5_54w8r"]
[sub_resource type="Resource" id="Resource_t4je2"]
resource_local_to_scene = true
script = ExtResource("3_ruvuk")
capacity = 4
pop_treshold = null
metadata/_custom_type_script = "uid://v0hkuo3gda1b"
[sub_resource type="AtlasTexture" id="AtlasTexture_uvy8r"]
atlas = ExtResource("1_kqxj7")
@ -9,6 +19,11 @@ region = Rect2(16, 0, 16, 16)
[node name="Conveyor" type="Node2D" groups=["buildings"]]
script = ExtResource("1_y326v")
inventory = SubResource("Resource_t4je2")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = SubResource("AtlasTexture_uvy8r")
[node name="Conveyor" type="Node2D" parent="."]
z_index = 1
script = ExtResource("5_54w8r")

12
scenes/debug_item.tscn Normal file
View file

@ -0,0 +1,12 @@
[gd_scene load_steps=3 format=3 uid="uid://bbh7akfbskq4u"]
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="1_omb5g"]
[sub_resource type="AtlasTexture" id="AtlasTexture_laovn"]
atlas = ExtResource("1_omb5g")
region = Rect2(0, 0, 5, 5)
[node name="DebugItem" type="Node2D"]
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = SubResource("AtlasTexture_laovn")

View file

@ -0,0 +1,31 @@
[gd_scene load_steps=8 format=3 uid="uid://cteh8r405wqwk"]
[ext_resource type="Script" uid="uid://bbd7o2st8kmgl" path="res://scripts/structure.gd" id="1_uhivg"]
[ext_resource type="Script" uid="uid://bd4ojfqrl8idm" path="res://scripts/inventory/inventory_slot.gd" id="2_0phsd"]
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="2_evk1q"]
[ext_resource type="Script" uid="uid://1scdy7mttx5h" path="res://scripts/inventory/storage.gd" id="3_nh3xp"]
[ext_resource type="Script" uid="uid://v3j1d3qyg30i" path="res://scripts/structures/debug_item_deposit.gd" id="5_nh3xp"]
[sub_resource type="Resource" id="Resource_vi75d"]
resource_local_to_scene = true
script = ExtResource("3_nh3xp")
capacity = 1
internal_array = Array[ExtResource("2_0phsd")]([Object(RefCounted,"script":ExtResource("2_0phsd"),"held_item":null,"amount":0)
])
metadata/_custom_type_script = "uid://1scdy7mttx5h"
[sub_resource type="AtlasTexture" id="AtlasTexture_wxqk4"]
atlas = ExtResource("2_evk1q")
region = Rect2(16, 0, 16, 16)
[node name="DebugItemDeposit" type="Node2D"]
script = ExtResource("1_uhivg")
inventory = SubResource("Resource_vi75d")
metadata/_custom_type_script = "uid://bbd7o2st8kmgl"
[node name="Sprite2D" type="Sprite2D" parent="."]
self_modulate = Color(1, 0, 0, 1)
texture = SubResource("AtlasTexture_wxqk4")
[node name="ItemDeposit" type="Node" parent="."]
script = ExtResource("5_nh3xp")

View file

@ -0,0 +1,87 @@
@tool
extends Inventory
class_name ConveyorInventory
## 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
@export var progress_speed : float = 1.0
@export var pop_treshold : float = 0.95
## :3
@export_storage var internal_array : Array[InventorySlot] = []
@export_storage var progress_array : Array[float] = []
func _init() -> void:
super()
deferred_init.call_deferred()
func deferred_init():
internal_array.resize(capacity)
progress_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(capacity):
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:
if internal_array[0].amount != 0:
return null
stack_added.emit(stack,0)
return internal_array[0].merge_stack(stack)
func can_add() -> bool:
return internal_array[0].amount == 0
## Tries to take first item. Returns null if no items in inventory
func pop() -> Stack:
if internal_array[capacity-1].amount == 0:
return null
if progress_array[capacity-1] < pop_treshold:
return null
stack_taken.emit(internal_array[capacity-1], capacity-1)
return internal_array[capacity-1].extract()
func advance(delta : float) -> void:
var progress_flag : bool = false
for i in range(capacity):
if internal_array[i].amount == 0:
continue
if progress_array[i] >= 1:
progress_flag = true
continue
progress_array[i] += delta * progress_speed
if progress_flag:
sort()
## 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 = internal_array[found].extract_stack(amount)
stack_taken.emit(extracted,found)
return extracted
func sort() -> void:
for i in range(capacity-1,0,-1):
if progress_array[i-1] >= 1.0 and internal_array[i].amount == 0:
progress_array[i-1] = 0
progress_array[i] = 0
internal_array[i].merge_stack(internal_array[i-1].extract())

View file

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

View file

@ -4,12 +4,19 @@ extends Resource
## Class that can hold items in it
class_name Inventory
signal stack_added(item : Stack,position : int)
signal stack_taken(item : Stack,position : int)
func _init() -> void:
resource_local_to_scene = true
## Tries to add an item into inventory. Returns not stored stack of item.
@abstract
func add(item : Stack) -> Stack
func add(stack : Stack) -> Stack
## Returns if conditions of adding are met
@abstract
func can_add() -> bool
## Tries to take first item. Returns null if no items in inventory
@abstract

View file

@ -14,15 +14,19 @@ class_name Queue
if value == capacity:
return
capacity = value
internal_array.resize(capacity)
for i in range(capacity):
internal_array[i] = InventorySlot.new()
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)):
@ -34,16 +38,24 @@ func find(item : Item) -> int:
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 can_add() -> bool:
for i in range(capacity):
if internal_array[i].amount == 0:
return true
return false
## 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
@ -53,6 +65,7 @@ func take(item: Item,amount: int) -> Stack:
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

View file

@ -13,15 +13,18 @@ class_name Storage
if value == capacity:
return
capacity = value
internal_array.resize(capacity)
for i in range(capacity):
internal_array[i] = InventorySlot.new()
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)):
@ -33,21 +36,31 @@ func find(item : Item) -> int:
func add(stack: Stack) -> Stack:
var found_index : int = find(stack.held_item)
if found_index != -1:
stack_added.emit(stack,found_index)
stack = internal_array[found_index].merge_stack(stack)
if stack == null:
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:
stack_added.emit(stack,i)
stack = internal_array[i].merge_stack(stack)
if stack == null:
return null
return stack
func can_add() -> bool:
for i in range(capacity):
if internal_array[i].amount == 0:
return true
return false
## Tries to take first item. Returns null if no items in inventory
func pop() -> Stack:
for i in range(len(internal_array)):
if internal_array[i].held_item != null:
return internal_array[i].extract()
var extracted = internal_array[i].extract()
stack_taken.emit(extracted,i)
return extracted
return null
## Tries to take certain item from inventory. Returns null if no item found
@ -55,4 +68,6 @@ func take(item: Item,amount: int) -> Stack:
var found = find(item)
if found == -1:
return null
return internal_array[found].extract_stack(amount)
var extracted = internal_array[found].extract_stack(amount)
stack_taken.emit(extracted,found)
return extracted

View file

@ -12,3 +12,5 @@ class_name Item
## Maximum amount of items that can be held in inventory
@export var stack_size : int
@export var scene : PackedScene

View file

@ -13,6 +13,9 @@ class_name Structure
get:
return dimensions
## Inventory of this structure
@export var inventory : Inventory
## Debug draw of points
func _draw() -> void:
if Engine.is_editor_hint():
@ -23,7 +26,9 @@ func _draw() -> void:
## Get structure at tile coordinates relative to this structure [br]
## dv : Vector2 - get position in tiles [br]
func get_relative(dv : Vector2) -> Structure:
return get_parent().get_at(global_position+dv*Globals.GRID_SIZE)
if get_parent() is GridController:
return get_parent().get_at(global_position+dv*Globals.GRID_SIZE)
return null
## Check structure is in zone and does not collide with any other structures [br]
## Returns true if structure is in zone and does not collide with any other structure [br]

View file

@ -0,0 +1,20 @@
extends Node2D
@onready var inventory : ConveyorInventory = get_parent().inventory
func _draw() -> void:
for i in range(inventory.capacity):
if inventory.internal_array[i].amount > 0:
var calculated_position = Vector2(-8,0)+Vector2(16/inventory.capacity*i+16/inventory.capacity*inventory.progress_array[i],0)
draw_texture(inventory.internal_array[i].held_item.preview,calculated_position - inventory.internal_array[i].held_item.preview.get_size()/2.0)
func _process(delta: float) -> void:
inventory.advance(delta)
queue_redraw()
var right : Structure = get_parent().get_relative(Vector2.RIGHT)
if right == null or right.inventory.can_add() == false:
return
var popped = inventory.pop()
if popped == null:
return
right.inventory.add(popped)

View file

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

View file

@ -0,0 +1,9 @@
extends Node
const test_item :=preload("res://generic/items/dbg_item.tres")
func _process(_delta: float) -> void:
for point in [Vector2(-1,0),Vector2(1,0),Vector2(0,1),Vector2(0,-1)]:
var found_structure = get_parent().get_relative(point)
if found_structure:
found_structure.inventory.add(Stack.new(test_item,1))

View file

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