From 1949320e8826f1f2d74f5f5b70eedeb386f937ac Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 21 Sep 2025 19:41:05 +0200 Subject: Add screenshot and sceneshot --- client/global.gd | 1 + client/gui/menus/game.gd | 14 ++++++++++++ client/project.godot | 17 ++++++++++++++- client/system/gltf_apply_visibility.gd | 35 ++++++++++++++++++++++++++++++ client/system/gltf_apply_visibility.gd.uid | 1 + client/system/settings.gd | 1 + 6 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 client/system/gltf_apply_visibility.gd create mode 100644 client/system/gltf_apply_visibility.gd.uid diff --git a/client/global.gd b/client/global.gd index e504a282..dc9e4f04 100644 --- a/client/global.gd +++ b/client/global.gd @@ -37,6 +37,7 @@ var focused_node: Control var focused_menu: Menu # only use this as a last resort, currently exists to open setup menu from settings func _ready(): + GLTFDocument.register_gltf_document_extension(GLTFApplyNodeVisibility.new()) Profile.load(OS.get_data_dir().path_join("hurrycurry").path_join("profile")) Settings.load(OS.get_config_dir().path_join("hurrycurry").path_join("settings.json")) get_viewport().gui_focus_changed.connect(Sound.play_hover_maybe) diff --git a/client/gui/menus/game.gd b/client/gui/menus/game.gd index 0bf44484..97c8cc1d 100644 --- a/client/gui/menus/game.gd +++ b/client/gui/menus/game.gd @@ -37,6 +37,20 @@ func _input(_event): await submenu("res://gui/menus/chat.tscn") chat_preview.visible = true + if Input.is_action_just_pressed("screenshot"): + get_viewport().get_texture().get_image().save_png(get_shot_path("screenshot-%s.png")) + if Input.is_action_just_pressed("sceneshot"): + var doc := GLTFDocument.new() + var state := GLTFState.new() + doc.append_from_scene(game, state) + doc.write_to_filesystem(state, get_shot_path("sceneshot-%s.glb")) + +func get_shot_path(template: String) -> String: + var path = Settings.read("gameplay.screenshot_path") + if path == "": path = "user://" + var filename = template % Time.get_datetime_string_from_system() + return "%s/%s" % [path, filename] + func _menu_cover(state): game.follow_camera.disable_input_menu = state game.follow_camera.update_disable_input() diff --git a/client/project.godot b/client/project.godot index cffc2b4e..b012f959 100644 --- a/client/project.godot +++ b/client/project.godot @@ -223,10 +223,25 @@ menu={ ] } toggle_overlay={ -"deadzone": 0.2, +"deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194332,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +screenshot={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194333,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} +toggle_debug={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194334,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} +sceneshot={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194335,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} [input_devices] diff --git a/client/system/gltf_apply_visibility.gd b/client/system/gltf_apply_visibility.gd new file mode 100644 index 00000000..5635bf6e --- /dev/null +++ b/client/system/gltf_apply_visibility.gd @@ -0,0 +1,35 @@ +# Hurry Curry! - a game about cooking +# Copyright (C) 2025 Hurry Curry! contributors +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License only. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +extends GLTFDocumentExtension +class_name GLTFApplyNodeVisibility + +# Since Godot 4.5 the KHR_node_visibility extension is +# required which is not yet supported in Blender, so we +# pre-apply them by removing meshes from hidden nodes. +func _export_post(state: GLTFState) -> Error: + state.json["extensionsRequired"].erase("KHR_node_visibility") + var nodes = state.json["nodes"] + for node in nodes: + var visible = node.get("extensions", {}).get("KHR_node_visibility", {}).get("visible", true) + if not visible: hide_node(nodes, node) + return Error.OK + +func hide_node(nodes: Array, node: Dictionary): + if node.has("mesh"): print("clear mesh") + node.erase("mesh") + for child_index in node.get("children", []): + print("clear child child_index") + hide_node(nodes, nodes[child_index]) diff --git a/client/system/gltf_apply_visibility.gd.uid b/client/system/gltf_apply_visibility.gd.uid new file mode 100644 index 00000000..2dfa14e4 --- /dev/null +++ b/client/system/gltf_apply_visibility.gd.uid @@ -0,0 +1 @@ +uid://xi0tf4wav1ky diff --git a/client/system/settings.gd b/client/system/settings.gd index 43613de0..a3aece89 100644 --- a/client/system/settings.gd +++ b/client/system/settings.gd @@ -30,6 +30,7 @@ static func get_root(): ToggleSetting.new("accessible_movement", false), ToggleSetting.new("first_person", false), DropdownSetting.new("interact_target", "dirsnap", ["dir", "dirsnap"]), + PathSetting.new("screenshot_path", "", FileDialog.FileMode.FILE_MODE_OPEN_DIR), ]), SettingsCategory.new("graphics", [ PresetRow.new("preset", { -- cgit v1.2.3-70-g09d2