Files
MusicPlayer/tools/take_screenshots.gd
T
Sansan 92e3a66075
Build / test (push) Successful in 45s
Build / build (push) Successful in 1m20s
Save the quiz settings to the config folder
The quiz card's settings are saved to quiz_settings.cfg in OS.get_config_dir()
on every change and loaded at start. Debug builds use their own file, and
MUSICPLAYER_CONFIG_DIR moves the file elsewhere so tests never touch it.

Count plays in statistics and Prefer less played soundtracks are not saved and
move from the quiz card to the Settings popup.
2026-10-07 18:13:00 +02:00

57 lines
2.1 KiB
GDScript

extends SceneTree
## Takes a screenshot of the main window in every UiTour state, against a fake server.
##
## Usage:
## MUSICPLAYER_CONFIG_DIR=$(mktemp -d) godot --path . -s tools/take_screenshots.gd -- <dir>
##
## Setting [code]MUSICPLAYER_CONFIG_DIR[/code] keeps your saved quiz settings out of the
## pictures.
##
## Writes [code]<state>.png[/code] for each state and [code]layout.json[/code] with where
## every node is in each state. With [code]--headless[/code] only the layout is written.
## Compare two runs with [code]tools/compare_screenshots.py[/code].
const SIZE: Vector2i = Vector2i(1920, 1080)
func _initialize() -> void:
_take.call_deferred()
func _take() -> void:
var args: PackedStringArray = OS.get_cmdline_user_args()
var out_dir: String = args[0] if !args.is_empty() else "user://screenshots"
DirAccess.make_dir_recursive_absolute(out_dir)
var draws: bool = DisplayServer.get_name() != "headless"
# Loaded here, not named as a class: autoloads such as Playlist do not exist yet
# when this script is compiled
var ui_tour: GDScript = load("res://tests/fakes/ui_tour.gd")
ui_tour.prepare_autoloads()
var server: RefCounted = ui_tour.make_server().install()
# Drawn at the layout size, so the pictures do not depend on the screen size
var viewport: SubViewport = SubViewport.new()
viewport.size = SIZE
viewport.gui_embed_subwindows = true
viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
root.add_child(viewport)
var main: Control = load("res://main/MainWindow.tscn").instantiate()
viewport.add_child(main)
var layout: Dictionary = {}
var save_state: Callable = func(state: String, popup: Node) -> void:
layout[state] = ui_tour.dump_layout(main, main if popup == null else popup)
if draws:
await RenderingServer.frame_post_draw
viewport.get_texture().get_image().save_png(out_dir.path_join(state + ".png"))
print("Saved state ", state)
await ui_tour.new(main).run(save_state)
var file: FileAccess = FileAccess.open(out_dir.path_join("layout.json"), FileAccess.WRITE)
file.store_string(JSON.stringify(layout, " ", true))
file.close()
server.uninstall()
main.queue_free()
quit()