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>
This commit is contained in:
Steven Wroblewski
2026-10-02 12:49:40 +02:00
parent 714d604c58
commit ab81f66ef0
8 changed files with 126 additions and 27 deletions
+54 -25
View File
@@ -1,14 +1,22 @@
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. Lets a
## change to the look be checked without playing by hand. The player's real
## key and save stay untouched.
## 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"
const FRAMES_AFTER_HIT := 30
## 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:
@@ -16,37 +24,58 @@ func _initialize() -> void:
func _run() -> void:
var arguments := OS.get_cmdline_user_args()
var output := arguments[0] if arguments.size() > 0 else "user://screenshot.png"
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()
main.command_line = PackedStringArray([style] if not style.is_empty() else [])
root.add_child(main)
main.play(false)
await process_frame
# Four tiles to the right, toward the rock outcrop beside the clearing.
for frame in 48:
main.avatar.walk(Vector2.RIGHT, 1.0 / 60.0)
if showcase:
main.open_showcase()
await process_frame
var session: GwSession = main.session
var rock := session.spawn_point() + Vector2i(7, 0)
main.dig_at(rock)
for frame in FRAMES_AFTER_HIT:
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()
for file in DirAccess.get_files_at(STORAGE):
DirAccess.remove_absolute(STORAGE.path_join(file))
for directory in DirAccess.get_directories_at(STORAGE):
var path := STORAGE.path_join(directory)
for file in DirAccess.get_files_at(path):
DirAccess.remove_absolute(path.path_join(file))
DirAccess.remove_absolute(path)
DirAccess.remove_absolute(STORAGE)
_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)