Jam10/Scripts/CutsceneRunner.gd

91 lines
2.6 KiB
GDScript3
Raw Normal View History

2023-01-30 01:07:02 +00:00
extends Control
export var cutscene_name : String
export var next_scene_to_load : String
2023-01-30 02:39:59 +00:00
var text_speed : int = 30
2023-01-30 01:07:02 +00:00
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": [
2023-01-30 02:39:59 +00:00
["Kyouko: Woooow.",
"Kyouko: I can't believe it's taken this long for them to make a stupid game about me snowboarding."],
2023-01-30 01:07:02 +00:00
2023-01-30 02:39:59 +00:00
["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."],
2023-01-30 01:07:02 +00:00
],
}
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():
2023-01-30 08:02:47 +00:00
get_node("ColorRect").modulate.a = 255
2023-01-30 01:07:02 +00:00
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]
2023-01-30 02:39:59 +00:00
if Input.is_action_just_released("mouse_click") and not dialogue_fading_in:
2023-01-30 01:07:02 +00:00
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