Jam10/Scripts/CutsceneRunner.gd

78 lines
2.0 KiB
GDScript

extends Control
export var cutscene_name : String
export var next_scene_to_load : String
var text_speed : int = 24
var text_label : RichTextLabel
var animation_player : AnimationPlayer
var audio_stream_player : AudioStreamPlayer
var cutscene_index : int = 0
var cutscene_sub_index : int = 0
var this_text : String
var message_time_elapsed : float
var chars_rendered : int = 0
var dialogue_fading_in : bool = true
var cutscene_directory = {
"Cutscene1": [
["Hello.",
"How are you?"],
["I'm fine.",
"How about you?"],
],
}
func _ready():
text_label = find_node("RichTextLabel")
animation_player = find_node("AnimationPlayer")
audio_stream_player = find_node("AudioStreamPlayer")
animation_player.play("InitialFade")
func advance_dialogue():
if cutscene_sub_index == cutscene_directory[cutscene_name][cutscene_index].size() - 1:
animation_player.play("DialogueFade")
else:
cutscene_sub_index += 1
message_time_elapsed = 0
chars_rendered = 0
func mid_dialogue_fade():
if cutscene_index == cutscene_directory[cutscene_name].size() - 1:
animation_player.stop()
animation_player.play("FinalFade")
else:
cutscene_index += 1
cutscene_sub_index = 0
message_time_elapsed = 0
chars_rendered = 0
dialogue_fading_in = true
func dialogue_fade_done():
dialogue_fading_in = false
func final_fade_done():
get_tree().change_scene("res://Scenes/" + next_scene_to_load + ".tscn")
func _process(delta):
this_text = cutscene_directory[cutscene_name][cutscene_index][cutscene_sub_index]
if Input.is_action_just_released("mouse_click"):
if chars_rendered < this_text.length():
message_time_elapsed = 60
else:
advance_dialogue()
if not dialogue_fading_in:
message_time_elapsed = min(60, message_time_elapsed + delta)
var chars_to_display : int = floor(message_time_elapsed * text_speed)
chars_to_display = min(this_text.length(), chars_to_display)
text_label.text = this_text.substr(0, chars_to_display)
if chars_to_display > chars_rendered:
audio_stream_player.play()
chars_rendered = chars_to_display