rotation rework, deletion of complex objects
This commit is contained in:
parent
609b1b976d
commit
8dcd7725a9
15 changed files with 103 additions and 147 deletions
|
@ -1,7 +1,6 @@
|
|||
extends StructureBehaviour
|
||||
|
||||
@export var selected_recipe : Recipe
|
||||
@onready var inventory : InOutInventory = get_parent().inventory
|
||||
|
||||
func _ready() -> void:
|
||||
inventory.stack_added.connect(check_for_recipe)
|
||||
|
@ -23,13 +22,12 @@ func _process(_delta: float) -> void:
|
|||
var output : Structure = get_output_structure()
|
||||
if output == null:
|
||||
return
|
||||
var ang_diff = Globals.facing_difference(output.facing,structure_parent.facing)
|
||||
var ang_diff = output.direction_difference(structure_parent)
|
||||
if output.inventory.can_add_from_side(ang_diff):
|
||||
inventory.output_slot.merge_stack(output.inventory.add_from_side(inventory.output_slot.extract(),ang_diff))
|
||||
|
||||
func get_output_structure() -> Structure:
|
||||
var facing_direction = Structure.facing_to_vector(structure_parent.facing)
|
||||
var rotated = Vector2(0.5,1.5).rotated(-Vector2.DOWN.angle_to(facing_direction))
|
||||
var rotated = Vector2(1.5,-0.5).rotated(structure_parent.direction)
|
||||
return structure_parent.get_relative(rotated+Vector2(0.5,0.5))
|
||||
|
||||
func check_for_recipe(_stack : Stack, _position : int) -> void:
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
extends StructureBehaviour
|
||||
|
||||
@onready var inventory : BeltInventory = structure_parent.inventory
|
||||
@onready var animator : AnimationPlayer = $"../AnimationPlayer"
|
||||
|
||||
func _ready() -> void:
|
||||
sync_animations.call_deferred()
|
||||
|
||||
func sync_animations() -> void:
|
||||
animator.seek(BeltManager.sync_time,true)
|
||||
|
||||
func _draw() -> void:
|
||||
for i in range(inventory.capacity):
|
||||
if inventory.internal_array[i].amount > 0:
|
||||
|
@ -23,41 +16,20 @@ func _process(delta: float) -> void:
|
|||
|
||||
func calculate_position(index: int) -> Vector2:
|
||||
var indexed_part = 16.0 / inventory.capacity
|
||||
match structure_parent.facing:
|
||||
Structure.Facing.RIGHT:
|
||||
return Vector2.LEFT*8 + Vector2.RIGHT * indexed_part * (index + inventory.progress_array[index])
|
||||
Structure.Facing.DOWN:
|
||||
return Vector2.UP*8 + Vector2.DOWN * indexed_part * (index + inventory.progress_array[index])
|
||||
Structure.Facing.LEFT:
|
||||
return Vector2.RIGHT*8 + Vector2.LEFT * indexed_part * (index + inventory.progress_array[index])
|
||||
Structure.Facing.UP:
|
||||
return Vector2.DOWN*8 + Vector2.UP * indexed_part * (index + inventory.progress_array[index])
|
||||
return Vector2.ZERO
|
||||
|
||||
return -structure_parent.direction_vector()*8 + structure_parent.direction_vector() * indexed_part * (index + inventory.progress_array[index])
|
||||
|
||||
func get_next() -> Structure:
|
||||
var faced_vector = Structure.facing_to_vector(structure_parent.facing)
|
||||
return structure_parent.get_relative(faced_vector)
|
||||
return structure_parent.get_relative(structure_parent.direction_vector())
|
||||
|
||||
func try_transfer(structure : Structure) -> void:
|
||||
if structure == null or inventory.internal_array[inventory.capacity-1].amount == 0:
|
||||
return
|
||||
var last_slot = inventory.internal_array[inventory.capacity-1]
|
||||
var ang_diff = Globals.facing_difference(structure_parent.facing,structure.facing)
|
||||
var ang_diff = structure_parent.direction_difference(structure)
|
||||
if structure.inventory.can_add_from_side(ang_diff,last_slot.held_item) == false:
|
||||
return
|
||||
last_slot.merge_stack(structure.inventory.add_from_side(last_slot.extract(),ang_diff))
|
||||
|
||||
if last_slot.amount == 0:
|
||||
inventory.sort()
|
||||
|
||||
func _on_conveyor_switched_facing(to: Structure.Facing) -> void:
|
||||
match to:
|
||||
Structure.Facing.RIGHT:
|
||||
animator.play("right")
|
||||
Structure.Facing.DOWN:
|
||||
animator.play("down")
|
||||
Structure.Facing.LEFT:
|
||||
animator.play("left")
|
||||
Structure.Facing.UP:
|
||||
animator.play("up")
|
||||
sync_animations()
|
||||
|
|
4
scripts/structures/belt_animation_sync.gd
Normal file
4
scripts/structures/belt_animation_sync.gd
Normal file
|
@ -0,0 +1,4 @@
|
|||
extends AnimationPlayer
|
||||
|
||||
func _ready() -> void:
|
||||
seek.call_deferred(BeltManager.sync_time, true)
|
1
scripts/structures/belt_animation_sync.gd.uid
Normal file
1
scripts/structures/belt_animation_sync.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://drsty3i1820ha
|
12
scripts/structures/directional_sprite.gd
Normal file
12
scripts/structures/directional_sprite.gd
Normal file
|
@ -0,0 +1,12 @@
|
|||
extends Sprite2D
|
||||
|
||||
@export var textures : Array[Texture]
|
||||
@export var structure : Structure
|
||||
|
||||
func _ready() -> void:
|
||||
structure.changed_direction.connect(on_direction_changed)
|
||||
|
||||
func on_direction_changed(to: float, max_directions: int) -> void:
|
||||
var indexed_direction = to*max_directions/TAU
|
||||
|
||||
texture = textures[indexed_direction]
|
1
scripts/structures/directional_sprite.gd.uid
Normal file
1
scripts/structures/directional_sprite.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://lchhqigib2t0
|
Loading…
Add table
Add a link
Reference in a new issue