Jam10/Scripts/CutsceneRunner.gd

91 lines
2.6 KiB
GDScript

extends Control
export var cutscene_name : String
export var next_scene_to_load : String
var text_speed : int = 30
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": [
["Kyouko: Woooow.",
"Kyouko: I can't believe it's taken this long for them to make a stupid game about me snowboarding."],
["Reimu: Is the dialogue completed at least?",
"Kyouko: They're still working on it.",
"Reimu: Oh. Wake me up when they're finished."],
["Kyouko: Gee, I hope they get the game done soon.",
"Kyouko: I really wanna go snowboarding now."],
["Kyouko: Like I reaaally wanna. Really."],
],
"Cutscene2": [
["Kyouko: Ain't got nothing going on in Cutscene 2 huh."],
],
"Cutscene3": [
["Kyouko: Cutscene 3 too."],
],
}
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_node("ColorRect").modulate.a = 255
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") and not dialogue_fading_in:
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