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 Aug 15, 2024
1 parent ee363af commit fd87766
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 8 deletions.
3 changes: 2 additions & 1 deletion doc/classes/EditorInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,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
41 changes: 41 additions & 0 deletions editor/editor_interface.compat.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**************************************************************************/
/* editor_interface.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef DISABLE_DEPRECATED

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("open_scene_from_path", "scene_path"), &EditorInterface::_open_scene_from_path_bind_compat_90057);
}

#endif
7 changes: 4 additions & 3 deletions editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**************************************************************************/

#include "editor_interface.h"
#include "editor_interface.compat.inc"

#include "editor/editor_command_palette.h"
#include "editor/editor_feature_profile.h"
Expand Down Expand Up @@ -401,12 +402,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 @@ -579,7 +580,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
7 changes: 6 additions & 1 deletion editor/editor_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class EditorInterface : public Object {
protected:
static void _bind_methods();

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

public:
static EditorInterface *get_singleton() { return singleton; }

Expand Down Expand Up @@ -147,7 +152,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 @@ -4481,15 +4481,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 @@ -775,7 +775,7 @@ class EditorNode : public Node {

void select_editor_by_name(const String &p_name);

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
7 changes: 7 additions & 0 deletions misc/extension_api_validation/4.3-stable.expected
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ should instead be used to justify these changes and describe how users should wo
Add new entries at the end of the file.

## Changes between 4.3-stable and 4.4-stable

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 fd87766

Please sign in to comment.