diff --git a/scenes/debug_item_deposit.tscn b/scenes/debug_item_deposit.tscn index 5272d2b..112e6ba 100644 --- a/scenes/debug_item_deposit.tscn +++ b/scenes/debug_item_deposit.tscn @@ -1,26 +1,15 @@ -[gd_scene load_steps=8 format=3 uid="uid://cteh8r405wqwk"] +[gd_scene load_steps=5 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="Texture2D" uid="uid://gfkhedfdi7ug" path="res://sprites/atlasses/Popekko.png" id="2_evk1q"] [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="."] diff --git a/scripts/inventory/conveyor_inventory.gd b/scripts/inventory/conveyor_inventory.gd index dcb21d2..0b2a71b 100644 --- a/scripts/inventory/conveyor_inventory.gd +++ b/scripts/inventory/conveyor_inventory.gd @@ -46,19 +46,26 @@ func add(stack: Stack) -> Stack: return internal_array[0].merge_stack(stack) func add_from_side(stack : Stack, ang_diff : float) -> Stack: - if abs(ang_diff) >= PI/4: + if is_equal_approx(abs(ang_diff),PI/2): if internal_array[capacity/2].amount != 0: return null stack_added.emit(stack,capacity/2) return internal_array[capacity/2].merge_stack(stack) + elif is_equal_approx(abs(ang_diff), PI): + if internal_array[capacity-1].amount != 0: + return null + stack_added.emit(stack,capacity-1) + return internal_array[capacity-1].merge_stack(stack) return add(stack) func can_add() -> bool: return internal_array[0].amount == 0 func can_add_from_side(ang_diff : float) -> bool: - if abs(ang_diff) >= PI/4: + 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() ## Tries to take first item. Returns null if no items in inventory diff --git a/scripts/placement_manager.gd b/scripts/placement_manager.gd index 6166700..4281d46 100644 --- a/scripts/placement_manager.gd +++ b/scripts/placement_manager.gd @@ -2,6 +2,7 @@ extends Node2D ## Currently held structure var held_construction : Structure +var selected_prototype : Prototype func _ready() -> void: GuiEventBus.construction_selected.connect(on_construction_selected) @@ -11,23 +12,25 @@ func _input(event: InputEvent) -> void: return if event.is_action_pressed("plc_place"): var zone = try_get_zone(held_construction.global_position) - if zone == null: - held_construction.queue_free() - else: - if held_construction.try_place(zone): - held_construction = null + if zone != null and held_construction.try_place(zone): + var facing = held_construction.facing + held_construction = selected_prototype.scene.instantiate() + add_child(held_construction) + held_construction.set_facing(facing) if event.is_action_pressed("plc_rotate_up"): if held_construction != null: held_construction.cycle_up_facing() if event.is_action_pressed("plc_cancel"): held_construction.queue_free() + selected_prototype = null func on_construction_selected(constructible : Prototype): if held_construction: held_construction.queue_free() held_construction = constructible.scene.instantiate() add_child(held_construction) + selected_prototype = constructible func _process(_delta: float) -> void: diff --git a/scripts/structure.gd b/scripts/structure.gd index d13fa7d..e512e68 100644 --- a/scripts/structure.gd +++ b/scripts/structure.gd @@ -83,8 +83,16 @@ func get_dimension_points() -> Array[Vector2]: result[x + y * dimensions.size.x] = (Vector2(x,y)*Globals.GRID_SIZE + Vector2(dimensions.position)) return result +func set_facing(to : Facing) -> void: + facing = to + switched_facing.emit(facing) + func cycle_up_facing() -> void: if facing == Facing.UNDIRECTIONAL: return - facing = wrapi(facing+1,1,5) as Facing - switched_facing.emit(facing) + set_facing(wrapi(facing+1,1,5)) + +func cycle_down_facing() -> void: + if facing == Facing.UNDIRECTIONAL: + return + set_facing(wrapi(facing-1,1,5)) diff --git a/scripts/structures/debug_item_deposit.gd b/scripts/structures/debug_item_deposit.gd index 34f2330..e2beb37 100644 --- a/scripts/structures/debug_item_deposit.gd +++ b/scripts/structures/debug_item_deposit.gd @@ -5,5 +5,5 @@ 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: + if found_structure and found_structure.inventory: found_structure.inventory.add(Stack.new(test_item,1))