Files
gamedev-the-steward/tests/dialogue_manager_plugin_test.gd
T
2026-08-12 20:10:54 +02:00

82 lines
2.4 KiB
GDScript

extends SceneTree
var failures: Array[String] = []
func _initialize() -> void:
call_deferred("_run")
func _run() -> void:
var manager := root.get_node_or_null("DialogueManager")
_check(manager != null, "Dialogue Manager should load through the pinned autoload")
if manager == null:
call_deferred("_finish")
return
await _exercise_runtime_api(manager)
call_deferred("_finish")
func _exercise_runtime_api(manager: Node) -> void:
var source := (
"~ start\n"
+ "Amina: The pantry is empty. [#intent=describe_need]\n"
+ "- What happened? [#option=ask_what_happened]\n"
+ "\tAmina: The final food was taken this morning.\n"
+ "- I can help. [#option=offer_help]\n"
+ "\tAmina: I will remember that.\n"
+ "=> END"
)
var resource: Resource = manager.create_resource_from_text(source)
_check(resource != null, "Runtime-generated dialogue should compile")
if resource == null:
return
var line: DialogueLine = await manager.get_next_dialogue_line(resource, "start")
_check(
line != null and line.character == "Amina" and line.text == "The pantry is empty.",
"The generated semantic turn should map to a stable rendered line"
)
if line != null:
_check(
line.get_tag_value("intent") == "describe_need",
"Controlled intent tags should survive compilation"
)
_check(line.responses.size() == 2, "The generated turn should expose two responses")
if line.responses.size() == 2:
_check(
line.responses[0].get_tag_value("option") == "ask_what_happened",
"The first response should preserve its stable option ID"
)
_check(
line.responses[1].get_tag_value("option") == "offer_help",
"The second response should preserve its stable option ID"
)
var selected: DialogueLine = await manager.get_next_dialogue_line(
resource, line.responses[1].next_id
)
_check(
selected != null and selected.text == "I will remember that.",
"A selected stable option should resolve to its generated presentation line"
)
if selected != null:
selected.extra_game_states.clear()
line.extra_game_states.clear()
line.responses.clear()
resource.set("lines", {})
resource.set_script(null)
func _check(condition: bool, message: String) -> void:
if not condition:
failures.append(message)
func _finish() -> void:
if failures.is_empty():
print("[TEST] Dialogue Manager v3.10.4 runtime adapter contract passed")
quit(0)
return
for failure in failures:
push_error("[TEST] " + failure)
quit(1)