38 lines
1.4 KiB
GDScript
38 lines
1.4 KiB
GDScript
extends Timer
|
|
|
|
var base_path = "user://screenshots/"
|
|
var session_path = ""
|
|
var count = 0
|
|
|
|
func _ready():
|
|
# Generate a timestamp
|
|
var datetime = Time.get_datetime_dict_from_system()
|
|
var timestamp = "%d-%02d-%02d_%02d-%02d-%02d" % [datetime.year, datetime.month, datetime.day, datetime.hour, datetime.minute, datetime.second]
|
|
|
|
# Create a session-specific subdirectory
|
|
session_path = base_path + timestamp + "/"
|
|
if not DirAccess.dir_exists_absolute(session_path):
|
|
DirAccess.make_dir_recursive_absolute(session_path)
|
|
|
|
$"../ScreenOverlay/SettingsWindow/VBoxContainer/HBoxContainer/Interval".text=str(wait_time)
|
|
$"../ScreenOverlay/SettingsWindow/VBoxContainer/HBoxContainer/Screenshots".set_pressed(is_stopped() == false)
|
|
|
|
func _on_timeout():
|
|
var image = get_viewport().get_texture().get_image()
|
|
image.save_png(session_path + ("%010d"%count) + ".png")
|
|
count += 1
|
|
|
|
func _on_screenshots_toggled(toggled_on):
|
|
if(toggled_on):
|
|
start()
|
|
else:
|
|
stop()
|
|
$"../ScreenOverlay/SettingsWindow/VBoxContainer/HBoxContainer/Interval".text=str(wait_time)
|
|
$"../ScreenOverlay/SettingsWindow/VBoxContainer/HBoxContainer/Screenshots".set_pressed(is_stopped() == false)
|
|
|
|
func _on_interval_text_changed(new_text):
|
|
wait_time=int(new_text)
|
|
$"../ScreenOverlay/SettingsWindow/VBoxContainer/HBoxContainer/Interval".text=str(wait_time)
|
|
$"../ScreenOverlay/SettingsWindow/VBoxContainer/HBoxContainer/Screenshots".set_pressed(is_stopped() == false)
|
|
|