allow for taking screenshots

This commit is contained in:
Nitwel 2024-05-02 19:35:47 +02:00
parent 722dca31a7
commit feea2a40b1
5 changed files with 39 additions and 3 deletions

View File

@ -7,7 +7,7 @@ sky_material = SubResource("ProceduralSkyMaterial_i4xao")
[resource]
background_mode = 1
background_color = Color(1, 1, 1, 1)
background_color = Color(0.441, 0.962033, 0.98, 1)
sky = SubResource("Sky_vhymk")
ambient_light_source = 2
ambient_light_color = Color(1, 1, 1, 1)

View File

@ -1,6 +1,6 @@
extends StaticBody3D
var entity_id: String
@export var entity_id: String
var icon = R.state("question_mark")
var icon_color = R.state(Color(1, 1, 1, 1))

View File

@ -23,6 +23,9 @@ var color_supported = false
# Called when the node enters the scene tree for the first time.
func _ready():
super()
if HomeApi.has_connected() == false:
await HomeApi.on_connect
icon.value = "lightbulb"
var stateInfo = await HomeApi.get_state(entity_id)
@ -126,4 +129,4 @@ func quick_action():
_toggle()
func _toggle():
HomeApi.set_state(entity_id, "off" if active.value else "on")
HomeApi.set_state(entity_id, "off" if active.value else "on")

View File

@ -47,6 +47,9 @@ func _ready():
toggle_menu()
elif action.name == "by_button":
House.body.mini_view.small.value=!House.body.mini_view.small.value
elif action.name == "ax_button":
if take_screenshot():
EventSystem.notify("Screenshot taken", EventNotify.Type.INFO)
)
EventSystem.on_focus_in.connect(func(event):
@ -115,6 +118,9 @@ func _input(event):
if event is InputEventKey and Input.is_key_pressed(KEY_F10):
var vp = get_viewport()
vp.debug_draw = (vp.debug_draw + 1) % 5
if event is InputEventKey and Input.is_key_pressed(KEY_F2):
take_screenshot()
if event is InputEventKey and Input.is_key_pressed(KEY_M):
toggle_menu()
@ -138,3 +144,26 @@ func vector_key_mapping(key_positive_x: int, key_negative_x: int, key_positive_y
vec = vec.normalized()
return vec
func take_screenshot():
var vp = get_viewport()
var texture = vp.get_texture()
var image = texture.get_image()
var file_name = "%s.png" % Time.get_datetime_string_from_system().replace(":", "-")
if image == null:
return false
if OS.get_name() == "Android":
var path = OS.get_system_dir(OS.SYSTEM_DIR_PICTURES, false) + "/immersive-home/" + file_name
if not FileAccess.file_exists(path):
var dir = path.get_base_dir()
DirAccess.open("user://").make_dir_recursive(dir)
image.save_png(path)
else:
image.save_png("user://screenshots/%s.png" % Time.get_datetime_string_from_system().replace(":", "-"))
return true

View File

@ -29,6 +29,10 @@ EventSystem="*res://lib/globals/event_system.gd"
House="*res://lib/globals/house_body.gd"
Request="*res://lib/globals/request.gd"
[display]
window/vsync/vsync_mode=0
[editor_plugins]
enabled=PackedStringArray("res://addons/godot-xr-tools/plugin.cfg")