Started working on a simple dialog system

This commit is contained in:
2026-03-15 07:11:42 +11:00
parent 84cb13e717
commit 336dd59dbb
6 changed files with 39 additions and 3 deletions

View File

@@ -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:

View File

@@ -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()])

10
DialogDebug_1.tres Normal file
View File

@@ -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"

22
DialogText.gd Normal file
View File

@@ -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)

1
DialogText.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://d1wmy2e1qhr5h

View File

@@ -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"]