harvest/game/tools/capture_intro.gd
Forrest c6daf3d217 #33: opening intro cutscene
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>
2026-10-07 22:54:24 -04:00

96 lines
3.6 KiB
GDScript

extends SceneTree
## Captures the opening intro (OpeningIntro) for review: runs the real game (main.tscn, so the
## toon look and the pixel outlines are on, as ToonLook comes with Main) in a window, starts a New
## vacation, and saves a PNG at the start of every stage and every --every seconds of it, then one
## of the first morning's sign, and quits. It needs a window (not --headless) and must not run
## fullscreen (the project's default), so pass --windowed and a resolution; a hidden window with
## VSync on crawls on some desktops, so keep it visible and pass --disable-vsync. --fixed-fps
## makes every frame the same game time, so the shots don't depend on the machine's speed:
## godot --path . --windowed --resolution 1600x900 --disable-vsync --fixed-fps 30 \
## --script res://game/tools/capture_intro.gd -- --out=/tmp/hs-intro --every=2
## Options (after --): --out=dir (default /tmp/hs-intro/), --every=seconds (default 2; 0: stage
## starts only), --prefix=text (default "intro"), --skip-at=stage (skips half a second into that
## stage, to look at the skip). It saves to its own user://capture_intro_* files, so the player's
## save and settings are never touched.
const SAVE := "user://capture_intro_save.json"
const SETTINGS := "user://capture_intro_settings.cfg"
const LIMIT := 240.0 # seconds of intro before giving up
var _out := "/tmp/hs-intro/"
var _every := 2.0
var _prefix := "intro"
var _skip_at := ""
var _count: int = 0
func _initialize() -> void:
for a in OS.get_cmdline_user_args():
var arg := String(a)
if arg.begins_with("--out="):
_out = arg.trim_prefix("--out=")
elif arg.begins_with("--every="):
_every = float(arg.trim_prefix("--every="))
elif arg.begins_with("--prefix="):
_prefix = arg.trim_prefix("--prefix=")
elif arg.begins_with("--skip-at="):
_skip_at = arg.trim_prefix("--skip-at=")
if not _out.ends_with("/"):
_out += "/"
_run.call_deferred()
func _run() -> void:
DirAccess.make_dir_recursive_absolute(_out)
var main := (load("res://game/scenes/main.tscn") as PackedScene).instantiate() as Main
main.save_path = SAVE
main.settings_path = SETTINGS
root.add_child(main)
for i in 5:
await process_frame
main.new_vacation()
var intro := main.sim.intro if main.sim != null else null
if intro == null or not intro.busy():
printerr("capture_intro: the intro didn't start")
quit(1)
return
var last := ""
var next_shot := 0.0
var skipped := false
while intro.busy() and intro.elapsed < LIMIT:
await process_frame
if intro.stage != last:
last = intro.stage
await _shot(intro, "start")
elif _every > 0.0 and intro.elapsed >= next_shot:
next_shot = intro.elapsed + _every
await _shot(intro, "")
if _skip_at != "" and not skipped and intro.stage == _skip_at and intro.elapsed > 0.0:
skipped = true
for i in 15:
await process_frame
intro.skip()
for i in 30: # the sign settles
await process_frame
await _shot(intro, "sign")
print("capture_intro: %d shots in %s (%.1f s of intro)" % [_count, _out, intro.elapsed])
main.queue_free()
await process_frame
await create_timer(0.3).timeout
_clean()
quit()
func _shot(intro: OpeningIntro, tag: String) -> void:
await RenderingServer.frame_post_draw
var image := root.get_texture().get_image()
var stage := intro.stage if intro.stage != "" else "none"
var file := "%s%s_%03d_%05.1fs_%s%s.png" % [_out, _prefix, _count, intro.elapsed, stage, "_" + tag if tag != "" else ""]
image.save_png(file)
_count += 1
func _clean() -> void:
for p in [SAVE, SAVE + ".tmp", SETTINGS]:
if FileAccess.file_exists(p):
DirAccess.remove_absolute(ProjectSettings.globalize_path(p))