OpeningIntro (game/scripts/opening_intro.gd) plays on every New vacation (not Continue, not when hosting co-op): the farmers leave in their loaded station wagon, "Later that night....", a bickering UFO crew drops a part whose blue flash brings the scarecrow (hung on a post in its T-pose) to life, the UFO zooms off, then the loading screen and the first morning's sign. Hold Space / Enter / A (or E, or the mouse button) 1 s to skip from any stage; Escape pauses it; Restart the night skips it; Save & quit clears it. It ends with the farm exactly as new_campaign() leaves it. Hooks: ReviewPanel keeps the sign down while the intro has the farm (and only focuses Start when the sign is up); DialogueDirector holds its conversations and the sign, then intro_over() plays night 1's morning conversations before the sign; Tutorial hides; FarmAudio gets set_scene / end_scene (ambience and music held by a cutscene) and stop_cue (the morning stinger plays with the sign instead); Main wires new_vacation(intro), blocked, resume's freeze, restart and to_menu. Tests: test_intro (45 checks); test_flow skips the new intro. Tool: game/tools/capture_intro.gd saves a frame per stage for the timing review. Docs: README, RULES, LAYOUT (staging points), PLAYTEST. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
273 lines
12 KiB
GDScript
273 lines
12 KiB
GDScript
extends RefCounted
|
|
## The opening intro (OpeningIntro) through the game's entry scene (main.tscn, with test save and
|
|
## settings paths): New vacation plays it, Continue and hosting co-op don't. Stepped through, it
|
|
## visits every stage in order while it holds the farm (no morning sign, no HUD, the scarecrow
|
|
## frozen on its post without its glow, the light forced), and it ends on the first morning's sign
|
|
## (focused) with the farm exactly as new_campaign() leaves it. Skipping it from any stage
|
|
## (pressing or holding), Restart the night, and Save & quit to menu leave it just as clean.
|
|
|
|
const SAVE := "user://test_intro_save.json"
|
|
const SETTINGS := "user://test_intro_settings.cfg"
|
|
const DT := 1.0 / 30.0
|
|
const LIMIT := 120.0 # seconds of stepping before a run counts as stuck
|
|
|
|
var r: GameTestRunner
|
|
var main: Main
|
|
var sim: FarmSim
|
|
var intro: OpeningIntro
|
|
|
|
|
|
func run(p_r: GameTestRunner) -> void:
|
|
r = p_r
|
|
_clean()
|
|
main = (load("res://game/scenes/main.tscn") as PackedScene).instantiate() as Main
|
|
main.save_path = SAVE
|
|
main.settings_path = SETTINGS
|
|
r.root.add_child(main)
|
|
await r.process_frame
|
|
await r.physics_frame
|
|
sim = main.sim
|
|
intro = sim.intro
|
|
intro.set_process(false) # stepped by hand
|
|
await _new_and_continue()
|
|
await _whole_intro()
|
|
await _skips()
|
|
await _hold_to_skip()
|
|
await _restart_and_quit()
|
|
await _hosting()
|
|
main.queue_free()
|
|
r.paused = false
|
|
await r.process_frame
|
|
_clean()
|
|
|
|
|
|
func _clean() -> void:
|
|
for p in [SAVE, SAVE + ".tmp", SETTINGS]:
|
|
if FileAccess.file_exists(p):
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(p))
|
|
|
|
|
|
func _hud_visible() -> bool:
|
|
return (main.farm.get_node("Hud") as CanvasLayer).visible
|
|
|
|
|
|
## New vacation (from the menu; it asks over a save).
|
|
func _new_vacation() -> void:
|
|
main.main_menu.new_button.pressed.emit()
|
|
if main.confirm.is_open:
|
|
main.confirm.yes_button.pressed.emit()
|
|
|
|
|
|
## Steps until the stage is `until` (or it's over); returns false if it never got there.
|
|
func _step_to(until: String) -> bool:
|
|
var t := 0.0
|
|
while intro.stage != until and not intro.done and t < LIMIT:
|
|
intro.step(DT)
|
|
t += DT
|
|
return intro.stage == until
|
|
|
|
|
|
func _step_to_end() -> bool:
|
|
var t := 0.0
|
|
while intro.busy() and t < LIMIT:
|
|
intro.step(DT)
|
|
t += DT
|
|
return intro.done
|
|
|
|
|
|
## The farm held by the intro: no sign, no HUD, the intro's camera, the scarecrow frozen.
|
|
func _held() -> bool:
|
|
return intro.running and not sim.review_panel.visible and not _hud_visible() and sim.local_frozen \
|
|
and not sim.player.input_enabled and not sim.player.is_physics_processing() \
|
|
and main.get_viewport().get_camera_3d() != sim.camera
|
|
|
|
|
|
## The farm as new_campaign() leaves it, and the first morning's sign up (focused).
|
|
func _check_clean(what: String) -> void:
|
|
var p := sim.player
|
|
var dn := sim.day_night
|
|
var morning := DayNight.morning()
|
|
var light := dn.forced == "" and not dn.lanterns_dark and is_equal_approx(float(dn.current["elev"]), float(morning["elev"])) \
|
|
and is_equal_approx(float(dn.current["energy"]), float(morning["energy"])) \
|
|
and is_equal_approx(float(dn.target()["energy"]), float(morning["energy"]))
|
|
var body := p.global_position.distance_to(OpeningIntro.START) < 0.01 and is_zero_approx(p.model.rotation.y) \
|
|
and p.is_physics_processing() and p.input_enabled and not sim.local_frozen and p.core_glow.visible \
|
|
and p.find_children("*", "LookAtModifier3D", true, false).is_empty() and sim.scarecrow.alive and sim.combat.show_marker
|
|
var gone := intro.done and not intro.running and intro.stage == "end" and intro.get_child_count() == 0
|
|
var screen := _hud_visible() and main.get_viewport().get_camera_3d() == sim.camera and sim.review_panel.visible \
|
|
and sim.campaign.state.phase == CampaignController.Phase.MORNING and sim.campaign.state.night == 1
|
|
var sound := sim.audio.focus == p and not sim.audio.scene and sim.audio.music_track == "farm"
|
|
await r.process_frame
|
|
await r.process_frame
|
|
var focus := sim.review_panel._start.has_focus()
|
|
r.check(gone and body and light and screen and sound and focus,
|
|
"%s: the farm's as new_campaign() left it (intro gone %s, scarecrow at its start with input and glow %s, the morning light %s, HUD / game camera / sign %s, sounds %s, Start focused %s)"
|
|
% [what, gone, body, light, screen, sound, focus])
|
|
|
|
|
|
## New vacation plays it, holding the farm; Save & quit to menu takes it down; Continue doesn't
|
|
## play it.
|
|
func _new_and_continue() -> void:
|
|
_new_vacation()
|
|
r.check(main.screen == Main.Screen.PLAYING and intro.running and intro.stage == "leave" and _held(),
|
|
"New vacation starts the intro: no sign, no HUD, its own camera, the scarecrow frozen")
|
|
var p := sim.player
|
|
var on_post := absf(p.global_position.y - OpeningIntro.POST_LIFT) < 0.2 and not p.core_glow.visible \
|
|
and not p.animation_player.is_playing() and sim.day_night.forced == "morning" and sim.day_night.lanterns_dark \
|
|
and not sim.scarecrow.alive and not sim.combat.show_marker
|
|
r.check(on_post, "the scarecrow hangs on its post (raised, T-pose: no animation), not alive yet (no chest glow, fear ring, or aim marker), a forced morning, lantern dark")
|
|
var at := p.global_position
|
|
Input.action_press(&"move_forward")
|
|
for i in 6:
|
|
await r.physics_frame
|
|
Input.action_release(&"move_forward")
|
|
r.check(p.global_position == at and intro.running, "and the scarecrow can't move")
|
|
r.check(not sim.tutorial._box.visible, "no tips meanwhile")
|
|
main.to_menu()
|
|
r.check(main.screen == Main.Screen.MENU and not intro.busy() and intro.get_child_count() == 0 and not sim.local_frozen
|
|
and sim.player.is_physics_processing() and sim.day_night.forced == "" and sim.player.core_glow.visible,
|
|
"Save & quit to menu mid-intro: nothing of it left, the scarecrow given back")
|
|
main.main_menu.continue_button.pressed.emit()
|
|
r.check(main.screen == Main.Screen.PLAYING and not intro.busy() and sim.review_panel.visible and _hud_visible(),
|
|
"Continue plays no intro: straight to the saved morning's sign")
|
|
main.to_menu()
|
|
|
|
|
|
## The whole intro, stepped: every stage in order, the farm held until it's handed back.
|
|
func _whole_intro() -> void:
|
|
var audio := sim.audio
|
|
var before := audio.played.duplicate()
|
|
var count := func(cue: String) -> int: return int(audio.played.get(cue, 0)) - int(before.get(cue, 0))
|
|
var fired: Array[int] = [0]
|
|
var on_finished := func() -> void: fired[0] += 1
|
|
intro.finished.connect(on_finished)
|
|
_new_vacation()
|
|
var stinger := false
|
|
for v in audio._voices_ui:
|
|
stinger = stinger or (v.playing and v.get_meta(&"cue", "") == "morning")
|
|
r.check(count.call("morning") == 1 and not stinger, "new_campaign()'s morning stinger is stopped under the intro")
|
|
var seen: Array[String] = [intro.stage]
|
|
var length := {intro.stage: 0.0}
|
|
var held := true
|
|
var night_ok := false
|
|
var part_ok := false
|
|
var flash_ok := false
|
|
var t := 0.0
|
|
while intro.busy() and t < LIMIT:
|
|
intro.step(DT)
|
|
t += DT
|
|
if intro.stage != seen[-1]:
|
|
seen.append(intro.stage)
|
|
length[intro.stage] = 0.0
|
|
match intro.stage:
|
|
"flight":
|
|
night_ok = sim.day_night.forced == "night" and sim.day_night.lanterns_dark and intro._ufo.visible \
|
|
and audio.music_track == "" and audio._ambience_target == Vector2(0.0, 1.0)
|
|
"flash":
|
|
part_ok = intro._part.visible and intro._part.global_position.distance_to(OpeningIntro.START + OpeningIntro.FACING * 0.8) < 0.3
|
|
"uh_oh":
|
|
flash_ok = sim.player.core_glow.visible and not sim.day_night.lanterns_dark \
|
|
and absf(sim.player.global_position.y - intro._ground) < 0.01 and not intro._part.visible
|
|
else:
|
|
length[intro.stage] = float(length[intro.stage]) + DT
|
|
if intro.running and not _held():
|
|
held = false
|
|
r.check(seen == OpeningIntro.STAGES, "it visits every stage in order (%s)" % [seen])
|
|
r.check(held, "and holds the farm all along (no sign, no HUD, the scarecrow frozen) until it's handed back")
|
|
r.check(night_ok, "the night falls under the card: forced night, the lantern dark, the UFO up, night ambience, no music")
|
|
r.check(part_ok, "the part lands in front of the scarecrow")
|
|
r.check(flash_ok, "after the flash the scarecrow is down off its post, glowing, its lantern lit, the part gone into it")
|
|
r.check(fired[0] == 1 and t > 50.0 and t < 100.0, "finished once, %.1f s in all" % t)
|
|
var parts := PackedStringArray()
|
|
for s: String in seen:
|
|
parts.append("%s %.1f" % [s, float(length[s])])
|
|
r.info("intro stages (s): %s; %.1f s in all" % [", ".join(parts), t])
|
|
var cues := ["door_creak", "car_door", "horn", "ufo_whine", "part_fall", "life_flash", "ufo_zoom", "morning"]
|
|
var counts := []
|
|
for c: String in cues:
|
|
counts.append(count.call(c))
|
|
r.check(counts == [1, 2, 1, 1, 1, 1, 1, 2], "its sounds: %s = %s (the morning stinger with the sign)" % [cues, counts])
|
|
intro.finished.disconnect(on_finished)
|
|
await _check_clean("at the end")
|
|
main.to_menu()
|
|
|
|
|
|
## A skip from any stage fades straight to the sign, the farm just as clean.
|
|
func _skips() -> void:
|
|
for stage in OpeningIntro.STAGES:
|
|
if stage == "end":
|
|
continue
|
|
_new_vacation()
|
|
var got := _step_to(stage)
|
|
var t := 0.0
|
|
while got and intro.stage == stage and t < 0.6:
|
|
intro.step(DT)
|
|
t += DT
|
|
var at := intro.stage
|
|
intro.skip()
|
|
var ended := _step_to_end()
|
|
r.check(got and ended and intro._loading == null, "a skip in %s ends it" % at)
|
|
await _check_clean("skipped in " + at)
|
|
main.to_menu()
|
|
|
|
|
|
## Holding Space / Enter / A for a second skips it (a key already down at the start doesn't).
|
|
func _hold_to_skip() -> void:
|
|
Input.action_press(&"ui_accept")
|
|
_new_vacation()
|
|
for i in 45:
|
|
intro.step(DT)
|
|
var ignored := not intro._skipping
|
|
Input.action_release(&"ui_accept")
|
|
intro.step(DT)
|
|
Input.action_press(&"ui_accept")
|
|
for i in 20:
|
|
intro.step(DT)
|
|
var early := intro._skipping
|
|
for i in 12:
|
|
intro.step(DT)
|
|
var skipping := intro._skipping
|
|
Input.action_release(&"ui_accept")
|
|
_step_to_end()
|
|
r.check(ignored and not early and skipping, "holding [Space / Enter / A] a second skips (a key held from the menu doesn't count)")
|
|
await _check_clean("held to skip")
|
|
main.to_menu()
|
|
|
|
|
|
## The pause menu over it: Restart the night skips it; Save & quit to menu takes it down.
|
|
func _restart_and_quit() -> void:
|
|
_new_vacation()
|
|
var morning := SaveGame.read(SAVE).state.to_dict()
|
|
_step_to("flight")
|
|
main.pause()
|
|
r.check(main.screen == Main.Screen.PAUSED and r.paused and intro._box.is_blocked(), "Escape pauses it (its box waits)")
|
|
main.pause_menu.restart_button.pressed.emit()
|
|
main.confirm.yes_button.pressed.emit()
|
|
r.check(main.screen == Main.Screen.PLAYING and not r.paused and intro._skipping and sim.local_frozen,
|
|
"Restart the night during it skips it (still held while it fades)")
|
|
_step_to_end()
|
|
await _check_clean("restarted")
|
|
r.check(JSON.stringify(SaveGame.read(SAVE).state.to_dict()) == JSON.stringify(morning), "the save is still the first morning")
|
|
main.to_menu()
|
|
_new_vacation()
|
|
_step_to("uh_oh")
|
|
main.pause()
|
|
main.pause_menu.menu_button.pressed.emit()
|
|
var p := sim.player
|
|
r.check(main.screen == Main.Screen.MENU and not intro.busy() and intro.get_child_count() == 0 and not sim.local_frozen
|
|
and p.global_position.distance_to(OpeningIntro.START) < 0.01 and p.is_physics_processing() and p.core_glow.visible
|
|
and p.find_children("*", "LookAtModifier3D", true, false).is_empty() and sim.day_night.forced == ""
|
|
and not sim.day_night.lanterns_dark and not sim.audio.scene, "Save & quit to menu late in it leaves nothing behind")
|
|
|
|
|
|
## Hosting co-op starts the vacation without the intro.
|
|
func _hosting() -> void:
|
|
var gd := main.lobby.gdsync
|
|
main.lobby.gdsync = null # (no network in the test: the lobby just fails)
|
|
main._host_coop(CoopLobby.Mode.LAN, "Ana", false)
|
|
if main.confirm.is_open:
|
|
main.confirm.yes_button.pressed.emit()
|
|
r.check(main.screen == Main.Screen.PLAYING and not intro.busy() and sim.review_panel.visible and _hud_visible()
|
|
and not sim.local_frozen, "hosting co-op starts a new vacation without the intro")
|
|
main.lobby.gdsync = gd
|
|
main.to_menu()
|