From d98d6f52bdc5a430b3dabb5d1ca60066dfebff86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Thu, 29 Feb 2024 18:41:53 +0000 Subject: [PATCH] add a new main scene (#89) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/89 Co-authored-by: Lera ElvoƩ Co-committed-by: Lera ElvoƩ --- graph_node_renderer/deck_holder_renderer.gd | 28 +++++++++--------- main.gd | 32 +++++++++++++++++++++ main.tscn | 6 ++++ project.godot | 2 +- 4 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 main.gd create mode 100644 main.tscn diff --git a/graph_node_renderer/deck_holder_renderer.gd b/graph_node_renderer/deck_holder_renderer.gd index 1bc7793..05997f0 100644 --- a/graph_node_renderer/deck_holder_renderer.gd +++ b/graph_node_renderer/deck_holder_renderer.gd @@ -67,9 +67,10 @@ var _deck_to_save: WeakRef @onready var twitch_setup_dialog := $Twitch_Setup_Dialog as TwitchSetupDialog @onready var bottom_dock: BottomDock = %BottomDock +signal quit_completed + func _ready() -> void: - get_tree().auto_accept_quit = false tab_container.add_button_pressed.connect(add_empty_deck) tab_container.tab_changed.connect(_on_tab_container_tab_changed) tab_container.tab_about_to_change.connect(_on_tab_container_tab_about_to_change) @@ -465,19 +466,17 @@ func add_recents_to_menu() -> void: RendererPersistence.set_value(PERSISTENCE_NAMESPACE, "config", "recent_files", recent_files) -func _notification(what: int) -> void: - if what == NOTIFICATION_WM_CLOSE_REQUEST: - RendererPersistence.commit(PERSISTENCE_NAMESPACE) - - if range(tab_container.get_tab_count()).any(func(x: int): return tab_container.get_content(x).dirty): - unsaved_changes_dialog.show() - else: - #for i in tab_container.get_tab_count(): - #close_tab(i) - for i in range(tab_container.get_tab_count() - 1, -1, -1): - await close_tab(i) +func request_quit() -> void: + RendererPersistence.commit(PERSISTENCE_NAMESPACE) + + if range(tab_container.get_tab_count()).any(func(x: int): return tab_container.get_content(x).dirty): + unsaved_changes_dialog.show() + else: + for i in range(tab_container.get_tab_count() - 1, -1, -1): + await close_tab(i) - get_tree().quit() + #get_tree().quit() + quit_completed.emit() func _on_unsaved_changes_dialog_single_deck_confirmed() -> void: @@ -494,7 +493,8 @@ func _on_unsaved_changes_dialog_single_deck_custom_action(action: StringName) -> func _on_unsaved_changes_dialog_confirmed() -> void: for i in range(tab_container.get_tab_count() - 1, -1, -1): await close_tab(i) - get_tree().quit() + #get_tree().quit() + quit_completed.emit() func _unhandled_input(event: InputEvent) -> void: diff --git a/main.gd b/main.gd new file mode 100644 index 0000000..bda6cab --- /dev/null +++ b/main.gd @@ -0,0 +1,32 @@ +# (c) 2023-present Eroax +# (c) 2023-present Yagich +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) +extends Node + +const DEFAULT_RENDERER := preload("res://graph_node_renderer/deck_holder_renderer.tscn") + +var deck_holder_renderer: DeckHolderRenderer = null +var deck_holder_renderer_finished := false + + +func _ready() -> void: + get_tree().auto_accept_quit = false + + if DisplayServer.get_name() != "headless": + # not headless, start default renderer + deck_holder_renderer = DEFAULT_RENDERER.instantiate() + add_child(deck_holder_renderer) + deck_holder_renderer.quit_completed.connect(_on_deck_holder_renderer_quit_completed) + + +func _on_deck_holder_renderer_quit_completed() -> void: + # will be used later to make sure both default and rpc are finished processing + deck_holder_renderer_finished = true + + get_tree().quit() + + +func _notification(what: int) -> void: + if what == NOTIFICATION_WM_CLOSE_REQUEST: + if deck_holder_renderer: + deck_holder_renderer.request_quit() diff --git a/main.tscn b/main.tscn new file mode 100644 index 0000000..e93eebb --- /dev/null +++ b/main.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://clxtes7sdpe65"] + +[ext_resource type="Script" path="res://main.gd" id="1_rxyjw"] + +[node name="Main" type="Node"] +script = ExtResource("1_rxyjw") diff --git a/project.godot b/project.godot index 952e699..329fad8 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="StreamGraph" config/version="0.0.5" -run/main_scene="res://graph_node_renderer/deck_holder_renderer.tscn" +run/main_scene="res://main.tscn" config/use_custom_user_dir=true config/custom_user_dir_name="streamgraph" config/auto_accept_quit=false