Skip to content

Instantly share code, notes, and snippets.

@tavurth
Created December 22, 2021 20:42
Show Gist options
  • Save tavurth/65234316a2f6c980507515de2eec67e9 to your computer and use it in GitHub Desktop.
Save tavurth/65234316a2f6c980507515de2eec67e9 to your computer and use it in GitHub Desktop.
extends NinePatchRect
var to_display = ""
var wait_time = 0.05
var wait_default = 0.05
var last_sound = 0
onready var Timer = $Timer
onready var Audio = $AudioStreamPlayer
onready var Text = $MarginContainer/RichTextLabel
func _ready():
pass
func display(text: String):
self.last_sound = 0
self.to_display = text
self.wait_time = self.wait_default
Timer.start(wait_time)
func _input(event: InputEvent):
if event is InputEventMouseButton and event.pressed:
self.wait_time = 0.0001
func _on_Timer_timeout():
if not len(to_display):
return Timer.stop()
if Text.bbcode_text == to_display:
return Timer.stop()
var next_char = to_display[0]
if next_char == '.':
self.wait_time = self.wait_default
Timer.set_wait_time(0.5)
else:
Timer.set_wait_time(self.wait_time)
self.last_sound += 1
if self.last_sound > 1:
Audio.play()
self.last_sound = 0
Text.append_bbcode(next_char)
to_display = to_display.substr(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment