diff --git a/ArrowGirl/ArrowGirl.gd b/ArrowGirl/ArrowGirl.gd index 6106cda..d33cac2 100644 --- a/ArrowGirl/ArrowGirl.gd +++ b/ArrowGirl/ArrowGirl.gd @@ -1,6 +1,8 @@ class_name ArrowGirl extends Area2D @onready var _sprite = $AnimatedSprite2D +var dialog_text = preload("res://DialogDebug_1.tres") +var dialog_counter: int = 0 #boilerplate func _ready(): @@ -15,7 +17,8 @@ func _on_animation_finished() -> void: func _on_body_entered(body) -> void: if body is BoxBoy: - %DialogController.set_dialog("Hello flowers!", 0.2) + %DialogController.set_dialog(dialog_text.get_line_raw(dialog_counter), 0.2) + dialog_counter += 1 func _on_body_exited(body) -> void: if body is BoxBoy: diff --git a/Controllers/GameplayController.gd b/Controllers/GameplayController.gd index 8e14b99..e19c1b3 100644 --- a/Controllers/GameplayController.gd +++ b/Controllers/GameplayController.gd @@ -18,4 +18,4 @@ func _process(_delta: float) -> void: godmode = !godmode if Input.is_action_just_pressed("controller_dialog"): - get_node("../DialogController").set_dialog(LOREM_IPSUM[ randi() % LOREM_IPSUM.size()]) + %DialogController.set_dialog(LOREM_IPSUM[ randi() % LOREM_IPSUM.size()]) diff --git a/DialogDebug_1.tres b/DialogDebug_1.tres new file mode 100644 index 0000000..4f3ea2d --- /dev/null +++ b/DialogDebug_1.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" script_class="DialogText" format=3 uid="uid://iprmiuvbd0pj"] + +[ext_resource type="Script" uid="uid://d1wmy2e1qhr5h" path="res://DialogText.gd" id="1_d2twj"] + +[resource] +script = ExtResource("1_d2twj") +text = "She smiles. + +\"Hello flowers!\"" +metadata/_custom_type_script = "uid://d1wmy2e1qhr5h" diff --git a/DialogText.gd b/DialogText.gd new file mode 100644 index 0000000..e956260 --- /dev/null +++ b/DialogText.gd @@ -0,0 +1,22 @@ +class_name DialogText extends Resource + +#contains the raw text info, allows you to iterate through it line-by-line +#only parse text once + +@export_multiline() var text: String +var _content: Array = [] + +func get_line_raw(line: int) -> String: + if _content.size() == 0 and text.length() > 0: + _parse_text() + if line >= _content.size(): + return "" + return _content[line] + +func get_line_count() -> int: + if _content.size() == 0 and text.length() > 0: + _parse_text() + return _content.size() + +func _parse_text() -> void: + _content = Array(text.split("\n")).filter(func(line): return line.length() > 0) diff --git a/DialogText.gd.uid b/DialogText.gd.uid new file mode 100644 index 0000000..0f3b749 --- /dev/null +++ b/DialogText.gd.uid @@ -0,0 +1 @@ +uid://d1wmy2e1qhr5h diff --git a/Scenes/OneOne.tscn b/Scenes/OneOne.tscn index 86d8ff2..08f68dd 100644 --- a/Scenes/OneOne.tscn +++ b/Scenes/OneOne.tscn @@ -40,6 +40,6 @@ metadata/_edit_lock_ = true [node name="NPCs" type="Node" parent="." unique_id=1460483921] [node name="ArrowGirl" parent="NPCs" unique_id=869288979 instance=ExtResource("6_ywj2d")] -position = Vector2(4480, 240) +position = Vector2(4479, 240) [editable path="CanvasLayer/DialogContainer"]