extends RichTextLabel
class_name TextBox

var letters_per_second:float = 10
var complete_text:String = ''
var time_elapsed: float = 0
var done:bool = true
var text_to_write = ''
signal done_text


func _process(delta: float) -> void:
	if done: return
	time_elapsed += delta
	var num_letters = int(time_elapsed*letters_per_second)
	text_to_write = complete_text.left(num_letters)
	text = '[center]' + text_to_write
	if text_to_write == complete_text:
		done = true
		done_text.emit()
	
	
func set_new_text(new_text:String):
	complete_text = new_text
	time_elapsed = 0
	done = false


func reset_text():
	complete_text = ''
	text = ''
