64 lines
1.3 KiB
GDScript
64 lines
1.3 KiB
GDScript
extends ColorRect
|
|
|
|
export var dialog_path: String = ''
|
|
export var text_speed: float = 0.05
|
|
|
|
var dialog: Array
|
|
var phrase_num: int = 0
|
|
var finished = false
|
|
|
|
|
|
func _ready() -> void:
|
|
$Timer.wait_time = text_speed
|
|
dialog = get_dialog()
|
|
assert(dialog, 'Dialog not found')
|
|
next_phrase()
|
|
return
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
$Indicator.visible = finished
|
|
if event.is_action_pressed('ui_accept'):
|
|
if finished:
|
|
next_phrase()
|
|
else:
|
|
$Text.visible_characters = len($Text.text)
|
|
return
|
|
|
|
|
|
func get_dialog() -> Array:
|
|
var f = File.new()
|
|
assert(f.file_exists(dialog_path), 'File path does not exist')
|
|
|
|
f.open(dialog_path, File.READ)
|
|
var json = f.get_as_text()
|
|
|
|
var output = parse_json(json)
|
|
|
|
if typeof(output) == TYPE_ARRAY:
|
|
return output
|
|
else:
|
|
return []
|
|
|
|
func next_phrase() -> void:
|
|
if phrase_num >= len(dialog):
|
|
queue_free()
|
|
return
|
|
|
|
finished = false
|
|
|
|
$Name.bbcode_text = dialog[phrase_num]['Name']
|
|
$Text.bbcode_text = dialog[phrase_num]['Text']
|
|
|
|
$Text.visible_characters = 0
|
|
|
|
while $Text.visible_characters < len($Text.text):
|
|
$Text.visible_characters += 1
|
|
|
|
$Timer.start()
|
|
yield($Timer, 'timeout')
|
|
|
|
finished = true
|
|
phrase_num += 1
|
|
return
|