40 lines
1 KiB
GDScript3
40 lines
1 KiB
GDScript3
|
extends Node
|
||
|
# Ref : https://github.com/Maujoe/godot-simlpe-screenshot-script/blob/master/scripts/screenshot.gd
|
||
|
|
||
|
var file_prefix = "khanat"
|
||
|
var output_path:String = "user://screenshot"
|
||
|
var index = 0
|
||
|
|
||
|
|
||
|
func _ready():
|
||
|
check_path(output_path)
|
||
|
if not output_path[-1] == "/":
|
||
|
output_path += "/"
|
||
|
set_process_input(true)
|
||
|
|
||
|
|
||
|
func _input(event):
|
||
|
if event.is_action_pressed("INPUT_VIEW_SCREENSHOT", true):
|
||
|
make_screenshot()
|
||
|
|
||
|
|
||
|
func make_screenshot():
|
||
|
var filename: String
|
||
|
var img = get_viewport().get_texture().get_image()
|
||
|
var time = Time.get_datetime_dict_from_system()
|
||
|
filename = "%s%s_%s_%02d_%02d_%02d_%02d_%02d_%s_%s.png" % [
|
||
|
output_path, file_prefix, time['year'], time['month'], time['day'],
|
||
|
time['hour'], time['minute'], time['second'],
|
||
|
str(OS.get_process_id()), str(index)]
|
||
|
Common.msg_debug("Create screenshot: " + filename)
|
||
|
index += 1
|
||
|
img.save_png(filename)
|
||
|
|
||
|
|
||
|
func check_path(path):
|
||
|
var dir = Directory.new()
|
||
|
dir.open(path)
|
||
|
if not dir.dir_exists(path):
|
||
|
Common.msg_info("Create direcotory %s" % path)
|
||
|
dir.make_dir(path)
|