summaryrefslogtreecommitdiffstats
path: root/scripts/DwarfNPC.gd
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/DwarfNPC.gd')
-rw-r--r--scripts/DwarfNPC.gd25
1 files changed, 17 insertions, 8 deletions
diff --git a/scripts/DwarfNPC.gd b/scripts/DwarfNPC.gd
index 8fa7b24..b6b8848 100644
--- a/scripts/DwarfNPC.gd
+++ b/scripts/DwarfNPC.gd
@@ -2,17 +2,27 @@ extends KinematicBody2D
class_name DwarfNPC
export (NodePath) var target
+export (String, FILE, "*.json") var dialogue_file
onready var target_node = get_node(target)
+var dialogue_data = []
-# Declare member variables here. Examples:
-# var a = 2
-# var b = "text"
-
+func load_text_file(path):
+ var f = File.new()
+ var err = f.open(path, File.READ)
+ if err != OK:
+ printerr("Could not open file, error code ", err)
+ return ""
+ var text = f.get_as_text()
+ f.close()
+ return text
# Called when the node enters the scene tree for the first time.
func _ready():
- pass # Replace with function body.
-
+ var dialogue_txt = load_text_file(dialogue_file)
+ var dialogue_result = JSON.parse(dialogue_txt)
+ if dialogue_result.error != OK:
+ return push_error(dialogue_result.error_string)
+ dialogue_data = dialogue_result.result
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
@@ -23,5 +33,4 @@ func _process(_delta):
$Sprite.set_scale(Vector2(dir, 1))
func get_dialogue():
- return [{ "name": "Dwarf", "body": "Hello, I'm a dwarf." },
- { "name": "Dwarf", "body": "How's it going?" }]
+ return dialogue_data