-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialogue.gd
49 lines (37 loc) · 988 Bytes
/
dialogue.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
extends Control
@onready var _dialogue : RichTextLabel = $VBoxContainer/Text
@onready var _continue : Button = $Box/Continue
var text := []
var textIndex := 0
func _ready() -> void:
var json_as_text = FileAccess.get_file_as_string("messages.json")
var json_as_dict = JSON.parse_string(json_as_text)
if json_as_dict and Global.owner_code in json_as_dict:
text = json_as_dict[Global.owner_code]
print("For owner code: ", Global.owner_code, " had text: ", text)
Global.dialogue = self
func single_line(line: String):
_dialogue.text = line
open()
_continue.grab_focus()
func display_line(opening: bool = false):
if opening and textIndex != 0:
return
if textIndex < len(text):
_dialogue.text = text[textIndex]
open()
_continue.grab_focus()
textIndex += 1
else:
close()
textIndex = 0
func open():
visible = true
func close():
visible = false
func _on_continue_pressed() -> void:
print(textIndex)
if textIndex != 0:
display_line()
else:
close()