Skip to content

Commit

Permalink
Add inherit parameter to open_scene_from_path
Browse files Browse the repository at this point in the history
  • Loading branch information
ryevdokimov committed Sep 12, 2024
1 parent 83d54ab commit 8535a0f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion doc/classes/EditorInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@
<method name="open_scene_from_path">
<return type="void" />
<param index="0" name="scene_filepath" type="String" />
<param index="1" name="set_inherited" type="bool" default="false" />
<description>
Opens the scene at the given path.
Opens the scene at the given path. If [param set_inherited] is [code]true[/code], a new inherited scene will be created.
</description>
</method>
<method name="play_current_scene">
Expand Down
5 changes: 5 additions & 0 deletions editor/editor_interface.compat.inc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ void EditorInterface::_popup_property_selector_bind_compat_94323(Object *p_objec
popup_property_selector(p_object, p_callback, p_type_filter, String());
}

void EditorInterface::_open_scene_from_path_bind_compat_90057(const String &scene_path) {
return open_scene_from_path(scene_path, false);
}

void EditorInterface::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("popup_node_selector", "callback", "valid_types"), &EditorInterface::_popup_node_selector_bind_compat_94323, DEFVAL(TypedArray<StringName>()));
ClassDB::bind_compatibility_method(D_METHOD("popup_property_selector", "object", "callback", "type_filter"), &EditorInterface::_popup_property_selector_bind_compat_94323, DEFVAL(PackedInt32Array()));
ClassDB::bind_compatibility_method(D_METHOD("open_scene_from_path", "scene_path"), &EditorInterface::_open_scene_from_path_bind_compat_90057);
}

#endif
6 changes: 3 additions & 3 deletions editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,12 @@ void EditorInterface::edit_script(const Ref<Script> &p_script, int p_line, int p
ScriptEditor::get_singleton()->edit(p_script, p_line - 1, p_col - 1, p_grab_focus);
}

void EditorInterface::open_scene_from_path(const String &scene_path) {
void EditorInterface::open_scene_from_path(const String &scene_path, bool p_set_inherited) {
if (EditorNode::get_singleton()->is_changing_scene()) {
return;
}

EditorNode::get_singleton()->open_request(scene_path);
EditorNode::get_singleton()->open_request(scene_path, p_set_inherited);
}

void EditorInterface::reload_scene_from_path(const String &scene_path) {
Expand Down Expand Up @@ -586,7 +586,7 @@ void EditorInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("edit_resource", "resource"), &EditorInterface::edit_resource);
ClassDB::bind_method(D_METHOD("edit_node", "node"), &EditorInterface::edit_node);
ClassDB::bind_method(D_METHOD("edit_script", "script", "line", "column", "grab_focus"), &EditorInterface::edit_script, DEFVAL(-1), DEFVAL(0), DEFVAL(true));
ClassDB::bind_method(D_METHOD("open_scene_from_path", "scene_filepath"), &EditorInterface::open_scene_from_path);
ClassDB::bind_method(D_METHOD("open_scene_from_path", "scene_filepath", "set_inherited"), &EditorInterface::open_scene_from_path, DEFVAL(false));
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);
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class EditorInterface : public Object {
#ifndef DISABLE_DEPRECATED
void _popup_node_selector_bind_compat_94323(const Callable &p_callback, const TypedArray<StringName> &p_valid_types = TypedArray<StringName>());
void _popup_property_selector_bind_compat_94323(Object *p_object, const Callable &p_callback, const PackedInt32Array &p_type_filter = PackedInt32Array());

void _open_scene_from_path_bind_compat_90057(const String &scene_path);
static void _bind_compatibility_methods();
#endif

Expand Down Expand Up @@ -156,7 +156,7 @@ class EditorInterface : public Object {
void edit_resource(const Ref<Resource> &p_resource);
void edit_node(Node *p_node);
void edit_script(const Ref<Script> &p_script, int p_line = -1, int p_col = 0, bool p_grab_focus = true);
void open_scene_from_path(const String &scene_path);
void open_scene_from_path(const String &scene_path, bool p_set_inherited = false);
void reload_scene_from_path(const String &scene_path);

PackedStringArray get_open_scenes() const;
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4367,15 +4367,15 @@ void EditorNode::replace_history_reimported_nodes(Node *p_original_root_node, No
}
}

void EditorNode::open_request(const String &p_path) {
void EditorNode::open_request(const String &p_path, bool p_set_inherited) {
if (!opening_prev) {
List<String>::Element *prev_scene_item = previous_scenes.find(p_path);
if (prev_scene_item != nullptr) {
prev_scene_item->erase();
}
}

load_scene(p_path); // As it will be opened in separate tab.
load_scene(p_path, false, p_set_inherited); // As it will be opened in separate tab.
}

bool EditorNode::has_previous_scenes() const {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ class EditorNode : public Node {
void push_node_item(Node *p_node);
void hide_unused_editors(const Object *p_editing_owner = nullptr);

void open_request(const String &p_path);
void open_request(const String &p_path, bool p_set_inherited = false);
void edit_foreign_resource(Ref<Resource> p_resource);

bool is_resource_read_only(Ref<Resource> p_resource, bool p_foreign_resources_are_writable = false);
Expand Down
8 changes: 8 additions & 0 deletions misc/extension_api_validation/4.3-stable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,11 @@ GH-94434
Validate extension JSON: Error: Field 'classes/OS/methods/execute_with_pipe/arguments': size changed value in new API, from 2 to 3.

Optional argument added. Compatibility method registered.


GH-90057
--------
Validate extension JSON: Error: Field 'classes/EditorInterface/methods/open_scene_from_path/arguments': size changed value in new API, from 1 to 2.

Added optional argument to open_scene_from_path to create a new inherited scene.
Compatibility method registered.

0 comments on commit 8535a0f

Please sign in to comment.