110 lines
2.5 KiB
GDScript
110 lines
2.5 KiB
GDScript
extends Control
|
|
|
|
|
|
@onready
|
|
var template = $Printer/PictureLayer/Template
|
|
|
|
signal done_loading_picture(picture)
|
|
signal done_processing_photo(photo)
|
|
|
|
var files_being_processed = 0
|
|
|
|
func _ready():
|
|
get_viewport().files_dropped.connect(
|
|
func(files):
|
|
var thread = Thread.new()
|
|
thread.start(on_files_dropped.bind(files), Thread.PRIORITY_LOW)
|
|
$PhotoProcess.process_files(files)
|
|
)
|
|
|
|
$PhotoProcess.done_with_photo.connect(
|
|
func(photo):
|
|
var thread = Thread.new()
|
|
thread.start(print_out.bind(photo), Thread.PRIORITY_LOW)
|
|
)
|
|
|
|
done_loading_picture.connect(animate_picture)
|
|
done_processing_photo.connect(animate_printing_out)
|
|
|
|
template.get_parent().remove_child(template)
|
|
|
|
|
|
func on_files_dropped(files):
|
|
var index = 0
|
|
for path in files:
|
|
var image = Image.load_from_file(path)
|
|
var texture = ImageTexture.create_from_image(image)
|
|
|
|
var picture = template.duplicate()
|
|
picture.get_node('Texture').texture = texture
|
|
picture.global_position = Vector2(randf_range(-300, 300), -300) * 2.0
|
|
picture.rotation = randf() * TAU * randf_range(1, 3)
|
|
call_deferred('emit_signal', 'done_loading_picture', picture, index)
|
|
index += 1
|
|
|
|
|
|
func animate_picture(picture, index):
|
|
$Printer/PictureLayer.add_child(picture)
|
|
await get_tree().create_timer(index).timeout
|
|
var tween = create_tween().set_parallel()
|
|
var time = 1.0 + randf()
|
|
tween.tween_property(
|
|
picture,
|
|
'rotation',
|
|
.0,
|
|
time
|
|
)
|
|
|
|
tween.tween_property(
|
|
picture,
|
|
'global_position',
|
|
$Printer/Back/AnimationTarget.global_position,
|
|
time
|
|
)
|
|
|
|
tween.chain().tween_property(
|
|
picture,
|
|
'global_position',
|
|
$Printer/Back/AnimationTarget.global_position + Vector2.DOWN * 100,
|
|
1.0
|
|
)
|
|
|
|
tween.play()
|
|
await tween.finished
|
|
files_being_processed += 1
|
|
|
|
|
|
func print_out(photo):
|
|
var image = Image.load_from_file(photo)
|
|
var texture = ImageTexture.create_from_image(image)
|
|
|
|
var picture = template.duplicate()
|
|
picture.get_node('Texture').texture = texture
|
|
call_deferred('emit_signal', 'done_processing_photo', picture)
|
|
|
|
|
|
func animate_printing_out(picture):
|
|
$Printer/PictureOutLayer.add_child(picture)
|
|
files_being_processed -= 1
|
|
|
|
picture.global_position = $Printer/Back/AnimationTarget.global_position + Vector2.DOWN * 100
|
|
picture.rotation = .0
|
|
|
|
var tween = create_tween()
|
|
var time = 3.0 + randf()
|
|
|
|
tween.tween_property(
|
|
picture,
|
|
'global_position',
|
|
$Printer/Back/AnimationTarget.global_position + Vector2.DOWN * 200,
|
|
time
|
|
)
|
|
|
|
tween.play()
|
|
|
|
|
|
func _process(_delta):
|
|
if files_being_processed > 0:
|
|
$Printer/Front.rotation = sin(Time.get_ticks_msec()) * .025
|
|
else:
|
|
$Printer/Front.rotation = .0
|