mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-07 10:59:49 +00:00
Compare commits
5 commits
9040942865
...
b274e7ad0e
Author | SHA1 | Date | |
---|---|---|---|
|
b274e7ad0e | ||
|
710f6d41e6 | ||
|
214ba1b17d | ||
|
97495a19da | ||
|
019a8db21c |
|
@ -1,7 +1,14 @@
|
||||||
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 }
|
||||||
|
|
||||||
|
@ -688,9 +695,11 @@ 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:
|
||||||
|
@ -713,9 +722,11 @@ 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)
|
||||||
|
|
|
@ -36,6 +36,7 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@ 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
|
||||||
|
@ -69,13 +70,29 @@ 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 animation_running or Global.current_project.current_frame == layer.playback_frame:
|
if not is_instance_valid(audio_player):
|
||||||
_play_audio()
|
return
|
||||||
|
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()
|
_play_audio(false)
|
||||||
|
|
||||||
|
|
||||||
|
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:
|
||||||
|
@ -84,17 +101,21 @@ func _on_animation_finished() -> void:
|
||||||
audio_player.stop()
|
audio_player.stop()
|
||||||
|
|
||||||
|
|
||||||
func _play_audio() -> void:
|
func _play_audio(single_frame: bool) -> void:
|
||||||
if not is_instance_valid(audio_player):
|
if not is_instance_valid(audio_player):
|
||||||
return
|
return
|
||||||
var layer := Global.current_project.layers[layer_index] as AudioLayer
|
var project := Global.current_project
|
||||||
if not layer.visible:
|
var layer := project.layers[layer_index] as AudioLayer
|
||||||
|
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 := Global.current_project.frames[Global.current_project.current_frame]
|
var frame := project.frames[project.current_frame]
|
||||||
var frame_pos := frame.position_in_seconds(Global.current_project, layer.playback_frame)
|
var frame_pos := frame.position_in_seconds(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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue