Splitters part 1

This commit is contained in:
Rendo 2025-10-16 23:29:49 +05:00
commit 3c0777f4fd
9 changed files with 150 additions and 2 deletions

View file

@ -0,0 +1,15 @@
extends Node
@export var structure : Structure
@export var sprite : Sprite2D
@onready var initial_dimensions : Rect2i = structure.dimensions
@onready var initial_offset : Vector2 = sprite.offset
func _ready() -> void:
structure.changed_direction.connect(on_changed_direction)
func on_changed_direction(to: float,max_directions : int):
var calculated_size = Vector2(initial_dimensions.size).rotated(to).abs().ceil()
structure.dimensions = Rect2i(initial_dimensions.position,calculated_size)
sprite.offset = initial_offset.rotated(to).abs()

View file

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

View file

@ -2,6 +2,8 @@
extends Inventory
class_name SplitterInventory
@export var capacity : int:
set(value):
if value < 0:
@ -25,3 +27,48 @@ func deferred_init():
for i in range(capacity):
upper_array[i] = InventorySlot.new()
down_array[i] = InventorySlot.new()
func add(stack : Stack, context: InventoryContext = null) -> Stack:
if context == null:
return stack
if context.position == context.target.global_position:
return add_to_array(stack,upper_array,context)
return add_to_array(stack,down_array,context)
func add_to_array(stack: Stack, array: Array[InventorySlot], context: InventoryContext = null) -> Stack:
for i in range(len(array)):
if array[i].held_item == null or array[i].held_item == stack.held_item:
stack_added.emit(stack,i)
array[i].merge_stack(stack)
if stack.is_valid() == false:
return null
return stack
func can_add(item : Item = null, context: InventoryContext = null) -> bool:
if context == null:
return false
if item == null:
for i in range(capacity):
if upper_array[i].amount == 0 or down_array[i].amount == 0:
return true
else:
for i in range(capacity):
if upper_array[i].amount == 0:
return upper_array[i].can_be_merged(item)
if down_array[i].amount ==0:
return down_array[i].can_be_merged(item)
return false
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