Talking-head dialogue: DialogueDirector, DialogueBox, conversations and speakers
Conversations saved in game/resources/dialogue/ play once at their night and phase in a paper box with talking heads; example: the morning of day 2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
bbd8012fff
commit
1d92f49d96
22 changed files with 1158 additions and 2 deletions
|
|
@ -24,6 +24,7 @@ const SUITES := [
|
|||
"res://game/tests/test_flow.gd",
|
||||
"res://game/tests/test_coop.gd",
|
||||
"res://game/tests/test_look.gd",
|
||||
"res://game/tests/test_dialogue.gd",
|
||||
]
|
||||
const TICK := 1.0 / 60.0
|
||||
## Points on the farm's edge (FarmZones.edge) for tests that send an enemy in from a known side:
|
||||
|
|
|
|||
281
game/tests/test_dialogue.gd
Normal file
281
game/tests/test_dialogue.gd
Normal file
|
|
@ -0,0 +1,281 @@
|
|||
extends RefCounted
|
||||
## The talking-head conversations on the real farm: every conversation saved in game/resources/
|
||||
## dialogue/ is sound; the box (DialogueBox) writes a line letter by letter (a beat after a full
|
||||
## stop), goes on and skips by input, styles the words (speaker, line, BBCode), and puts each
|
||||
## speaker's head on their side; the director (DialogueDirector) plays a conversation at its
|
||||
## night's phase and delay, pauses the farm for it and lets it go after, puts the morning sign
|
||||
## aside meanwhile, doesn't replay it on a retry but does on a new vacation,
|
||||
## takes it down on a new morning, plays several in order, waits under a menu, and lets one that
|
||||
## doesn't pause the game go on by itself.
|
||||
|
||||
const P := CampaignController.Phase
|
||||
const DT := 1.0 / 60.0
|
||||
|
||||
var r: GameTestRunner
|
||||
var sim: FarmSim
|
||||
var c: CampaignController
|
||||
var director: DialogueDirector
|
||||
var box: DialogueBox
|
||||
var alien: DialogueSpeaker
|
||||
var scarecrow: DialogueSpeaker
|
||||
|
||||
|
||||
func run(p_r: GameTestRunner) -> void:
|
||||
r = p_r
|
||||
_saved()
|
||||
var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D
|
||||
r.root.add_child(farm)
|
||||
await r.process_frame
|
||||
await r.physics_frame
|
||||
sim = farm.get_node("FarmSim") as FarmSim
|
||||
sim.set_physics_process(false)
|
||||
c = sim.campaign
|
||||
director = sim.dialogue
|
||||
r.check(director != null and director.box != null and director.box.get_parent() == farm.get_node("Hud"),
|
||||
"the farm has a dialogue director, its box in the HUD")
|
||||
if director == null:
|
||||
farm.queue_free()
|
||||
return
|
||||
box = director.box
|
||||
director.conversations.clear() # this suite's own conversations only
|
||||
alien = _speaker("Little Green Alien", DialogueSpeaker.HeadSide.LEFT, "thief")
|
||||
scarecrow = _speaker("Scarecrow", DialogueSpeaker.HeadSide.RIGHT, "portrait")
|
||||
_writing()
|
||||
_input()
|
||||
_style()
|
||||
await _triggers()
|
||||
_order_and_menus()
|
||||
_not_paused()
|
||||
director.stop()
|
||||
r.paused = false
|
||||
farm.queue_free()
|
||||
await r.process_frame
|
||||
|
||||
|
||||
## Every conversation saved with the game loads, has lines with words, and plays within the vacation.
|
||||
func _saved() -> void:
|
||||
var all := DialogueDirector.load_all(DialogueDirector.DIR)
|
||||
var nights: int = (load("res://game/resources/game_config.tres") as GameConfig).campaign_nights
|
||||
var bad: Array[String] = []
|
||||
for conv in all:
|
||||
if conv.lines.is_empty() or conv.night < 1 or conv.night > nights:
|
||||
bad.append(conv.resource_path)
|
||||
for line in conv.lines:
|
||||
if line == null or line.text.strip_edges() == "":
|
||||
bad.append(conv.resource_path)
|
||||
r.check(bad.is_empty(), "every saved conversation has lines with words and plays within the vacation (bad: %s)" % [bad])
|
||||
r.check(DialogueDirector.load_all("res://game/resources/dialogue/speakers/").is_empty(),
|
||||
"a speaker's file isn't taken for a conversation")
|
||||
|
||||
|
||||
func _writing() -> void:
|
||||
var conv := _conversation(1, P.MORNING, 0.0, [_line(alien, "Hi. There"), _line(scarecrow, "Hello!")])
|
||||
alien.letters_per_second = 10.0
|
||||
r.check(box.play(conv) and box.is_playing() and box.visible and box.written_text() == "" and box.speaker_name() == "Little Green Alien",
|
||||
"play() puts the first line up, nothing written yet, under the speaker's name")
|
||||
r.check(not box.play(_conversation(1, P.MORNING, 0.0, [])) and box.conversation == conv, "a conversation without lines isn't shown")
|
||||
_frames(0.25)
|
||||
r.check(box.written_text() == "Hi", "letters come at the speaker's speed (10 a second: '%s' after 0.25 s)" % box.written_text())
|
||||
_frames(0.2)
|
||||
var at_stop := box.written_text()
|
||||
_frames(0.2)
|
||||
r.check(at_stop == "Hi." and box.written_text() == "Hi.", "a beat after a full stop ('%s', still '%s' 0.2 s on)" % [at_stop, box.written_text()])
|
||||
_frames(0.5)
|
||||
r.check(box.written_text().begins_with("Hi. T"), "then the words go on ('%s')" % box.written_text())
|
||||
box.advance()
|
||||
r.check(box.is_written() and box.written_text() == "Hi. There" and box.index == 0, "going on mid-line writes the rest of it")
|
||||
box.advance()
|
||||
r.check(box.index == 1 and box.speaker_name() == "Scarecrow", "going on again: the next line, the next speaker")
|
||||
r.check(box._heads.size() == 2 and box._heads[0].leaving and box._heads[1].speaker == scarecrow,
|
||||
"the new speaker's head comes up; the last one's goes down")
|
||||
var done: Array[Conversation] = []
|
||||
box.finished.connect(func(f: Conversation) -> void: done.append(f), CONNECT_ONE_SHOT)
|
||||
box.advance()
|
||||
box.advance()
|
||||
r.check(done.size() == 1 and done[0] == conv and not box.is_playing(), "after the last line the conversation is finished")
|
||||
_frames(0.6)
|
||||
r.check(not box.visible and box._heads.is_empty(), "and the box fades away, the head sinking")
|
||||
alien.letters_per_second = 45.0
|
||||
|
||||
|
||||
func _input() -> void:
|
||||
var conv := _conversation(1, P.MORNING, 0.0, [_line(alien, "One"), _line(alien, "Two"), _line(alien, "Three")])
|
||||
box.play(conv)
|
||||
r.check(box.mouse_filter == Control.MOUSE_FILTER_STOP and box.has_focus(), "a conversation that pauses the game takes the clicks and the keys")
|
||||
var click := InputEventMouseButton.new()
|
||||
click.button_index = MOUSE_BUTTON_LEFT
|
||||
click.pressed = true
|
||||
box._gui_input(click)
|
||||
r.check(box.is_written() and box.index == 0, "a click writes the rest of the line")
|
||||
box._gui_input(_action("ui_accept"))
|
||||
r.check(box.index == 1, "Enter (ui_accept) goes on to the next")
|
||||
box.blocked = func() -> bool: return true
|
||||
box._gui_input(_action("ui_accept"))
|
||||
box._gui_input(_action("ui_accept"))
|
||||
_frames(1.0)
|
||||
r.check(box.index == 1 and box.written_text() == "", "under a menu (blocked) it takes no input and writes nothing")
|
||||
box.blocked = Callable()
|
||||
box._gui_input(_action("hide_tips"))
|
||||
r.check(not box.is_playing(), "Backspace (hide_tips) skips the rest of the conversation")
|
||||
r.check(box.mouse_filter == Control.MOUSE_FILTER_IGNORE and not box.has_focus(), "and lets the clicks and keys go again")
|
||||
box.stop()
|
||||
|
||||
|
||||
func _style() -> void:
|
||||
var line := _line(scarecrow, "I [b]said[/b] go.")
|
||||
line.italic = true
|
||||
line.font_size = 50
|
||||
line.text_color = Color.RED
|
||||
box.play(_conversation(1, P.MORNING, 0.0, [line, _line(null, "The wind blows.")]))
|
||||
var t := box._text
|
||||
r.check(t.text == "[i]I [b]said[/b] go.[/i]" and box._plain == "I said go.", "a line in italics, its BBCode kept ('%s')" % t.text)
|
||||
r.check(t.get_theme_font_size("normal_font_size") == 50 and t.get_theme_color("default_color") == Color.RED,
|
||||
"a line's size and color over the speaker's")
|
||||
r.check(t.get_theme_font("italics_font") is FontVariation and (t.get_theme_font("italics_font") as FontVariation).base_font == Sketch.font(),
|
||||
"italics are the handwritten font, slanted")
|
||||
r.check(box._name.horizontal_alignment == HORIZONTAL_ALIGNMENT_RIGHT and t.horizontal_alignment == HORIZONTAL_ALIGNMENT_RIGHT,
|
||||
"a speaker on the right has their name and words on the right")
|
||||
_frames(0.5)
|
||||
var head := box._current_head()
|
||||
var r_sheet := box._sheet_rect()
|
||||
r.check(head != null and head.speaker == scarecrow and head.risen == 1.0 and r_sheet.size.x == DialogueBox.WIDTH
|
||||
and absf(r_sheet.end.y - (box.size.y - DialogueBox.BOTTOM)) < 0.01, "their head is up, the paper over the hotbar")
|
||||
box.advance()
|
||||
box.advance()
|
||||
r.check(box.speaker_name() == "" and not box._name.visible and box._current_head() == null, "a line without a speaker: words only")
|
||||
box.stop()
|
||||
|
||||
|
||||
func _triggers() -> void:
|
||||
var morning := _conversation(2, P.MORNING, 0.0, [_line(alien, "Morning.")])
|
||||
var night := _conversation(2, P.NIGHT, 5.0, [_line(scarecrow, "Night.")])
|
||||
director.conversations.assign([morning, night])
|
||||
c.new_campaign()
|
||||
_tick()
|
||||
r.check(not box.is_playing(), "night 1: nothing to say")
|
||||
_to_morning(2)
|
||||
await r.process_frame # the morning sign takes the focus (deferred)
|
||||
await r.process_frame
|
||||
_tick()
|
||||
r.check(box.conversation == morning and r.paused, "the morning of day 2: its conversation, the farm paused")
|
||||
r.check(box.has_focus() and not sim.review_panel.visible, "the morning sign waits; the box has the keys (Enter doesn't start the day)")
|
||||
box.skip()
|
||||
r.check(not r.paused and not director.is_playing() and sim.review_panel.visible, "done: the farm goes on, the morning sign is back")
|
||||
await r.process_frame
|
||||
r.check(sim.review_panel._start.has_focus(), "with Start the day focused")
|
||||
c.retry_night()
|
||||
_tick()
|
||||
r.check(not box.is_playing(), "a retry doesn't play it again")
|
||||
c.begin_day()
|
||||
c.advance_phase()
|
||||
c.advance_phase()
|
||||
_tick()
|
||||
r.check(c.state.phase == P.NIGHT and not box.is_playing(), "the night's conversation waits for its delay")
|
||||
c.state.phase_time_left = c.phase_length(P.NIGHT) - 5.5
|
||||
_tick()
|
||||
r.check(box.conversation == night and r.paused, "5 s into night 2: it plays")
|
||||
c.retry_night()
|
||||
r.check(not box.is_playing() and not r.paused, "a new morning (here a retry) takes it down")
|
||||
c.new_campaign()
|
||||
_to_morning(2)
|
||||
_tick()
|
||||
r.check(box.conversation == morning, "a new vacation plays them again")
|
||||
director.stop()
|
||||
|
||||
|
||||
func _order_and_menus() -> void:
|
||||
var late := _conversation(3, P.MORNING, 2.0, [_line(alien, "Second.")])
|
||||
var early := _conversation(3, P.MORNING, 1.0, [_line(alien, "First.")])
|
||||
var asked := _conversation(1, P.MORNING, 0.0, [_line(scarecrow, "Asked.")])
|
||||
director.conversations.assign([late, early])
|
||||
_to_morning(3)
|
||||
_tick()
|
||||
r.check(box.conversation == early, "several at once: by delay")
|
||||
director.play(asked)
|
||||
box.skip()
|
||||
r.check(box.conversation == asked and r.paused, "play() while one is up: right after it, the farm still paused")
|
||||
box.skip()
|
||||
r.check(box.conversation == late, "then the rest")
|
||||
box.skip()
|
||||
r.check(not director.is_playing() and not r.paused, "then the farm goes on")
|
||||
director.conversations.assign([_conversation(4, P.MORNING, 0.0, [_line(alien, "Wait.")])])
|
||||
box.blocked = func() -> bool: return true
|
||||
_to_morning(4)
|
||||
_tick()
|
||||
r.check(not box.is_playing(), "under Main's menus nothing starts")
|
||||
box.blocked = Callable()
|
||||
sim.upgrade_panel.is_open = true
|
||||
_tick()
|
||||
r.check(not box.is_playing(), "nor while a shop is open")
|
||||
sim.upgrade_panel.is_open = false
|
||||
_tick()
|
||||
r.check(box.is_playing(), "after them, it does")
|
||||
box.skip()
|
||||
director.replay()
|
||||
r.check(box.is_playing(), "replay() plays this phase's again")
|
||||
director.stop()
|
||||
|
||||
|
||||
func _not_paused() -> void:
|
||||
var conv := _conversation(5, P.MORNING, 0.0, [_line(alien, "Busy?"), _line(alien, "Never mind.")])
|
||||
conv.pause_game = false
|
||||
director.conversations.assign([conv])
|
||||
_to_morning(5)
|
||||
_tick()
|
||||
r.check(box.conversation == conv and not r.paused and box.mouse_filter == Control.MOUSE_FILTER_IGNORE and not box.has_focus(),
|
||||
"one that doesn't pause the game takes no clicks or keys")
|
||||
box._gui_input(_action("ui_accept"))
|
||||
r.check(box.index == 0, "Enter is the game's")
|
||||
_frames(0.5 + Conversation.AUTO_ADVANCE)
|
||||
r.check(box.index == 1, "its lines go on by themselves")
|
||||
_frames(0.5 + Conversation.AUTO_ADVANCE)
|
||||
r.check(not box.is_playing(), "and it ends by itself")
|
||||
|
||||
|
||||
func _to_morning(n: int) -> void:
|
||||
var s := c.state
|
||||
s.night = n
|
||||
s.nights_survived = n - 1
|
||||
c.load_state(s)
|
||||
|
||||
|
||||
## The director's frame (it starts what's due).
|
||||
func _tick() -> void:
|
||||
director._process(DT)
|
||||
|
||||
|
||||
## The box's frames for seconds.
|
||||
func _frames(seconds: float) -> void:
|
||||
for i in roundi(seconds / DT):
|
||||
box._process(DT)
|
||||
|
||||
|
||||
func _action(name: String) -> InputEventAction:
|
||||
var e := InputEventAction.new()
|
||||
e.action = StringName(name)
|
||||
e.pressed = true
|
||||
return e
|
||||
|
||||
|
||||
static func _speaker(n: String, side: DialogueSpeaker.HeadSide, icon: String) -> DialogueSpeaker:
|
||||
var sp := DialogueSpeaker.new()
|
||||
sp.display_name = n
|
||||
sp.side = side
|
||||
sp.icon = icon
|
||||
return sp
|
||||
|
||||
|
||||
static func _line(sp: DialogueSpeaker, text: String) -> DialogueLine:
|
||||
var l := DialogueLine.new()
|
||||
l.speaker = sp
|
||||
l.text = text
|
||||
return l
|
||||
|
||||
|
||||
static func _conversation(n: int, phase: CampaignController.Phase, delay: float, lines: Array[DialogueLine]) -> Conversation:
|
||||
var conv := Conversation.new()
|
||||
conv.night = n
|
||||
conv.phase = int(phase) as Conversation.Phase
|
||||
conv.delay = delay
|
||||
conv.lines = lines
|
||||
return conv
|
||||
1
game/tests/test_dialogue.gd.uid
Normal file
1
game/tests/test_dialogue.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://2v2ctiydeo6v
|
||||
Loading…
Add table
Add a link
Reference in a new issue