1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-07 10:59:49 +00:00

Compare commits

..

1 commit

Author SHA1 Message Date
Emmanouil Papadeas 9040942865
Merge fa3642f99c into 5ec316a50f 2024-12-12 21:37:07 +02:00
3 changed files with 8 additions and 41 deletions

View file

@ -1,14 +1,7 @@
extends Panel extends Panel
## Emitted when the animation starts playing.
signal animation_started(forward: bool) signal animation_started(forward: bool)
## Emitted when the animation reaches the final frame and is not looping,
## or if the animation is manually paused.
## Note: This signal is not emitted if the animation is looping.
signal animation_finished signal animation_finished
## Emitted when the animation loops, meaning when it reaches the final frame
## and the animation keeps playing.
signal animation_looped
enum LoopType { NO, CYCLE, PINGPONG } enum LoopType { NO, CYCLE, PINGPONG }
@ -695,11 +688,9 @@ func _on_AnimationTimer_timeout() -> void:
animation_timer.wait_time = ( animation_timer.wait_time = (
project.frames[project.current_frame].duration * (1 / fps) project.frames[project.current_frame].duration * (1 / fps)
) )
animation_looped.emit()
animation_timer.start() animation_timer.start()
LoopType.PINGPONG: LoopType.PINGPONG:
animation_forward = false animation_forward = false
animation_looped.emit()
_on_AnimationTimer_timeout() _on_AnimationTimer_timeout()
else: else:
@ -722,11 +713,9 @@ func _on_AnimationTimer_timeout() -> void:
animation_timer.wait_time = ( animation_timer.wait_time = (
project.frames[project.current_frame].duration * (1 / fps) project.frames[project.current_frame].duration * (1 / fps)
) )
animation_looped.emit()
animation_timer.start() animation_timer.start()
LoopType.PINGPONG: LoopType.PINGPONG:
animation_forward = true animation_forward = true
animation_looped.emit()
_on_AnimationTimer_timeout() _on_AnimationTimer_timeout()
frame_scroll_container.ensure_control_visible( frame_scroll_container.ensure_control_visible(
Global.frame_hbox.get_child(project.current_frame) Global.frame_hbox.get_child(project.current_frame)

View file

@ -36,7 +36,6 @@ func _ready() -> void:
_is_playing_audio() _is_playing_audio()
Global.cel_switched.connect(_is_playing_audio) Global.cel_switched.connect(_is_playing_audio)
Global.current_project.fps_changed.connect(_is_playing_audio) Global.current_project.fps_changed.connect(_is_playing_audio)
Global.current_project.layers[layer].audio_changed.connect(_is_playing_audio)
Global.current_project.layers[layer].playback_frame_changed.connect(_is_playing_audio) Global.current_project.layers[layer].playback_frame_changed.connect(_is_playing_audio)

View file

@ -47,7 +47,6 @@ func _ready() -> void:
layer.audio_changed.connect(func(): audio_player.stream = layer.audio) layer.audio_changed.connect(func(): audio_player.stream = layer.audio)
add_child(audio_player) add_child(audio_player)
Global.animation_timeline.animation_started.connect(_on_animation_started) Global.animation_timeline.animation_started.connect(_on_animation_started)
Global.animation_timeline.animation_looped.connect(_on_animation_looped)
Global.animation_timeline.animation_finished.connect(_on_animation_finished) Global.animation_timeline.animation_finished.connect(_on_animation_finished)
custom_minimum_size.y = Global.animation_timeline.cel_size custom_minimum_size.y = Global.animation_timeline.cel_size
label.text = layer.name label.text = layer.name
@ -70,29 +69,13 @@ func _on_cel_switched() -> void:
z_index = 1 if button_pressed else 0 z_index = 1 if button_pressed else 0
var layer := Global.current_project.layers[layer_index] var layer := Global.current_project.layers[layer_index]
if layer is AudioLayer: if layer is AudioLayer:
if not is_instance_valid(audio_player): if not animation_running or Global.current_project.current_frame == layer.playback_frame:
return _play_audio()
if not layer.is_visible_in_hierarchy():
audio_player.stop()
return
if animation_running:
if Global.current_project.current_frame == layer.playback_frame:
_play_audio(false)
else:
_play_audio(true)
func _on_animation_started(_dir: bool) -> void: func _on_animation_started(_dir: bool) -> void:
animation_running = true animation_running = true
_play_audio(false) _play_audio()
func _on_animation_looped() -> void:
var layer := Global.current_project.layers[layer_index]
if layer is AudioLayer:
if layer.playback_frame != 0 or not layer.is_visible_in_hierarchy():
if is_instance_valid(audio_player):
audio_player.stop()
func _on_animation_finished() -> void: func _on_animation_finished() -> void:
@ -101,21 +84,17 @@ func _on_animation_finished() -> void:
audio_player.stop() audio_player.stop()
func _play_audio(single_frame: bool) -> void: func _play_audio() -> void:
if not is_instance_valid(audio_player): if not is_instance_valid(audio_player):
return return
var project := Global.current_project var layer := Global.current_project.layers[layer_index] as AudioLayer
var layer := project.layers[layer_index] as AudioLayer if not layer.visible:
if not layer.is_visible_in_hierarchy():
return return
var audio_length := layer.get_audio_length() var audio_length := layer.get_audio_length()
var frame := project.frames[project.current_frame] var frame := Global.current_project.frames[Global.current_project.current_frame]
var frame_pos := frame.position_in_seconds(project, layer.playback_frame) var frame_pos := frame.position_in_seconds(Global.current_project, layer.playback_frame)
if frame_pos >= 0 and frame_pos < audio_length: if frame_pos >= 0 and frame_pos < audio_length:
audio_player.play(frame_pos) audio_player.play(frame_pos)
if single_frame:
var timer := get_tree().create_timer(frame.get_duration_in_seconds(project.fps))
timer.timeout.connect(func(): audio_player.stop())
else: else:
audio_player.stop() audio_player.stop()