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. ## ## From the repository root (opens a window for a moment): ## godot --path game -s res://tools/screenshot.gd -- const STORAGE := "user://screenshot-run" const FRAMES_AFTER_HIT := 30 func _initialize() -> void: _run.call_deferred() func _run() -> void: var arguments := OS.get_cmdline_user_args() var output := arguments[0] if arguments.size() > 0 else "user://screenshot.png" DirAccess.make_dir_recursive_absolute(STORAGE) var main: Node = load("res://main.tscn").instantiate() main.storage_dir = STORAGE main.command_line = PackedStringArray() 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) 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: await process_frame 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) quit(0 if error == OK else 1)