From 144d95d96cbd2cfb5d5d58a2a5721d3ae8a18f7e Mon Sep 17 00:00:00 2001 From: Cyclone <91777373+CycloneRing@users.noreply.github.com> Date: Sat, 5 Oct 2024 07:39:10 +0330 Subject: [PATCH] EditorInterface: Add `get_open_scene_roots` to retrieve all opened scenes root nodes --- doc/classes/EditorInterface.xml | 8 +++++++- editor/editor_interface.cpp | 21 +++++++++++++++++---- editor/editor_interface.h | 1 + 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml index d4acb820232..0a178178b3d 100644 --- a/doc/classes/EditorInterface.xml +++ b/doc/classes/EditorInterface.xml @@ -156,10 +156,16 @@ [b]Warning:[/b] Removing and freeing this node will render a part of the editor useless and may cause a crash. + + + + Returns an array with references to the root nodes of the currently opened scenes. + + - Returns an [Array] with the file paths of the currently opened scenes. + Returns an array with the file paths of the currently opened scenes. diff --git a/editor/editor_interface.cpp b/editor/editor_interface.cpp index c0d7b1b1fa7..587e3c12ec2 100644 --- a/editor/editor_interface.cpp +++ b/editor/editor_interface.cpp @@ -667,12 +667,24 @@ PackedStringArray EditorInterface::get_open_scenes() const { PackedStringArray ret; Vector scenes = EditorNode::get_editor_data().get_edited_scenes(); - int scns_amount = scenes.size(); - for (int idx_scn = 0; idx_scn < scns_amount; idx_scn++) { - if (scenes[idx_scn].root == nullptr) { + for (EditorData::EditedScene &edited_scene : scenes) { + if (edited_scene.root == nullptr) { continue; } - ret.push_back(scenes[idx_scn].root->get_scene_file_path()); + ret.push_back(edited_scene.root->get_scene_file_path()); + } + return ret; +} + +TypedArray EditorInterface::get_open_scene_roots() const { + TypedArray ret; + Vector scenes = EditorNode::get_editor_data().get_edited_scenes(); + + for (EditorData::EditedScene &edited_scene : scenes) { + if (edited_scene.root == nullptr) { + continue; + } + ret.push_back(edited_scene.root); } return ret; } @@ -830,6 +842,7 @@ void EditorInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("reload_scene_from_path", "scene_filepath"), &EditorInterface::reload_scene_from_path); ClassDB::bind_method(D_METHOD("get_open_scenes"), &EditorInterface::get_open_scenes); + ClassDB::bind_method(D_METHOD("get_open_scene_roots"), &EditorInterface::get_open_scene_roots); ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &EditorInterface::get_edited_scene_root); ClassDB::bind_method(D_METHOD("save_scene"), &EditorInterface::save_scene); diff --git a/editor/editor_interface.h b/editor/editor_interface.h index b6d163d2fdd..83ae8434d4e 100644 --- a/editor/editor_interface.h +++ b/editor/editor_interface.h @@ -171,6 +171,7 @@ public: void reload_scene_from_path(const String &scene_path); PackedStringArray get_open_scenes() const; + TypedArray get_open_scene_roots() const; Node *get_edited_scene_root() const; Error save_scene();