OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / scenes / test / _probe_texture_strip_shot.gd

56 lines · gd ref:
extends SceneTree
## PROBE (not a gate) — a real-window screenshot of build mode: the texture strip, the
## editor bands, the status bar (and the first-run card when the player has not
## dismissed it), to judge layout by eye.
##   DISPLAY=:0 <godot> --path . --rendering-driver vulkan --script res://scenes/test/_probe_texture_strip_shot.gd -- --out /tmp/strip.png [--size WxH]
## The window is moved off a fullscreen workspace first (probe_window.gd): a hidden
## window is not drawn and the screenshot comes back 2x2.

const ProbeWindow := preload("res://scenes/test/probe_window.gd")

var _frame := 0
var _out := "/tmp/strip.png"
var _size := Vector2i(1600, 900)
var _ws := ""
var _next_i3 := 0
var _drawn := 0


func _initialize() -> void:
	var args := OS.get_cmdline_user_args()
	var i := args.find("--out")
	if i >= 0 and i + 1 < args.size():
		_out = args[i + 1]
	var s := args.find("--size")
	if s >= 0 and s + 1 < args.size():
		var wh := args[s + 1].split("x")
		_size = Vector2i(int(wh[0]), int(wh[1]))
	DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
	DisplayServer.window_set_size(_size)
	_ws = ProbeWindow.free_workspace()
	root.add_child((load("res://scenes/maps/map_flat.tscn") as PackedScene).instantiate())


func _process(_d: float) -> bool:
	if _drawn < 10:
		if _ws != "" and _drawn == 0 and Time.get_ticks_msec() >= _next_i3:
			_next_i3 = Time.get_ticks_msec() + 1000
			ProbeWindow.move_to(_ws, _size)
		if ProbeWindow.drawing(root, mini(_size.x - 40, 1000)):
			_drawn += 1
		elif Time.get_ticks_msec() > 30000:
			print("PROBE FAIL window never drew (size %s)" % root.size)
			quit(1)
			return true
		return false
	_frame += 1
	if _frame == 20:
		root.get_node("/root/GameMode").set_mode("build")
	if _frame == 160:
		var img := root.get_viewport().get_texture().get_image()
		img.save_png(_out)
		print("PROBE shot %s %s" % [_out, str(img.get_size())])
		quit(0)
		return true
	return false