Skip to content

Commit d6c5c4e

Browse files
committed
Merge pull request #107671 from dsnopek/editor-run-control
Allow editor plugins to modify run arguments
2 parents 7864ac8 + fe27a72 commit d6c5c4e

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

doc/classes/EditorPlugin.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,20 @@
362362
Remember that you have to manage the visibility of all your editor controls manually.
363363
</description>
364364
</method>
365+
<method name="_run_scene" qualifiers="virtual const">
366+
<return type="PackedStringArray" />
367+
<param index="0" name="scene" type="String" />
368+
<param index="1" name="args" type="PackedStringArray" />
369+
<description>
370+
This function is called when an individual scene is about to be played in the editor. [param args] is a list of command line arguments that will be passed to the new Godot instance, which will be replaced by the list returned by this function.
371+
[codeblock]
372+
func _run_scene(scene, args):
373+
args.append("--an-extra-argument")
374+
return args
375+
[/codeblock]
376+
[b]Note:[/b] Text that is printed in this method will not be visible in the editor's Output panel unless [member EditorSettings.run/output/always_clear_output_on_play] is [code]false[/code].
377+
</description>
378+
</method>
365379
<method name="_save_external_data" qualifiers="virtual">
366380
<return type="void" />
367381
<description>

editor/editor_node.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7142,6 +7142,13 @@ bool EditorNode::call_build() {
71427142
return builds_successful;
71437143
}
71447144

7145+
void EditorNode::call_run_scene(const String &p_scene, Vector<String> &r_args) {
7146+
for (int i = 0; i < editor_data.get_editor_plugin_count(); i++) {
7147+
EditorPlugin *plugin = editor_data.get_editor_plugin(i);
7148+
plugin->run_scene(p_scene, r_args);
7149+
}
7150+
}
7151+
71457152
void EditorNode::_inherit_imported(const String &p_action) {
71467153
open_imported->hide();
71477154
load_scene(open_import_request, true, true);

editor/editor_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ class EditorNode : public Node {
730730
void _on_plugin_ready(Object *p_script, const String &p_activate_name);
731731

732732
bool call_build();
733+
void call_run_scene(const String &p_scene, Vector<String> &r_args);
733734

734735
// This is a very naive estimation, but we need something now. Will be reworked later.
735736
bool is_editor_ready() const { return is_inside_tree() && !waiting_for_first_scan; }

editor/plugins/editor_plugin.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,13 @@ bool EditorPlugin::build() {
556556
return success;
557557
}
558558

559+
void EditorPlugin::run_scene(const String &p_scene, Vector<String> &r_args) {
560+
Vector<String> new_args;
561+
if (GDVIRTUAL_CALL(_run_scene, p_scene, r_args, new_args)) {
562+
r_args = new_args;
563+
}
564+
}
565+
559566
void EditorPlugin::queue_save_layout() {
560567
EditorNode::get_singleton()->save_editor_layout_delayed();
561568
}
@@ -695,6 +702,7 @@ void EditorPlugin::_bind_methods() {
695702
GDVIRTUAL_BIND(_set_window_layout, "configuration");
696703
GDVIRTUAL_BIND(_get_window_layout, "configuration");
697704
GDVIRTUAL_BIND(_build);
705+
GDVIRTUAL_BIND(_run_scene, "scene", "args");
698706
GDVIRTUAL_BIND(_enable_plugin);
699707
GDVIRTUAL_BIND(_disable_plugin);
700708

editor/plugins/editor_plugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class EditorPlugin : public Node {
138138
GDVIRTUAL1(_set_window_layout, Ref<ConfigFile>)
139139
GDVIRTUAL1(_get_window_layout, Ref<ConfigFile>)
140140
GDVIRTUAL0R(bool, _build)
141+
GDVIRTUAL2RC(Vector<String>, _run_scene, String, Vector<String>)
141142
GDVIRTUAL0(_enable_plugin)
142143
GDVIRTUAL0(_disable_plugin)
143144

@@ -210,6 +211,7 @@ class EditorPlugin : public Node {
210211
virtual void get_window_layout(Ref<ConfigFile> p_layout);
211212
virtual void edited_scene_changed() {} // if changes are pending in editor, apply them
212213
virtual bool build(); // builds with external tools. Returns true if safe to continue running scene.
214+
virtual void run_scene(const String &p_scene, Vector<String> &r_args);
213215

214216
EditorInterface *get_editor_interface();
215217
ScriptCreateDialog *get_script_create_dialog();

editor/run/editor_run_bar.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,17 @@ void EditorRunBar::_run_scene(const String &p_scene_path, const Vector<String> &
314314
if (!EditorNode::get_singleton()->call_build()) {
315315
return;
316316
}
317+
318+
Vector<String> args = p_run_args;
319+
EditorNode::get_singleton()->call_run_scene(run_filename, args);
320+
317321
// Use the existing URI, in case it is overridden by the CLI.
318322
String uri = EditorDebuggerNode::get_singleton()->get_server_uri();
319323
if (uri.is_empty()) {
320324
uri = "tcp://";
321325
}
322326
EditorDebuggerNode::get_singleton()->start(uri);
323-
Error error = editor_run.run(run_filename, write_movie_file, p_run_args);
327+
Error error = editor_run.run(run_filename, write_movie_file, args);
324328
if (error != OK) {
325329
EditorDebuggerNode::get_singleton()->stop();
326330
EditorNode::get_singleton()->show_accept(TTR("Could not start subprocess(es)!"), TTR("OK"));

0 commit comments

Comments
 (0)