Người nói
Bốn từ là đủ cho toàn bộ addon:
| Quyết định | |
|---|---|
| Conversation | nói gì |
| Speakers | ai nói |
| Dialogue Box | trình bày thế nào |
| Placement | hiện ở đâu |
Trang này nói về cái thứ hai.
Speaker là một danh tính hội thoại
Không phải nhân vật trong gameplay. Một speaker giữ một cái tên, một gương mặt cho hộp thoại, và một giọng, ngoài ra không gì cả. Không NodePath, không AnimationPlayer, không sprite trong thế giới.
Vì vậy người kể chuyện, giọng bộ đàm, tấm biển, hay một nhân vật ở màn chơi chưa được nạp đều là speaker bình thường. Không có gì để trỏ chúng vào.
Tạo một speaker
Mở tab Speakers của workspace TalkKit rồi bấm + New. Khung giữa để chỉnh speaker, preview cho thấy hộp thoại sẽ vẽ họ ra sao.

| Ô | Là gì |
|---|---|
| Display Name | tên trên hộp, ví dụ Haru · Trail Keeper |
| Visual | gương mặt trong hộp: một Texture cho portrait tĩnh, hoặc Sprite Frames và Animation cho portrait chuyển động |
| Variants | các gương mặt khác có tên, ví dụ angry hay happy |
| Voice Blip, Voice Pitch Min/Max, Voice Blip Interval | tiếng ngắn phát khi chữ hiện ra; ▶ Preview voice blip để nghe thử |
Speaker tạo ở đây chỉ thuộc node này. Actions → Save as Shared… lưu nó thành .tres để NPC khác dùng chung; sửa một lần là mọi NPC đang dùng đều đổi theo. Make Unique để một NPC tách riêng.
Người chơi cũng là speaker
Cho speaker của người chơi dùng chính SpriteFrames mà nhân vật người chơi đang dùng, và hộp thoại hiện đúng animation đó. TalkKit đọc resource chứ không đọc node, nên cách này chạy được cả khi người chơi không có trong scene.
TalkKit không điều khiển nhân vật của bạn
Nó không bao giờ gắn speaker vào một node, không phát animation talk hay idle, không đọc trạng thái gameplay. Muốn nhân vật chuyển động khi nói thì game của bạn tự phát animation đó, ngay chỗ bắt đầu hội thoại.
Gương mặt có tên
Thêm gương mặt trong Variants, rồi chọn cho từng câu bằng Visual variant trong tuỳ chọn của câu. Variant mà speaker không có thì dùng gương mặt mặc định chứ không vẽ trống, nên một câu viết cho Haru đang giận vẫn chạy được với một Haru chỉ có một gương mặt.
Nhiều người nói, một hội thoại
Conversation ghi một lần ai thường nói. Một câu chỉ ghi khi nó là ngoại lệ, và câu sau tự quay về mặc định.
Defaults Haru Classic Panel Screen · Bottom
1 H Haru Defaults This road is dangerous.
2 H Haru Defaults Stay close.
3 R Ren 2 overrides Wait!
4 H Haru Defaults What is it?Muốn câu 3 là của Ren, bấm chữ H cạnh nó rồi chọn Ren, hoặc chọn câu đó và đặt Speaker trong tuỳ chọn. Không có dàn nhân vật nào phải khai báo: nhiều người nói không phải một chế độ, nó là chuyện xảy ra khi một câu ghi tên người khác.
Lựa chọn ở đâu cũng giống nhau:
| Default (Haru) | dùng người nói của conversation |
| None · narrator | không ai nói câu này |
| Haru, Ren, Player… | các speaker node này có |
Muốn dùng một speaker mà node chưa có thì thêm nó trong Speakers trước. Hàng Defaults của conversation còn có Browse…, cho speaker đã lưu ở bất kỳ đâu trong project.
Hai cấp, chỉ hai
câu → mặc định của conversationĐó là toàn bộ quy tắc, cho người nói, hộp thoại và vị trí. Node giữ danh sách để chọn; nó không phải cấp thứ ba quyết định những gì conversation bỏ trống.
Đây vẫn không phải rẽ nhánh
Một conversation là một chuỗi thẳng. Nhiều người nói chỉ đổi tên trên hộp; nó không đổi những gì chạy tiếp theo. Rẽ nhánh vẫn ở chỗ cũ: game của bạn trả lời một blocking event và bắt đầu hội thoại khác.
Chọn, không sửa
Conversation và câu thoại chỉ chọn speaker hay hộp thoại. Việc tạo, nhân bản, dùng chung và xoá chúng nằm ở tab Speakers và Dialogue Boxes, nơi mỗi cái cho thấy ai đang dùng nó.
Chọn Ren cho một câu là việc cục bộ; còn Ren thì không. Sửa Ren trong Speakers là đổi mọi câu và mọi NPC đang dùng speaker đó. Muốn một bản Speech Bubble màu đỏ cho một câu? Nhân bản nó trong Dialogue Boxes, đổi tên, rồi chọn cho câu đó.
Không ai nói
Đặt Speaker thành None · narrator. Chữ vẫn gõ, sự kiện vẫn bắn; tên và gương mặt để trống, đúng như một tấm biển, người kể chuyện hay thông báo hệ thống nên trông.
Rich text
Câu thoại là rich text. Gõ thẳng BBCode của Godot vào:
[color=red][b]Warning![/b][/color] Go back.Typewriter hiện ra chữ, không bao giờ hiện thẻ, nên câu gõ dở không bao giờ lộ [colo. BBCode là toàn bộ cú pháp; TalkKit không thêm ngôn ngữ đánh dấu riêng.
Thoại không cần viết trước
say() hiện một câu thẳng từ code: một câu bâng quơ, một gợi ý, một câu của người kể chuyện về điều vừa xảy ra. Nó nhận một chuỗi, một câu thoại, hoặc một danh sách.
$NPCTalkKit.say("[i]The river carries you back to the trailhead.[/i]")Node có không conversation nào vẫn là node chạy được. Câu đó đi qua đúng hộp, vị trí, sự kiện và luật như một hội thoại viết sẵn. Trong mục Quick Say ở Inspector của node, chọn speaker, hộp thoại và vị trí mà say() dùng.
Cái gì nằm ở đâu
| Speaker | Dialogue Box | |
|---|---|---|
| Tên hiện ra | ✅ cung cấp | ✅ quyết định có hiện không |
| Gương mặt hiện ra | ✅ cung cấp | ✅ quyết định cỡ, bên, có hiện không |
| Tiếng blip | ✅ âm thanh | — |
| Tốc độ gõ | — | ✅ |
Từ script
Mọi thứ ở trên cũng làm được bằng GDScript, cho speaker tạo lúc chạy game.
Một speaker:
extends Node
## Docs: /guide/speakers — who is talking, how they look, how they sound.
func _ready() -> void:
_build()
#region speaker
# A speaker is a dialogue identity. No NodePath, no AnimationPlayer, no world
# sprite — so a narrator, a radio voice, or someone standing in a level that is
# not even loaded are all ordinary speakers.
func make_a_speaker() -> TalkSpeaker:
var haru := TalkSpeaker.new()
haru.speaker_id = &"haru"
haru.display_name = "Haru"
haru.visual = TalkDialogueVisual.new()
haru.visual.texture = preload("res://addons/npc_talkkit/icons/talk_speaker.svg")
haru.voice_blip = AudioStreamWAV.new()
return haru
#endregion
#region reuse
# Separate from the node is not the same as separate from the asset. Pointing a
# speaker at the very SpriteFrames the player already uses is the intended way
# to make the player a speaker — TalkKit never looks for the player node.
func reuse_the_game_art(frames: SpriteFrames) -> TalkSpeaker:
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
player.visual = TalkDialogueVisual.new()
player.visual.sprite_frames = frames
player.visual.animation = &"idle"
return player
#endregion
#region variants
# Named faces, not a free-text mood. A variant the speaker does not have falls
# back to their default face rather than drawing nothing.
func add_an_angry_face(haru: TalkSpeaker, angry: Texture2D) -> void:
var variant := TalkDialogueVisual.new()
variant.texture = angry
haru.variants[&"angry"] = variant
func shout_this_line(line: TalkLine) -> void:
line.visual_variant = &"angry"
#endregion
#region multi
# One conversation, several speakers, one straight sequence. The conversation
# says once who normally speaks; a line says so only when it is the exception,
# and the line after it goes back to the default without being told to.
func a_conversation_with_three_people(
haru: TalkSpeaker, guard: TalkSpeaker, player: TalkSpeaker, box: TalkBoxTemplate,
) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"gate"
conversation.default_speaker = haru
conversation.default_dialogue_box = box
for pair in [[null, "Who are you?"], [guard, "Step away."],
[player, "I am only passing through."], [null, "Let him go."]]:
var line := TalkLine.new()
if pair[0] != null:
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = pair[0]
line.text = pair[1]
conversation.lines.append(line)
return conversation
#endregion
#region nobody
# No speaker at all is a working configuration, not a gap. The text still
# types, events still fire; the name row and the visual just stay empty.
func a_sign_nobody_speaks(box: TalkBoxTemplate) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"sign"
conversation.default_speaker = null # nobody, and that is the point
conversation.default_dialogue_box = box
var line := TalkLine.new()
line.text = "[i]The gate is barred.[/i]"
conversation.lines = [line]
return conversation
#endregion
#region say
# Nothing has to be authored anywhere. say() takes a string, a TalkLine, or a
# sequence of them, and runs them through the pipeline play() uses — same box,
# same placement, same events.
func bark(text: String) -> void:
$NPCTalkKit.say(text)
func interrupt(guard: TalkSpeaker) -> void:
var line := TalkLine.new()
line.text = "[color=#ff6b6b]Stop right there![/color]"
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = guard
$NPCTalkKit.say(line)
# Or name them by id, from the collections this node carries. An option is a
# selection, never a description: say() cannot build a speaker or restyle a box.
func interrupt_by_name() -> void:
$NPCTalkKit.say("[color=#ff6b6b]Stop right there![/color]",
{}, {"speaker": &"guard", "dialogue_box": &"warning"})
# The key is what counts, not the value. Leaving "speaker" out falls through to
# the Quick Say default; passing it as null says there is no speaker at all.
func narrate(text: String) -> void:
$NPCTalkKit.say(text, {}, {"speaker": null})
#endregion
func _build() -> void:
var talk := NPCTalkKit.new()
talk.name = "NPCTalkKit"
talk.dialogue_boxes = [_instant_box()]
add_child(talk)
func _verify() -> Array[String]:
var failures: Array[String] = []
var talk: NPCTalkKit = $NPCTalkKit
var haru := make_a_speaker()
var guard := TalkSpeaker.new()
guard.speaker_id = &"guard"
guard.display_name = "Guard"
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
var box: TalkBoxTemplate = talk.dialogue_boxes[0]
talk.speakers = [haru, guard, player]
talk.quick_say_speaker = haru
talk.quick_say_dialogue_box = box
var gate := a_conversation_with_three_people(haru, guard, player, box)
talk.conversations = [gate, a_sign_nobody_speaks(box)]
talk.play(&"gate")
for expected in ["Haru", "Guard", "Player", "Haru"]:
if talk._box.get_name_label().text != expected:
failures.append("speakers: expected %s, got '%s'"
% [expected, talk._box.get_name_label().text])
talk.advance()
if talk.is_running():
failures.append("speakers: the sequence should have finished")
# A named face, and a name that does not exist.
add_an_angry_face(haru, PlaceholderTexture2D.new())
shout_this_line(gate.lines[0])
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.variants[&"angry"]:
failures.append("speakers: a named variant should be chosen")
gate.lines[0].visual_variant = &"nonexistent"
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.visual:
failures.append("speakers: an unknown variant should fall back, not blank out")
gate.lines[0].visual_variant = &""
# Nobody speaking.
talk.play(&"sign")
if talk.resolve_speaker(talk.conversations[1].lines[0]) != null:
failures.append("speakers: a sign must resolve to no speaker")
if talk._box.get_name_label().visible:
failures.append("speakers: and show no name row")
talk.stop()
# Reusing game art, with no reference to any node.
var frames := SpriteFrames.new()
frames.add_animation(&"idle")
frames.add_frame(&"idle", PlaceholderTexture2D.new())
var reused := reuse_the_game_art(frames)
if reused.visual.frame_texture(0.0) == null:
failures.append("speakers: an animated visual must resolve a frame")
# say(), with nothing authored, falling through to the Quick Say defaults.
var blank := NPCTalkKit.new()
var quick := _instant_box()
blank.dialogue_boxes = [quick]
blank.speakers = [haru]
blank.quick_say_speaker = haru
blank.quick_say_dialogue_box = quick
add_child(blank)
if not blank.say("Just this."):
failures.append("speakers: say() must work on a node with no conversations")
if blank._box.get_name_label().text != "Haru":
failures.append("speakers: say() should fall through to the Quick Say speaker")
# ...and an explicit option beating it, including "explicitly nobody".
blank.stop()
blank.say("Three days later…", {}, {"speaker": null})
if not blank._box.get_name_label().text.is_empty():
failures.append("speakers: an explicit null speaker must mean narrator")
blank.stop()
blank.queue_free()
return failures
## Typing speed lives on the dialogue box, so a scripted run hands the node a
## box that types instantly.
func _instant_box() -> TalkBoxTemplate:
var template := TalkBoxTemplate.new()
template.typewriter_speed = 0.0
return templateDùng lại SpriteFrames của người chơi:
extends Node
## Docs: /guide/speakers — who is talking, how they look, how they sound.
func _ready() -> void:
_build()
#region speaker
# A speaker is a dialogue identity. No NodePath, no AnimationPlayer, no world
# sprite — so a narrator, a radio voice, or someone standing in a level that is
# not even loaded are all ordinary speakers.
func make_a_speaker() -> TalkSpeaker:
var haru := TalkSpeaker.new()
haru.speaker_id = &"haru"
haru.display_name = "Haru"
haru.visual = TalkDialogueVisual.new()
haru.visual.texture = preload("res://addons/npc_talkkit/icons/talk_speaker.svg")
haru.voice_blip = AudioStreamWAV.new()
return haru
#endregion
#region reuse
# Separate from the node is not the same as separate from the asset. Pointing a
# speaker at the very SpriteFrames the player already uses is the intended way
# to make the player a speaker — TalkKit never looks for the player node.
func reuse_the_game_art(frames: SpriteFrames) -> TalkSpeaker:
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
player.visual = TalkDialogueVisual.new()
player.visual.sprite_frames = frames
player.visual.animation = &"idle"
return player
#endregion
#region variants
# Named faces, not a free-text mood. A variant the speaker does not have falls
# back to their default face rather than drawing nothing.
func add_an_angry_face(haru: TalkSpeaker, angry: Texture2D) -> void:
var variant := TalkDialogueVisual.new()
variant.texture = angry
haru.variants[&"angry"] = variant
func shout_this_line(line: TalkLine) -> void:
line.visual_variant = &"angry"
#endregion
#region multi
# One conversation, several speakers, one straight sequence. The conversation
# says once who normally speaks; a line says so only when it is the exception,
# and the line after it goes back to the default without being told to.
func a_conversation_with_three_people(
haru: TalkSpeaker, guard: TalkSpeaker, player: TalkSpeaker, box: TalkBoxTemplate,
) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"gate"
conversation.default_speaker = haru
conversation.default_dialogue_box = box
for pair in [[null, "Who are you?"], [guard, "Step away."],
[player, "I am only passing through."], [null, "Let him go."]]:
var line := TalkLine.new()
if pair[0] != null:
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = pair[0]
line.text = pair[1]
conversation.lines.append(line)
return conversation
#endregion
#region nobody
# No speaker at all is a working configuration, not a gap. The text still
# types, events still fire; the name row and the visual just stay empty.
func a_sign_nobody_speaks(box: TalkBoxTemplate) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"sign"
conversation.default_speaker = null # nobody, and that is the point
conversation.default_dialogue_box = box
var line := TalkLine.new()
line.text = "[i]The gate is barred.[/i]"
conversation.lines = [line]
return conversation
#endregion
#region say
# Nothing has to be authored anywhere. say() takes a string, a TalkLine, or a
# sequence of them, and runs them through the pipeline play() uses — same box,
# same placement, same events.
func bark(text: String) -> void:
$NPCTalkKit.say(text)
func interrupt(guard: TalkSpeaker) -> void:
var line := TalkLine.new()
line.text = "[color=#ff6b6b]Stop right there![/color]"
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = guard
$NPCTalkKit.say(line)
# Or name them by id, from the collections this node carries. An option is a
# selection, never a description: say() cannot build a speaker or restyle a box.
func interrupt_by_name() -> void:
$NPCTalkKit.say("[color=#ff6b6b]Stop right there![/color]",
{}, {"speaker": &"guard", "dialogue_box": &"warning"})
# The key is what counts, not the value. Leaving "speaker" out falls through to
# the Quick Say default; passing it as null says there is no speaker at all.
func narrate(text: String) -> void:
$NPCTalkKit.say(text, {}, {"speaker": null})
#endregion
func _build() -> void:
var talk := NPCTalkKit.new()
talk.name = "NPCTalkKit"
talk.dialogue_boxes = [_instant_box()]
add_child(talk)
func _verify() -> Array[String]:
var failures: Array[String] = []
var talk: NPCTalkKit = $NPCTalkKit
var haru := make_a_speaker()
var guard := TalkSpeaker.new()
guard.speaker_id = &"guard"
guard.display_name = "Guard"
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
var box: TalkBoxTemplate = talk.dialogue_boxes[0]
talk.speakers = [haru, guard, player]
talk.quick_say_speaker = haru
talk.quick_say_dialogue_box = box
var gate := a_conversation_with_three_people(haru, guard, player, box)
talk.conversations = [gate, a_sign_nobody_speaks(box)]
talk.play(&"gate")
for expected in ["Haru", "Guard", "Player", "Haru"]:
if talk._box.get_name_label().text != expected:
failures.append("speakers: expected %s, got '%s'"
% [expected, talk._box.get_name_label().text])
talk.advance()
if talk.is_running():
failures.append("speakers: the sequence should have finished")
# A named face, and a name that does not exist.
add_an_angry_face(haru, PlaceholderTexture2D.new())
shout_this_line(gate.lines[0])
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.variants[&"angry"]:
failures.append("speakers: a named variant should be chosen")
gate.lines[0].visual_variant = &"nonexistent"
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.visual:
failures.append("speakers: an unknown variant should fall back, not blank out")
gate.lines[0].visual_variant = &""
# Nobody speaking.
talk.play(&"sign")
if talk.resolve_speaker(talk.conversations[1].lines[0]) != null:
failures.append("speakers: a sign must resolve to no speaker")
if talk._box.get_name_label().visible:
failures.append("speakers: and show no name row")
talk.stop()
# Reusing game art, with no reference to any node.
var frames := SpriteFrames.new()
frames.add_animation(&"idle")
frames.add_frame(&"idle", PlaceholderTexture2D.new())
var reused := reuse_the_game_art(frames)
if reused.visual.frame_texture(0.0) == null:
failures.append("speakers: an animated visual must resolve a frame")
# say(), with nothing authored, falling through to the Quick Say defaults.
var blank := NPCTalkKit.new()
var quick := _instant_box()
blank.dialogue_boxes = [quick]
blank.speakers = [haru]
blank.quick_say_speaker = haru
blank.quick_say_dialogue_box = quick
add_child(blank)
if not blank.say("Just this."):
failures.append("speakers: say() must work on a node with no conversations")
if blank._box.get_name_label().text != "Haru":
failures.append("speakers: say() should fall through to the Quick Say speaker")
# ...and an explicit option beating it, including "explicitly nobody".
blank.stop()
blank.say("Three days later…", {}, {"speaker": null})
if not blank._box.get_name_label().text.is_empty():
failures.append("speakers: an explicit null speaker must mean narrator")
blank.stop()
blank.queue_free()
return failures
## Typing speed lives on the dialogue box, so a scripted run hands the node a
## box that types instantly.
func _instant_box() -> TalkBoxTemplate:
var template := TalkBoxTemplate.new()
template.typewriter_speed = 0.0
return templateGương mặt có tên:
extends Node
## Docs: /guide/speakers — who is talking, how they look, how they sound.
func _ready() -> void:
_build()
#region speaker
# A speaker is a dialogue identity. No NodePath, no AnimationPlayer, no world
# sprite — so a narrator, a radio voice, or someone standing in a level that is
# not even loaded are all ordinary speakers.
func make_a_speaker() -> TalkSpeaker:
var haru := TalkSpeaker.new()
haru.speaker_id = &"haru"
haru.display_name = "Haru"
haru.visual = TalkDialogueVisual.new()
haru.visual.texture = preload("res://addons/npc_talkkit/icons/talk_speaker.svg")
haru.voice_blip = AudioStreamWAV.new()
return haru
#endregion
#region reuse
# Separate from the node is not the same as separate from the asset. Pointing a
# speaker at the very SpriteFrames the player already uses is the intended way
# to make the player a speaker — TalkKit never looks for the player node.
func reuse_the_game_art(frames: SpriteFrames) -> TalkSpeaker:
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
player.visual = TalkDialogueVisual.new()
player.visual.sprite_frames = frames
player.visual.animation = &"idle"
return player
#endregion
#region variants
# Named faces, not a free-text mood. A variant the speaker does not have falls
# back to their default face rather than drawing nothing.
func add_an_angry_face(haru: TalkSpeaker, angry: Texture2D) -> void:
var variant := TalkDialogueVisual.new()
variant.texture = angry
haru.variants[&"angry"] = variant
func shout_this_line(line: TalkLine) -> void:
line.visual_variant = &"angry"
#endregion
#region multi
# One conversation, several speakers, one straight sequence. The conversation
# says once who normally speaks; a line says so only when it is the exception,
# and the line after it goes back to the default without being told to.
func a_conversation_with_three_people(
haru: TalkSpeaker, guard: TalkSpeaker, player: TalkSpeaker, box: TalkBoxTemplate,
) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"gate"
conversation.default_speaker = haru
conversation.default_dialogue_box = box
for pair in [[null, "Who are you?"], [guard, "Step away."],
[player, "I am only passing through."], [null, "Let him go."]]:
var line := TalkLine.new()
if pair[0] != null:
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = pair[0]
line.text = pair[1]
conversation.lines.append(line)
return conversation
#endregion
#region nobody
# No speaker at all is a working configuration, not a gap. The text still
# types, events still fire; the name row and the visual just stay empty.
func a_sign_nobody_speaks(box: TalkBoxTemplate) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"sign"
conversation.default_speaker = null # nobody, and that is the point
conversation.default_dialogue_box = box
var line := TalkLine.new()
line.text = "[i]The gate is barred.[/i]"
conversation.lines = [line]
return conversation
#endregion
#region say
# Nothing has to be authored anywhere. say() takes a string, a TalkLine, or a
# sequence of them, and runs them through the pipeline play() uses — same box,
# same placement, same events.
func bark(text: String) -> void:
$NPCTalkKit.say(text)
func interrupt(guard: TalkSpeaker) -> void:
var line := TalkLine.new()
line.text = "[color=#ff6b6b]Stop right there![/color]"
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = guard
$NPCTalkKit.say(line)
# Or name them by id, from the collections this node carries. An option is a
# selection, never a description: say() cannot build a speaker or restyle a box.
func interrupt_by_name() -> void:
$NPCTalkKit.say("[color=#ff6b6b]Stop right there![/color]",
{}, {"speaker": &"guard", "dialogue_box": &"warning"})
# The key is what counts, not the value. Leaving "speaker" out falls through to
# the Quick Say default; passing it as null says there is no speaker at all.
func narrate(text: String) -> void:
$NPCTalkKit.say(text, {}, {"speaker": null})
#endregion
func _build() -> void:
var talk := NPCTalkKit.new()
talk.name = "NPCTalkKit"
talk.dialogue_boxes = [_instant_box()]
add_child(talk)
func _verify() -> Array[String]:
var failures: Array[String] = []
var talk: NPCTalkKit = $NPCTalkKit
var haru := make_a_speaker()
var guard := TalkSpeaker.new()
guard.speaker_id = &"guard"
guard.display_name = "Guard"
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
var box: TalkBoxTemplate = talk.dialogue_boxes[0]
talk.speakers = [haru, guard, player]
talk.quick_say_speaker = haru
talk.quick_say_dialogue_box = box
var gate := a_conversation_with_three_people(haru, guard, player, box)
talk.conversations = [gate, a_sign_nobody_speaks(box)]
talk.play(&"gate")
for expected in ["Haru", "Guard", "Player", "Haru"]:
if talk._box.get_name_label().text != expected:
failures.append("speakers: expected %s, got '%s'"
% [expected, talk._box.get_name_label().text])
talk.advance()
if talk.is_running():
failures.append("speakers: the sequence should have finished")
# A named face, and a name that does not exist.
add_an_angry_face(haru, PlaceholderTexture2D.new())
shout_this_line(gate.lines[0])
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.variants[&"angry"]:
failures.append("speakers: a named variant should be chosen")
gate.lines[0].visual_variant = &"nonexistent"
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.visual:
failures.append("speakers: an unknown variant should fall back, not blank out")
gate.lines[0].visual_variant = &""
# Nobody speaking.
talk.play(&"sign")
if talk.resolve_speaker(talk.conversations[1].lines[0]) != null:
failures.append("speakers: a sign must resolve to no speaker")
if talk._box.get_name_label().visible:
failures.append("speakers: and show no name row")
talk.stop()
# Reusing game art, with no reference to any node.
var frames := SpriteFrames.new()
frames.add_animation(&"idle")
frames.add_frame(&"idle", PlaceholderTexture2D.new())
var reused := reuse_the_game_art(frames)
if reused.visual.frame_texture(0.0) == null:
failures.append("speakers: an animated visual must resolve a frame")
# say(), with nothing authored, falling through to the Quick Say defaults.
var blank := NPCTalkKit.new()
var quick := _instant_box()
blank.dialogue_boxes = [quick]
blank.speakers = [haru]
blank.quick_say_speaker = haru
blank.quick_say_dialogue_box = quick
add_child(blank)
if not blank.say("Just this."):
failures.append("speakers: say() must work on a node with no conversations")
if blank._box.get_name_label().text != "Haru":
failures.append("speakers: say() should fall through to the Quick Say speaker")
# ...and an explicit option beating it, including "explicitly nobody".
blank.stop()
blank.say("Three days later…", {}, {"speaker": null})
if not blank._box.get_name_label().text.is_empty():
failures.append("speakers: an explicit null speaker must mean narrator")
blank.stop()
blank.queue_free()
return failures
## Typing speed lives on the dialogue box, so a scripted run hands the node a
## box that types instantly.
func _instant_box() -> TalkBoxTemplate:
var template := TalkBoxTemplate.new()
template.typewriter_speed = 0.0
return templateNhiều người nói trong một hội thoại:
extends Node
## Docs: /guide/speakers — who is talking, how they look, how they sound.
func _ready() -> void:
_build()
#region speaker
# A speaker is a dialogue identity. No NodePath, no AnimationPlayer, no world
# sprite — so a narrator, a radio voice, or someone standing in a level that is
# not even loaded are all ordinary speakers.
func make_a_speaker() -> TalkSpeaker:
var haru := TalkSpeaker.new()
haru.speaker_id = &"haru"
haru.display_name = "Haru"
haru.visual = TalkDialogueVisual.new()
haru.visual.texture = preload("res://addons/npc_talkkit/icons/talk_speaker.svg")
haru.voice_blip = AudioStreamWAV.new()
return haru
#endregion
#region reuse
# Separate from the node is not the same as separate from the asset. Pointing a
# speaker at the very SpriteFrames the player already uses is the intended way
# to make the player a speaker — TalkKit never looks for the player node.
func reuse_the_game_art(frames: SpriteFrames) -> TalkSpeaker:
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
player.visual = TalkDialogueVisual.new()
player.visual.sprite_frames = frames
player.visual.animation = &"idle"
return player
#endregion
#region variants
# Named faces, not a free-text mood. A variant the speaker does not have falls
# back to their default face rather than drawing nothing.
func add_an_angry_face(haru: TalkSpeaker, angry: Texture2D) -> void:
var variant := TalkDialogueVisual.new()
variant.texture = angry
haru.variants[&"angry"] = variant
func shout_this_line(line: TalkLine) -> void:
line.visual_variant = &"angry"
#endregion
#region multi
# One conversation, several speakers, one straight sequence. The conversation
# says once who normally speaks; a line says so only when it is the exception,
# and the line after it goes back to the default without being told to.
func a_conversation_with_three_people(
haru: TalkSpeaker, guard: TalkSpeaker, player: TalkSpeaker, box: TalkBoxTemplate,
) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"gate"
conversation.default_speaker = haru
conversation.default_dialogue_box = box
for pair in [[null, "Who are you?"], [guard, "Step away."],
[player, "I am only passing through."], [null, "Let him go."]]:
var line := TalkLine.new()
if pair[0] != null:
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = pair[0]
line.text = pair[1]
conversation.lines.append(line)
return conversation
#endregion
#region nobody
# No speaker at all is a working configuration, not a gap. The text still
# types, events still fire; the name row and the visual just stay empty.
func a_sign_nobody_speaks(box: TalkBoxTemplate) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"sign"
conversation.default_speaker = null # nobody, and that is the point
conversation.default_dialogue_box = box
var line := TalkLine.new()
line.text = "[i]The gate is barred.[/i]"
conversation.lines = [line]
return conversation
#endregion
#region say
# Nothing has to be authored anywhere. say() takes a string, a TalkLine, or a
# sequence of them, and runs them through the pipeline play() uses — same box,
# same placement, same events.
func bark(text: String) -> void:
$NPCTalkKit.say(text)
func interrupt(guard: TalkSpeaker) -> void:
var line := TalkLine.new()
line.text = "[color=#ff6b6b]Stop right there![/color]"
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = guard
$NPCTalkKit.say(line)
# Or name them by id, from the collections this node carries. An option is a
# selection, never a description: say() cannot build a speaker or restyle a box.
func interrupt_by_name() -> void:
$NPCTalkKit.say("[color=#ff6b6b]Stop right there![/color]",
{}, {"speaker": &"guard", "dialogue_box": &"warning"})
# The key is what counts, not the value. Leaving "speaker" out falls through to
# the Quick Say default; passing it as null says there is no speaker at all.
func narrate(text: String) -> void:
$NPCTalkKit.say(text, {}, {"speaker": null})
#endregion
func _build() -> void:
var talk := NPCTalkKit.new()
talk.name = "NPCTalkKit"
talk.dialogue_boxes = [_instant_box()]
add_child(talk)
func _verify() -> Array[String]:
var failures: Array[String] = []
var talk: NPCTalkKit = $NPCTalkKit
var haru := make_a_speaker()
var guard := TalkSpeaker.new()
guard.speaker_id = &"guard"
guard.display_name = "Guard"
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
var box: TalkBoxTemplate = talk.dialogue_boxes[0]
talk.speakers = [haru, guard, player]
talk.quick_say_speaker = haru
talk.quick_say_dialogue_box = box
var gate := a_conversation_with_three_people(haru, guard, player, box)
talk.conversations = [gate, a_sign_nobody_speaks(box)]
talk.play(&"gate")
for expected in ["Haru", "Guard", "Player", "Haru"]:
if talk._box.get_name_label().text != expected:
failures.append("speakers: expected %s, got '%s'"
% [expected, talk._box.get_name_label().text])
talk.advance()
if talk.is_running():
failures.append("speakers: the sequence should have finished")
# A named face, and a name that does not exist.
add_an_angry_face(haru, PlaceholderTexture2D.new())
shout_this_line(gate.lines[0])
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.variants[&"angry"]:
failures.append("speakers: a named variant should be chosen")
gate.lines[0].visual_variant = &"nonexistent"
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.visual:
failures.append("speakers: an unknown variant should fall back, not blank out")
gate.lines[0].visual_variant = &""
# Nobody speaking.
talk.play(&"sign")
if talk.resolve_speaker(talk.conversations[1].lines[0]) != null:
failures.append("speakers: a sign must resolve to no speaker")
if talk._box.get_name_label().visible:
failures.append("speakers: and show no name row")
talk.stop()
# Reusing game art, with no reference to any node.
var frames := SpriteFrames.new()
frames.add_animation(&"idle")
frames.add_frame(&"idle", PlaceholderTexture2D.new())
var reused := reuse_the_game_art(frames)
if reused.visual.frame_texture(0.0) == null:
failures.append("speakers: an animated visual must resolve a frame")
# say(), with nothing authored, falling through to the Quick Say defaults.
var blank := NPCTalkKit.new()
var quick := _instant_box()
blank.dialogue_boxes = [quick]
blank.speakers = [haru]
blank.quick_say_speaker = haru
blank.quick_say_dialogue_box = quick
add_child(blank)
if not blank.say("Just this."):
failures.append("speakers: say() must work on a node with no conversations")
if blank._box.get_name_label().text != "Haru":
failures.append("speakers: say() should fall through to the Quick Say speaker")
# ...and an explicit option beating it, including "explicitly nobody".
blank.stop()
blank.say("Three days later…", {}, {"speaker": null})
if not blank._box.get_name_label().text.is_empty():
failures.append("speakers: an explicit null speaker must mean narrator")
blank.stop()
blank.queue_free()
return failures
## Typing speed lives on the dialogue box, so a scripted run hands the node a
## box that types instantly.
func _instant_box() -> TalkBoxTemplate:
var template := TalkBoxTemplate.new()
template.typewriter_speed = 0.0
return templateMột câu không ai nói:
extends Node
## Docs: /guide/speakers — who is talking, how they look, how they sound.
func _ready() -> void:
_build()
#region speaker
# A speaker is a dialogue identity. No NodePath, no AnimationPlayer, no world
# sprite — so a narrator, a radio voice, or someone standing in a level that is
# not even loaded are all ordinary speakers.
func make_a_speaker() -> TalkSpeaker:
var haru := TalkSpeaker.new()
haru.speaker_id = &"haru"
haru.display_name = "Haru"
haru.visual = TalkDialogueVisual.new()
haru.visual.texture = preload("res://addons/npc_talkkit/icons/talk_speaker.svg")
haru.voice_blip = AudioStreamWAV.new()
return haru
#endregion
#region reuse
# Separate from the node is not the same as separate from the asset. Pointing a
# speaker at the very SpriteFrames the player already uses is the intended way
# to make the player a speaker — TalkKit never looks for the player node.
func reuse_the_game_art(frames: SpriteFrames) -> TalkSpeaker:
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
player.visual = TalkDialogueVisual.new()
player.visual.sprite_frames = frames
player.visual.animation = &"idle"
return player
#endregion
#region variants
# Named faces, not a free-text mood. A variant the speaker does not have falls
# back to their default face rather than drawing nothing.
func add_an_angry_face(haru: TalkSpeaker, angry: Texture2D) -> void:
var variant := TalkDialogueVisual.new()
variant.texture = angry
haru.variants[&"angry"] = variant
func shout_this_line(line: TalkLine) -> void:
line.visual_variant = &"angry"
#endregion
#region multi
# One conversation, several speakers, one straight sequence. The conversation
# says once who normally speaks; a line says so only when it is the exception,
# and the line after it goes back to the default without being told to.
func a_conversation_with_three_people(
haru: TalkSpeaker, guard: TalkSpeaker, player: TalkSpeaker, box: TalkBoxTemplate,
) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"gate"
conversation.default_speaker = haru
conversation.default_dialogue_box = box
for pair in [[null, "Who are you?"], [guard, "Step away."],
[player, "I am only passing through."], [null, "Let him go."]]:
var line := TalkLine.new()
if pair[0] != null:
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = pair[0]
line.text = pair[1]
conversation.lines.append(line)
return conversation
#endregion
#region nobody
# No speaker at all is a working configuration, not a gap. The text still
# types, events still fire; the name row and the visual just stay empty.
func a_sign_nobody_speaks(box: TalkBoxTemplate) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"sign"
conversation.default_speaker = null # nobody, and that is the point
conversation.default_dialogue_box = box
var line := TalkLine.new()
line.text = "[i]The gate is barred.[/i]"
conversation.lines = [line]
return conversation
#endregion
#region say
# Nothing has to be authored anywhere. say() takes a string, a TalkLine, or a
# sequence of them, and runs them through the pipeline play() uses — same box,
# same placement, same events.
func bark(text: String) -> void:
$NPCTalkKit.say(text)
func interrupt(guard: TalkSpeaker) -> void:
var line := TalkLine.new()
line.text = "[color=#ff6b6b]Stop right there![/color]"
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = guard
$NPCTalkKit.say(line)
# Or name them by id, from the collections this node carries. An option is a
# selection, never a description: say() cannot build a speaker or restyle a box.
func interrupt_by_name() -> void:
$NPCTalkKit.say("[color=#ff6b6b]Stop right there![/color]",
{}, {"speaker": &"guard", "dialogue_box": &"warning"})
# The key is what counts, not the value. Leaving "speaker" out falls through to
# the Quick Say default; passing it as null says there is no speaker at all.
func narrate(text: String) -> void:
$NPCTalkKit.say(text, {}, {"speaker": null})
#endregion
func _build() -> void:
var talk := NPCTalkKit.new()
talk.name = "NPCTalkKit"
talk.dialogue_boxes = [_instant_box()]
add_child(talk)
func _verify() -> Array[String]:
var failures: Array[String] = []
var talk: NPCTalkKit = $NPCTalkKit
var haru := make_a_speaker()
var guard := TalkSpeaker.new()
guard.speaker_id = &"guard"
guard.display_name = "Guard"
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
var box: TalkBoxTemplate = talk.dialogue_boxes[0]
talk.speakers = [haru, guard, player]
talk.quick_say_speaker = haru
talk.quick_say_dialogue_box = box
var gate := a_conversation_with_three_people(haru, guard, player, box)
talk.conversations = [gate, a_sign_nobody_speaks(box)]
talk.play(&"gate")
for expected in ["Haru", "Guard", "Player", "Haru"]:
if talk._box.get_name_label().text != expected:
failures.append("speakers: expected %s, got '%s'"
% [expected, talk._box.get_name_label().text])
talk.advance()
if talk.is_running():
failures.append("speakers: the sequence should have finished")
# A named face, and a name that does not exist.
add_an_angry_face(haru, PlaceholderTexture2D.new())
shout_this_line(gate.lines[0])
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.variants[&"angry"]:
failures.append("speakers: a named variant should be chosen")
gate.lines[0].visual_variant = &"nonexistent"
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.visual:
failures.append("speakers: an unknown variant should fall back, not blank out")
gate.lines[0].visual_variant = &""
# Nobody speaking.
talk.play(&"sign")
if talk.resolve_speaker(talk.conversations[1].lines[0]) != null:
failures.append("speakers: a sign must resolve to no speaker")
if talk._box.get_name_label().visible:
failures.append("speakers: and show no name row")
talk.stop()
# Reusing game art, with no reference to any node.
var frames := SpriteFrames.new()
frames.add_animation(&"idle")
frames.add_frame(&"idle", PlaceholderTexture2D.new())
var reused := reuse_the_game_art(frames)
if reused.visual.frame_texture(0.0) == null:
failures.append("speakers: an animated visual must resolve a frame")
# say(), with nothing authored, falling through to the Quick Say defaults.
var blank := NPCTalkKit.new()
var quick := _instant_box()
blank.dialogue_boxes = [quick]
blank.speakers = [haru]
blank.quick_say_speaker = haru
blank.quick_say_dialogue_box = quick
add_child(blank)
if not blank.say("Just this."):
failures.append("speakers: say() must work on a node with no conversations")
if blank._box.get_name_label().text != "Haru":
failures.append("speakers: say() should fall through to the Quick Say speaker")
# ...and an explicit option beating it, including "explicitly nobody".
blank.stop()
blank.say("Three days later…", {}, {"speaker": null})
if not blank._box.get_name_label().text.is_empty():
failures.append("speakers: an explicit null speaker must mean narrator")
blank.stop()
blank.queue_free()
return failures
## Typing speed lives on the dialogue box, so a scripted run hands the node a
## box that types instantly.
func _instant_box() -> TalkBoxTemplate:
var template := TalkBoxTemplate.new()
template.typewriter_speed = 0.0
return templatesay() với danh sách câu:
extends Node
## Docs: /guide/speakers — who is talking, how they look, how they sound.
func _ready() -> void:
_build()
#region speaker
# A speaker is a dialogue identity. No NodePath, no AnimationPlayer, no world
# sprite — so a narrator, a radio voice, or someone standing in a level that is
# not even loaded are all ordinary speakers.
func make_a_speaker() -> TalkSpeaker:
var haru := TalkSpeaker.new()
haru.speaker_id = &"haru"
haru.display_name = "Haru"
haru.visual = TalkDialogueVisual.new()
haru.visual.texture = preload("res://addons/npc_talkkit/icons/talk_speaker.svg")
haru.voice_blip = AudioStreamWAV.new()
return haru
#endregion
#region reuse
# Separate from the node is not the same as separate from the asset. Pointing a
# speaker at the very SpriteFrames the player already uses is the intended way
# to make the player a speaker — TalkKit never looks for the player node.
func reuse_the_game_art(frames: SpriteFrames) -> TalkSpeaker:
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
player.visual = TalkDialogueVisual.new()
player.visual.sprite_frames = frames
player.visual.animation = &"idle"
return player
#endregion
#region variants
# Named faces, not a free-text mood. A variant the speaker does not have falls
# back to their default face rather than drawing nothing.
func add_an_angry_face(haru: TalkSpeaker, angry: Texture2D) -> void:
var variant := TalkDialogueVisual.new()
variant.texture = angry
haru.variants[&"angry"] = variant
func shout_this_line(line: TalkLine) -> void:
line.visual_variant = &"angry"
#endregion
#region multi
# One conversation, several speakers, one straight sequence. The conversation
# says once who normally speaks; a line says so only when it is the exception,
# and the line after it goes back to the default without being told to.
func a_conversation_with_three_people(
haru: TalkSpeaker, guard: TalkSpeaker, player: TalkSpeaker, box: TalkBoxTemplate,
) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"gate"
conversation.default_speaker = haru
conversation.default_dialogue_box = box
for pair in [[null, "Who are you?"], [guard, "Step away."],
[player, "I am only passing through."], [null, "Let him go."]]:
var line := TalkLine.new()
if pair[0] != null:
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = pair[0]
line.text = pair[1]
conversation.lines.append(line)
return conversation
#endregion
#region nobody
# No speaker at all is a working configuration, not a gap. The text still
# types, events still fire; the name row and the visual just stay empty.
func a_sign_nobody_speaks(box: TalkBoxTemplate) -> TalkConversation:
var conversation := TalkConversation.new()
conversation.conversation_id = &"sign"
conversation.default_speaker = null # nobody, and that is the point
conversation.default_dialogue_box = box
var line := TalkLine.new()
line.text = "[i]The gate is barred.[/i]"
conversation.lines = [line]
return conversation
#endregion
#region say
# Nothing has to be authored anywhere. say() takes a string, a TalkLine, or a
# sequence of them, and runs them through the pipeline play() uses — same box,
# same placement, same events.
func bark(text: String) -> void:
$NPCTalkKit.say(text)
func interrupt(guard: TalkSpeaker) -> void:
var line := TalkLine.new()
line.text = "[color=#ff6b6b]Stop right there![/color]"
line.speaker_mode = TalkLine.SpeakerMode.SPEAKER
line.speaker = guard
$NPCTalkKit.say(line)
# Or name them by id, from the collections this node carries. An option is a
# selection, never a description: say() cannot build a speaker or restyle a box.
func interrupt_by_name() -> void:
$NPCTalkKit.say("[color=#ff6b6b]Stop right there![/color]",
{}, {"speaker": &"guard", "dialogue_box": &"warning"})
# The key is what counts, not the value. Leaving "speaker" out falls through to
# the Quick Say default; passing it as null says there is no speaker at all.
func narrate(text: String) -> void:
$NPCTalkKit.say(text, {}, {"speaker": null})
#endregion
func _build() -> void:
var talk := NPCTalkKit.new()
talk.name = "NPCTalkKit"
talk.dialogue_boxes = [_instant_box()]
add_child(talk)
func _verify() -> Array[String]:
var failures: Array[String] = []
var talk: NPCTalkKit = $NPCTalkKit
var haru := make_a_speaker()
var guard := TalkSpeaker.new()
guard.speaker_id = &"guard"
guard.display_name = "Guard"
var player := TalkSpeaker.new()
player.speaker_id = &"player"
player.display_name = "Player"
var box: TalkBoxTemplate = talk.dialogue_boxes[0]
talk.speakers = [haru, guard, player]
talk.quick_say_speaker = haru
talk.quick_say_dialogue_box = box
var gate := a_conversation_with_three_people(haru, guard, player, box)
talk.conversations = [gate, a_sign_nobody_speaks(box)]
talk.play(&"gate")
for expected in ["Haru", "Guard", "Player", "Haru"]:
if talk._box.get_name_label().text != expected:
failures.append("speakers: expected %s, got '%s'"
% [expected, talk._box.get_name_label().text])
talk.advance()
if talk.is_running():
failures.append("speakers: the sequence should have finished")
# A named face, and a name that does not exist.
add_an_angry_face(haru, PlaceholderTexture2D.new())
shout_this_line(gate.lines[0])
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.variants[&"angry"]:
failures.append("speakers: a named variant should be chosen")
gate.lines[0].visual_variant = &"nonexistent"
if talk.resolve_dialogue_visual(haru, gate.lines[0]) != haru.visual:
failures.append("speakers: an unknown variant should fall back, not blank out")
gate.lines[0].visual_variant = &""
# Nobody speaking.
talk.play(&"sign")
if talk.resolve_speaker(talk.conversations[1].lines[0]) != null:
failures.append("speakers: a sign must resolve to no speaker")
if talk._box.get_name_label().visible:
failures.append("speakers: and show no name row")
talk.stop()
# Reusing game art, with no reference to any node.
var frames := SpriteFrames.new()
frames.add_animation(&"idle")
frames.add_frame(&"idle", PlaceholderTexture2D.new())
var reused := reuse_the_game_art(frames)
if reused.visual.frame_texture(0.0) == null:
failures.append("speakers: an animated visual must resolve a frame")
# say(), with nothing authored, falling through to the Quick Say defaults.
var blank := NPCTalkKit.new()
var quick := _instant_box()
blank.dialogue_boxes = [quick]
blank.speakers = [haru]
blank.quick_say_speaker = haru
blank.quick_say_dialogue_box = quick
add_child(blank)
if not blank.say("Just this."):
failures.append("speakers: say() must work on a node with no conversations")
if blank._box.get_name_label().text != "Haru":
failures.append("speakers: say() should fall through to the Quick Say speaker")
# ...and an explicit option beating it, including "explicitly nobody".
blank.stop()
blank.say("Three days later…", {}, {"speaker": null})
if not blank._box.get_name_label().text.is_empty():
failures.append("speakers: an explicit null speaker must mean narrator")
blank.stop()
blank.queue_free()
return failures
## Typing speed lives on the dialogue box, so a scripted run hands the node a
## box that types instantly.
func _instant_box() -> TalkBoxTemplate:
var template := TalkBoxTemplate.new()
template.typewriter_speed = 0.0
return template