Files
Grovewright/game/tools/screenshot.gd
Steven Wroblewski ab81f66ef0 Stil wählen, merken und fotografieren
F2 wechselt im Spiel den Stil und meldet ihn, --style=NAME wählt ihn
beim Start, und das Spiel merkt sich die Wahl in den Einstellungen.
Das Bildschirmfoto-Werkzeug nimmt Bilder in einem bestimmten Stil und
von der Vitrine auf und zeigt eine zweite Figur mit Namen.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-10-02 12:49:40 +02:00

82 lines
2.6 KiB
GDScript

extends SceneTree
## Starts the game in a temporary storage folder, walks the figure toward the
## rock beside the clearing, hits it once and saves a screenshot. A second
## figure with a name stands beside it. Lets a change to the look be checked
## without playing by hand. The player's real key and save stay untouched.
##
## From the repository root (opens a window for a moment):
## godot --path game -s res://tools/screenshot.gd -- <path of the PNG>
## [--style=NAME] [--showcase]
## --style=NAME draws in that style; --showcase shows the style samples
## instead of the game.
const STORAGE := "user://screenshot-run"
## Frames between the hit and the picture: the burst of chips is still in
## the air, and the crack is there.
const FRAMES_AFTER_HIT := 8
## Seconds into the showcase at which the picture is taken: the plant is
## nearly grown and the animal in the air.
const SHOWCASE_SECONDS := 5.2
func _initialize() -> void:
_run.call_deferred()
func _run() -> void:
var output := "user://screenshot.png"
var style := ""
var showcase := false
for argument in OS.get_cmdline_user_args():
if argument.begins_with("--style="):
style = argument
elif argument == "--showcase":
showcase = true
else:
output = argument
DirAccess.make_dir_recursive_absolute(STORAGE)
var main: Node = load("res://main.tscn").instantiate()
main.storage_dir = STORAGE
main.command_line = PackedStringArray([style] if not style.is_empty() else [])
root.add_child(main)
if showcase:
main.open_showcase()
await process_frame
main.showcase.time = SHOWCASE_SECONDS
await process_frame
await process_frame
else:
await _play(main)
var image := root.get_texture().get_image()
var error := image.save_png(output)
print("screenshot %s: %s" % ["saved" if error == OK else "failed", ProjectSettings.globalize_path(output)])
root.remove_child(main)
main.free()
_remove(STORAGE)
quit(0 if error == OK else 1)
## Plays alone: walks four tiles to the right, toward the rock outcrop
## beside the clearing, and hits it once.
func _play(main: Node) -> void:
main.play(false)
await process_frame
for frame in 48:
main.avatar.walk(Vector2.RIGHT, 1.0 / 60.0)
await process_frame
var session: GwSession = main.session
main.figures.place(session.local_player(), main.avatar.position + Vector2(-40, 8))
var rock := session.spawn_point() + Vector2i(7, 0)
main.dig_at(rock)
for frame in FRAMES_AFTER_HIT:
await process_frame
func _remove(path: String) -> void:
for file in DirAccess.get_files_at(path):
DirAccess.remove_absolute(path.path_join(file))
for directory in DirAccess.get_directories_at(path):
_remove(path.path_join(directory))
DirAccess.remove_absolute(path)