From feea2a40b1308aebf81392543cfb0df0f3cd7d63 Mon Sep 17 00:00:00 2001 From: Nitwel Date: Thu, 2 May 2024 19:35:47 +0200 Subject: [PATCH] allow for taking screenshots --- app/assets/environment.tres | 2 +- app/content/entities/entity.gd | 2 +- app/content/entities/light/light.gd | 5 ++++- app/content/main.gd | 29 +++++++++++++++++++++++++++++ app/project.godot | 4 ++++ 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/assets/environment.tres b/app/assets/environment.tres index 1655b28..bb3fb95 100644 --- a/app/assets/environment.tres +++ b/app/assets/environment.tres @@ -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) diff --git a/app/content/entities/entity.gd b/app/content/entities/entity.gd index 5735650..a3e408f 100644 --- a/app/content/entities/entity.gd +++ b/app/content/entities/entity.gd @@ -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)) diff --git a/app/content/entities/light/light.gd b/app/content/entities/light/light.gd index c14c9d9..b0f876c 100644 --- a/app/content/entities/light/light.gd +++ b/app/content/entities/light/light.gd @@ -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") \ No newline at end of file + HomeApi.set_state(entity_id, "off" if active.value else "on") diff --git a/app/content/main.gd b/app/content/main.gd index 5732423..b763691 100644 --- a/app/content/main.gd +++ b/app/content/main.gd @@ -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 \ No newline at end of file diff --git a/app/project.godot b/app/project.godot index a53401f..bf26453 100644 --- a/app/project.godot +++ b/app/project.godot @@ -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")