rotation rework, deletion of complex objects
This commit is contained in:
parent
609b1b976d
commit
8dcd7725a9
15 changed files with 103 additions and 147 deletions
|
@ -6,7 +6,7 @@
|
|||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_kf3x0"]
|
||||
atlas = ExtResource("1_sh8t1")
|
||||
region = Rect2(32, 0, 32, 32)
|
||||
region = Rect2(48, 0, 32, 32)
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_mqcr0")
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
[gd_scene load_steps=14 format=3 uid="uid://b0h8dd82b3ox5"]
|
||||
[gd_scene load_steps=16 format=3 uid="uid://b0h8dd82b3ox5"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://gfkhedfdi7ug" 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/belt_inventory.gd" id="3_ruvuk"]
|
||||
[ext_resource type="Script" uid="uid://bp341eiwvfvyl" path="res://scripts/structures/belt.gd" id="5_54w8r"]
|
||||
[ext_resource type="Script" uid="uid://lchhqigib2t0" path="res://scripts/structures/directional_sprite.gd" id="5_ruvuk"]
|
||||
[ext_resource type="Script" uid="uid://drsty3i1820ha" path="res://scripts/structures/belt_animation_sync.gd" id="7_t4je2"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_t4je2"]
|
||||
resource_local_to_scene = true
|
||||
|
@ -21,7 +23,19 @@ metadata/_custom_type_script = "uid://v0hkuo3gda1b"
|
|||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_54w8r"]
|
||||
atlas = ExtResource("1_kqxj7")
|
||||
region = Rect2(16, 0, 16, 128)
|
||||
region = Rect2(16, 0, 16, 64)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_crbfm"]
|
||||
atlas = ExtResource("1_kqxj7")
|
||||
region = Rect2(32, 64, 16, 64)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_t4je2"]
|
||||
atlas = ExtResource("1_kqxj7")
|
||||
region = Rect2(32, 0, 16, 64)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ruvuk"]
|
||||
atlas = ExtResource("1_kqxj7")
|
||||
region = Rect2(16, 64, 16, 64)
|
||||
|
||||
[sub_resource type="Animation" id="Animation_ruvuk"]
|
||||
length = 0.001
|
||||
|
@ -38,41 +52,6 @@ tracks/0/keys = {
|
|||
"values": [0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_1rfp0"]
|
||||
resource_name = "down"
|
||||
loop_mode = 1
|
||||
step = 0.25
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.25, 0.5, 0.75),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [7, 6, 5, 4]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_t4je2"]
|
||||
resource_name = "left"
|
||||
length = 1.000025
|
||||
loop_mode = 1
|
||||
step = 0.25
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.25, 0.5, 0.75),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [3, 2, 1, 0]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_54w8r"]
|
||||
resource_name = "right"
|
||||
length = 1.000025
|
||||
|
@ -91,40 +70,24 @@ tracks/0/keys = {
|
|||
"values": [0, 1, 2, 3]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_crbfm"]
|
||||
resource_name = "up"
|
||||
loop_mode = 1
|
||||
step = 0.25
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.25, 0.5, 0.75),
|
||||
"transitions": PackedFloat32Array(1, 1, 1, 1),
|
||||
"update": 1,
|
||||
"values": [4, 5, 6, 7]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_crbfm"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_ruvuk"),
|
||||
&"down": SubResource("Animation_1rfp0"),
|
||||
&"left": SubResource("Animation_t4je2"),
|
||||
&"right": SubResource("Animation_54w8r"),
|
||||
&"up": SubResource("Animation_crbfm")
|
||||
&"right": SubResource("Animation_54w8r")
|
||||
}
|
||||
|
||||
[node name="Conveyor" type="Node2D" groups=["buildings"]]
|
||||
script = ExtResource("1_y326v")
|
||||
inventory = SubResource("Resource_t4je2")
|
||||
facing = 1
|
||||
direction = null
|
||||
maximum_directions = 4
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." node_paths=PackedStringArray("structure")]
|
||||
texture = SubResource("AtlasTexture_54w8r")
|
||||
vframes = 8
|
||||
vframes = 4
|
||||
script = ExtResource("5_ruvuk")
|
||||
textures = Array[Texture]([SubResource("AtlasTexture_54w8r"), SubResource("AtlasTexture_crbfm"), SubResource("AtlasTexture_t4je2"), SubResource("AtlasTexture_ruvuk")])
|
||||
structure = NodePath("..")
|
||||
|
||||
[node name="Conveyor" type="Node2D" parent="."]
|
||||
z_index = 1
|
||||
|
@ -135,5 +98,4 @@ libraries = {
|
|||
&"": SubResource("AnimationLibrary_crbfm")
|
||||
}
|
||||
autoplay = "right"
|
||||
|
||||
[connection signal="switched_facing" from="." to="Conveyor" method="_on_conveyor_switched_facing"]
|
||||
script = ExtResource("7_t4je2")
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://dfatkxv6n55dw"]
|
||||
[gd_scene load_steps=13 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="Script" uid="uid://lchhqigib2t0" path="res://scripts/structures/directional_sprite.gd" id="5_kno0u"]
|
||||
[ext_resource type="Resource" uid="uid://d2lbc1qqkayaa" path="res://generic/recipes/test_recipe.tres" id="6_wqoim"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_kno0u"]
|
||||
|
@ -21,17 +22,33 @@ metadata/_custom_type_script = "uid://m6b6vawdqgqb"
|
|||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_xh4eg"]
|
||||
atlas = ExtResource("2_4befw")
|
||||
region = Rect2(32, 0, 32, 32)
|
||||
region = Rect2(48, 0, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_0x00x"]
|
||||
atlas = ExtResource("2_4befw")
|
||||
region = Rect2(48, 32, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_dr8in"]
|
||||
atlas = ExtResource("2_4befw")
|
||||
region = Rect2(48, 96, 32, 32)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_kno0u"]
|
||||
atlas = ExtResource("2_4befw")
|
||||
region = Rect2(48, 64, 32, 32)
|
||||
|
||||
[node name="DebugAssembler" type="Node2D"]
|
||||
script = ExtResource("1_k5y3y")
|
||||
dimensions = Rect2i(0, 0, 2, 2)
|
||||
inventory = SubResource("Resource_kno0u")
|
||||
facing = 2
|
||||
direction = 1.571
|
||||
maximum_directions = 4
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." node_paths=PackedStringArray("structure")]
|
||||
texture = SubResource("AtlasTexture_xh4eg")
|
||||
offset = Vector2(8, 8)
|
||||
script = ExtResource("5_kno0u")
|
||||
textures = Array[Texture]([SubResource("AtlasTexture_0x00x"), SubResource("AtlasTexture_xh4eg"), SubResource("AtlasTexture_dr8in"), SubResource("AtlasTexture_kno0u")])
|
||||
structure = NodePath("..")
|
||||
|
||||
[node name="Assembler" type="Node2D" parent="."]
|
||||
position = Vector2(16, 16)
|
||||
|
|
|
@ -11,6 +11,3 @@ enum Sides {
|
|||
LEFT,
|
||||
UP
|
||||
}
|
||||
|
||||
static func facing_difference(from : Structure.Facing, to : Structure.Facing) -> float:
|
||||
return Structure.facing_to_vector(from).angle_to(Structure.facing_to_vector(to))
|
||||
|
|
|
@ -42,8 +42,13 @@ func destroy_at(point : Vector2) -> void:
|
|||
var index = building_zone.indexify_global_point(point)
|
||||
if index == -1:
|
||||
return
|
||||
structures[index].queue_free()
|
||||
structures[index] = null
|
||||
|
||||
var found: Structure = structures[index]
|
||||
|
||||
for dim_point in found.get_dimension_points():
|
||||
structures[building_zone.indexify_global_point(found.global_position+dim_point)] = null
|
||||
|
||||
found.queue_free()
|
||||
|
||||
func is_point_occupied(point : Vector2) -> bool:
|
||||
return get_at(point) != null
|
||||
|
|
|
@ -30,18 +30,18 @@ func _input(event: InputEvent) -> void:
|
|||
if event.is_action_pressed("plc_place"):
|
||||
var zone = try_get_zone(held_construction.global_position)
|
||||
if zone != null and held_construction.try_place(zone):
|
||||
var facing = held_construction.facing
|
||||
var direction = held_construction.direction
|
||||
held_construction = selected_prototype.scene.instantiate()
|
||||
add_child(held_construction)
|
||||
held_construction.set_facing(facing)
|
||||
held_construction.set_direction(direction)
|
||||
|
||||
if event.is_action_pressed("plc_rotate_up"):
|
||||
if held_construction != null:
|
||||
held_construction.cycle_up_facing()
|
||||
held_construction.increment_direction()
|
||||
|
||||
if event.is_action_pressed("plc_rotate_down"):
|
||||
if held_construction != null:
|
||||
held_construction.cycle_down_facing()
|
||||
held_construction.decrement_direction()
|
||||
|
||||
if event.is_action_pressed("plc_cancel"):
|
||||
held_construction.queue_free()
|
||||
|
|
|
@ -4,15 +4,7 @@ extends Node2D
|
|||
## Game object that interact with other structures in its grid space
|
||||
class_name Structure
|
||||
|
||||
enum Facing {
|
||||
UNDIRECTIONAL = 0,
|
||||
RIGHT = 1,
|
||||
DOWN = 2,
|
||||
LEFT = 3,
|
||||
UP = 4
|
||||
}
|
||||
|
||||
signal switched_facing(to: Facing)
|
||||
signal changed_direction(to: float,max_directions : int)
|
||||
|
||||
## Dimensions of structure in grid tiles
|
||||
@export var dimensions : Rect2i = Rect2i(0,0,1,1):
|
||||
|
@ -25,20 +17,8 @@ signal switched_facing(to: Facing)
|
|||
|
||||
## Inventory of this structure
|
||||
@export var inventory : Inventory
|
||||
@export var facing : Facing
|
||||
|
||||
static func facing_to_vector(face : Facing) -> Vector2:
|
||||
match face:
|
||||
Facing.RIGHT:
|
||||
return Vector2.RIGHT
|
||||
Facing.LEFT:
|
||||
return Vector2.LEFT
|
||||
Facing.UP:
|
||||
return Vector2.UP
|
||||
Facing.DOWN:
|
||||
return Vector2.DOWN
|
||||
_:
|
||||
return Vector2.ZERO
|
||||
@export var direction : float
|
||||
@export var maximum_directions : int
|
||||
|
||||
## Debug draw of points
|
||||
func _draw() -> void:
|
||||
|
@ -83,16 +63,21 @@ 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 set_direction(to : float) -> void:
|
||||
direction = to
|
||||
changed_direction.emit(direction,maximum_directions)
|
||||
|
||||
func cycle_up_facing() -> void:
|
||||
if facing == Facing.UNDIRECTIONAL:
|
||||
return
|
||||
set_facing(wrapi(facing+1,1,5))
|
||||
func increment_direction() -> void:
|
||||
set_direction(wrapf(direction + TAU/maximum_directions,0,TAU))
|
||||
|
||||
func cycle_down_facing() -> void:
|
||||
if facing == Facing.UNDIRECTIONAL:
|
||||
return
|
||||
set_facing(wrapi(facing-1,1,5))
|
||||
func decrement_direction() -> void:
|
||||
set_direction(wrapf(direction - TAU/maximum_directions,0,TAU))
|
||||
|
||||
func direction_vector() -> Vector2:
|
||||
return Vector2.from_angle(direction)
|
||||
|
||||
func direction_to(structure: Structure):
|
||||
return (structure.global_position-global_position).angle()
|
||||
|
||||
func direction_difference(structure: Structure):
|
||||
return direction-structure.direction
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
@abstract
|
||||
extends Node2D
|
||||
|
||||
class_name StructureBehaviour
|
||||
|
||||
@onready var structure_parent : Structure = get_parent()
|
||||
@onready var inventory : Inventory = structure_parent.inventory
|
||||
|
|
|
@ -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
|
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.3 KiB |
Loading…
Add table
Add a link
Reference in a new issue