Conveyor sideloading
This commit is contained in:
parent
222960a824
commit
81451bd356
14 changed files with 243 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
|||
[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="Texture2D" uid="uid://gfkhedfdi7ug" 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"]
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[gd_resource type="Resource" script_class="Prototype" load_steps=5 format=3 uid="uid://dj524jjal1f0n"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c80sp6f77l5ha" path="res://scripts/prototype.gd" id="1_53h7j"]
|
||||
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="1_x27pp"]
|
||||
[ext_resource type="Texture2D" uid="uid://gfkhedfdi7ug" path="res://sprites/atlasses/Popekko.png" id="1_x27pp"]
|
||||
[ext_resource type="PackedScene" uid="uid://b0h8dd82b3ox5" path="res://scenes/conveyor.tscn" id="2_hinjf"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_uvy8r"]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[gd_resource type="Resource" script_class="Prototype" load_steps=5 format=3 uid="uid://yn1iesx30nfu"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c80sp6f77l5ha" path="res://scripts/prototype.gd" id="1_mqcr0"]
|
||||
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="1_sh8t1"]
|
||||
[ext_resource type="Texture2D" uid="uid://gfkhedfdi7ug" path="res://sprites/atlasses/Popekko.png" id="1_sh8t1"]
|
||||
[ext_resource type="PackedScene" uid="uid://dfatkxv6n55dw" path="res://scenes/debug_assembler.tscn" id="2_kf3x0"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_kf3x0"]
|
||||
|
|
|
@ -20,6 +20,7 @@ config/icon="res://icon.svg"
|
|||
GuiEventBus="*res://scripts/gui/gui_event_bus.gd"
|
||||
RuntimePlayerData="*res://scripts/autoloads/runtime_player_data.gd"
|
||||
Registry="*res://scripts/autoloads/registry.gd"
|
||||
ConveyorManager="*res://scripts/autoloads/conveyor_manager.gd"
|
||||
|
||||
[display]
|
||||
|
||||
|
@ -43,6 +44,12 @@ plc_cancel={
|
|||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(441.39453, 21.890625),"global_position":Vector2(445.39453, 58.890625),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
plc_rotate_up={
|
||||
"deadzone": 1.0,
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":8,"position":Vector2(85.30078, 15.171875),"global_position":Vector2(89.30078, 52.171875),"factor":1.0,"button_index":4,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://b0h8dd82b3ox5"]
|
||||
[gd_scene load_steps=14 format=3 uid="uid://b0h8dd82b3ox5"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dinyjq8853usn" path="res://sprites/atlasses/Popekko.png" id="1_kqxj7"]
|
||||
[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/conveyor_inventory.gd" id="3_ruvuk"]
|
||||
|
@ -10,20 +10,129 @@
|
|||
resource_local_to_scene = true
|
||||
script = ExtResource("3_ruvuk")
|
||||
capacity = 4
|
||||
pop_treshold = null
|
||||
internal_array = Array[ExtResource("2_54w8r")]([Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
||||
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
||||
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
||||
, Object(RefCounted,"script":ExtResource("2_54w8r"),"held_item":null,"amount":0)
|
||||
])
|
||||
progress_array = Array[float]([0.0, 0.0, 0.0, 0.0])
|
||||
metadata/_custom_type_script = "uid://v0hkuo3gda1b"
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_uvy8r"]
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_54w8r"]
|
||||
atlas = ExtResource("1_kqxj7")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
region = Rect2(16, 0, 16, 128)
|
||||
|
||||
[sub_resource type="Animation" id="Animation_ruvuk"]
|
||||
length = 0.001
|
||||
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),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"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
|
||||
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": [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")
|
||||
}
|
||||
|
||||
[node name="Conveyor" type="Node2D" groups=["buildings"]]
|
||||
script = ExtResource("1_y326v")
|
||||
inventory = SubResource("Resource_t4je2")
|
||||
facing = 1
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("AtlasTexture_uvy8r")
|
||||
texture = SubResource("AtlasTexture_54w8r")
|
||||
vframes = 8
|
||||
|
||||
[node name="Conveyor" type="Node2D" parent="."]
|
||||
z_index = 1
|
||||
script = ExtResource("5_54w8r")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_crbfm")
|
||||
}
|
||||
autoplay = "right"
|
||||
|
||||
[connection signal="switched_facing" from="." to="Conveyor" method="_on_conveyor_switched_facing"]
|
||||
|
|
8
scripts/autoloads/conveyor_manager.gd
Normal file
8
scripts/autoloads/conveyor_manager.gd
Normal file
|
@ -0,0 +1,8 @@
|
|||
extends Node
|
||||
|
||||
# TODO: Use this autoload for conveyor optimizations
|
||||
|
||||
var sync_time : float
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
sync_time = fposmod(sync_time+delta,1)
|
1
scripts/autoloads/conveyor_manager.gd.uid
Normal file
1
scripts/autoloads/conveyor_manager.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://damurnhtipmga
|
|
@ -4,3 +4,13 @@ extends Object
|
|||
class_name Globals
|
||||
|
||||
const GRID_SIZE : Vector2 = Vector2(16,16)
|
||||
|
||||
enum Sides {
|
||||
RIGHT,
|
||||
DOWN,
|
||||
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))
|
||||
|
|
|
@ -45,9 +45,22 @@ func add(stack: Stack) -> Stack:
|
|||
stack_added.emit(stack,0)
|
||||
return internal_array[0].merge_stack(stack)
|
||||
|
||||
func add_from_side(stack : Stack, ang_diff : float) -> Stack:
|
||||
if abs(ang_diff) >= PI/4:
|
||||
if internal_array[capacity/2].amount != 0:
|
||||
return null
|
||||
stack_added.emit(stack,capacity/2)
|
||||
return internal_array[capacity/2].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:
|
||||
return internal_array[capacity/2].amount == 0
|
||||
return can_add()
|
||||
|
||||
## Tries to take first item. Returns null if no items in inventory
|
||||
func pop() -> Stack:
|
||||
if internal_array[capacity-1].amount == 0:
|
||||
|
|
|
@ -16,7 +16,10 @@ func _input(event: InputEvent) -> void:
|
|||
else:
|
||||
if held_construction.try_place(zone):
|
||||
held_construction = null
|
||||
|
||||
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()
|
||||
|
||||
|
|
|
@ -4,6 +4,16 @@ 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)
|
||||
|
||||
## Dimensions of structure in grid tiles
|
||||
@export var dimensions : Rect2i = Rect2i(0,0,1,1):
|
||||
set(value):
|
||||
|
@ -15,6 +25,20 @@ class_name Structure
|
|||
|
||||
## 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
|
||||
|
||||
## Debug draw of points
|
||||
func _draw() -> void:
|
||||
|
@ -58,3 +82,9 @@ func get_dimension_points() -> Array[Vector2]:
|
|||
for y in range(dimensions.size.y):
|
||||
result[x + y * dimensions.size.x] = (Vector2(x,y)*Globals.GRID_SIZE + Vector2(dimensions.position))
|
||||
return result
|
||||
|
||||
func cycle_up_facing() -> void:
|
||||
if facing == Facing.UNDIRECTIONAL:
|
||||
return
|
||||
facing = wrapi(facing+1,1,5) as Facing
|
||||
switched_facing.emit(facing)
|
||||
|
|
|
@ -1,20 +1,65 @@
|
|||
extends Node2D
|
||||
|
||||
@onready var inventory : ConveyorInventory = get_parent().inventory
|
||||
@onready var parent_structure : Structure = get_parent()
|
||||
@onready var inventory : ConveyorInventory = parent_structure.inventory
|
||||
@onready var animator : AnimationPlayer = $"../AnimationPlayer"
|
||||
|
||||
func _ready() -> void:
|
||||
sync_animations.call_deferred()
|
||||
|
||||
func sync_animations() -> void:
|
||||
animator.seek(ConveyorManager.sync_time,true)
|
||||
|
||||
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)
|
||||
var calculated_position = calculate_position(i) - inventory.internal_array[i].held_item.preview.get_size()/2.0
|
||||
draw_texture(inventory.internal_array[i].held_item.preview,calculated_position)
|
||||
|
||||
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:
|
||||
var next : Structure = get_next()
|
||||
if next == null or next.inventory.can_add_from_side(Globals.facing_difference(next.facing,parent_structure.facing)) == false:
|
||||
return
|
||||
var popped = inventory.pop()
|
||||
if popped == null:
|
||||
return
|
||||
right.inventory.add(popped)
|
||||
next.inventory.add_from_side(popped,Globals.facing_difference(next.facing,parent_structure.facing))
|
||||
|
||||
func calculate_position(index: int) -> Vector2:
|
||||
var indexed_part = 16.0 / inventory.capacity
|
||||
match parent_structure.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
|
||||
|
||||
func get_next() -> Structure:
|
||||
match parent_structure.facing:
|
||||
Structure.Facing.RIGHT:
|
||||
return parent_structure.get_relative(Vector2(1,0))
|
||||
Structure.Facing.DOWN:
|
||||
return parent_structure.get_relative(Vector2(0,1))
|
||||
Structure.Facing.LEFT:
|
||||
return parent_structure.get_relative(Vector2(-1,0))
|
||||
Structure.Facing.UP:
|
||||
return parent_structure.get_relative(Vector2(0,-1))
|
||||
return null
|
||||
|
||||
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()
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.5 KiB |
|
@ -2,7 +2,7 @@
|
|||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dinyjq8853usn"
|
||||
uid="uid://gfkhedfdi7ug"
|
||||
path="res://.godot/imported/Popekko.png-5c34a5f2a8c85fcf59453310fa6553d9.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue