summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/DwarfNPC.gd25
-rw-r--r--scripts/PlayerCharacter.gd2
2 files changed, 18 insertions, 9 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
diff --git a/scripts/PlayerCharacter.gd b/scripts/PlayerCharacter.gd
index 15b3421..8e2b83a 100644
--- a/scripts/PlayerCharacter.gd
+++ b/scripts/PlayerCharacter.gd
@@ -40,7 +40,7 @@ func update_input_and_movement():
func _process(_delta):
# Update walking wobble
- var is_moving = velocity.length_squared() > .0
+ var is_moving = velocity.length_squared() > .0 and dialogue_state != DialogueState.ACTIVE
if is_moving:
var time = OS.get_system_time_msecs() / 1000.0
var rot = 0.2 * sin(walk_wobble_coeff * time)