2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* editor_internal_calls.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* 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. */
|
|
|
|
/**************************************************************************/
|
2019-07-03 09:44:53 +02:00
|
|
|
|
|
|
|
#include "editor_internal_calls.h"
|
|
|
|
|
2019-12-17 13:10:01 +01:00
|
|
|
#ifdef UNIX_ENABLED
|
|
|
|
#include <unistd.h> // access
|
|
|
|
#endif
|
|
|
|
|
2022-02-12 02:46:22 +01:00
|
|
|
#include "core/config/project_settings.h"
|
2019-07-03 09:44:53 +02:00
|
|
|
#include "core/os/os.h"
|
|
|
|
#include "core/version.h"
|
2020-02-07 02:52:05 +01:00
|
|
|
#include "editor/debugger/editor_debugger_node.h"
|
2019-07-03 09:44:53 +02:00
|
|
|
#include "editor/editor_node.h"
|
2022-07-30 02:00:56 +02:00
|
|
|
#include "editor/editor_paths.h"
|
2019-12-24 08:17:23 +01:00
|
|
|
#include "editor/editor_scale.h"
|
2022-08-01 00:40:18 +02:00
|
|
|
#include "editor/editor_settings.h"
|
2023-04-12 21:02:28 +02:00
|
|
|
#include "editor/gui/editor_run_bar.h"
|
2019-07-03 09:44:53 +02:00
|
|
|
#include "editor/plugins/script_editor_plugin.h"
|
|
|
|
#include "main/main.h"
|
|
|
|
|
|
|
|
#include "../csharp_script.h"
|
|
|
|
#include "../godotsharp_dirs.h"
|
2022-07-20 08:28:22 +02:00
|
|
|
#include "../utils/macos_utils.h"
|
2020-05-09 20:45:43 +02:00
|
|
|
#include "code_completion.h"
|
2019-07-03 09:44:53 +02:00
|
|
|
|
2021-09-12 20:21:15 +02:00
|
|
|
#include "../interop_types.h"
|
2019-07-03 09:44:53 +02:00
|
|
|
|
2021-09-12 20:23:05 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_GodotSharpDirs_ResMetadataDir(godot_string *r_dest) {
|
2021-09-12 20:21:15 +02:00
|
|
|
memnew_placement(r_dest, String(GodotSharpDirs::get_res_metadata_dir()));
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_GodotSharpDirs_MonoUserDir(godot_string *r_dest) {
|
2021-09-12 20:21:15 +02:00
|
|
|
memnew_placement(r_dest, String(GodotSharpDirs::get_mono_user_dir()));
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_GodotSharpDirs_BuildLogsDirs(godot_string *r_dest) {
|
2019-07-03 09:44:53 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-09-12 20:21:15 +02:00
|
|
|
memnew_placement(r_dest, String(GodotSharpDirs::get_build_logs_dir()));
|
2019-07-03 09:44:53 +02:00
|
|
|
#else
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2019-07-03 09:44:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_GodotSharpDirs_DataEditorToolsDir(godot_string *r_dest) {
|
2019-07-03 09:44:53 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-09-12 20:21:15 +02:00
|
|
|
memnew_placement(r_dest, String(GodotSharpDirs::get_data_editor_tools_dir()));
|
2019-07-03 09:44:53 +02:00
|
|
|
#else
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2019-07-03 09:44:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_EditorProgress_Create(const godot_string *p_task, const godot_string *p_label, int32_t p_amount, bool p_can_cancel) {
|
2021-09-12 20:21:15 +02:00
|
|
|
String task = *reinterpret_cast<const String *>(p_task);
|
|
|
|
String label = *reinterpret_cast<const String *>(p_label);
|
2019-07-03 09:44:53 +02:00
|
|
|
EditorNode::progress_add_task(task, label, p_amount, (bool)p_can_cancel);
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_EditorProgress_Dispose(const godot_string *p_task) {
|
2021-09-12 20:21:15 +02:00
|
|
|
String task = *reinterpret_cast<const String *>(p_task);
|
2019-07-03 09:44:53 +02:00
|
|
|
EditorNode::progress_end_task(task);
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
bool godot_icall_EditorProgress_Step(const godot_string *p_task, const godot_string *p_state, int32_t p_step, bool p_force_refresh) {
|
2021-09-12 20:21:15 +02:00
|
|
|
String task = *reinterpret_cast<const String *>(p_task);
|
|
|
|
String state = *reinterpret_cast<const String *>(p_state);
|
2019-07-03 09:44:53 +02:00
|
|
|
return EditorNode::progress_task_step(task, state, p_step, (bool)p_force_refresh);
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Internal_FullExportTemplatesDir(godot_string *r_dest) {
|
2022-08-30 02:34:01 +02:00
|
|
|
String full_templates_dir = EditorPaths::get_singleton()->get_export_templates_dir().path_join(VERSION_FULL_CONFIG);
|
2021-09-12 20:21:15 +02:00
|
|
|
memnew_placement(r_dest, String(full_templates_dir));
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
bool godot_icall_Internal_IsMacOSAppBundleInstalled(const godot_string *p_bundle_id) {
|
2022-07-20 08:28:22 +02:00
|
|
|
#ifdef MACOS_ENABLED
|
2021-09-12 20:21:15 +02:00
|
|
|
String bundle_id = *reinterpret_cast<const String *>(p_bundle_id);
|
|
|
|
return (bool)macos_is_app_bundle_installed(bundle_id);
|
2019-07-03 09:44:53 +02:00
|
|
|
#else
|
|
|
|
(void)p_bundle_id; // UNUSED
|
2021-09-12 20:21:15 +02:00
|
|
|
return (bool)false;
|
2019-07-03 09:44:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
bool godot_icall_Internal_GodotIs32Bits() {
|
2019-07-03 09:44:53 +02:00
|
|
|
return sizeof(void *) == 4;
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
bool godot_icall_Internal_GodotIsRealTDouble() {
|
2019-07-03 09:44:53 +02:00
|
|
|
#ifdef REAL_T_IS_DOUBLE
|
2021-09-12 20:21:15 +02:00
|
|
|
return (bool)true;
|
2019-07-03 09:44:53 +02:00
|
|
|
#else
|
2021-09-12 20:21:15 +02:00
|
|
|
return (bool)false;
|
2019-07-03 09:44:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Internal_GodotMainIteration() {
|
2019-07-03 09:44:53 +02:00
|
|
|
Main::iteration();
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
bool godot_icall_Internal_IsAssembliesReloadingNeeded() {
|
2019-07-03 09:44:53 +02:00
|
|
|
#ifdef GD_MONO_HOT_RELOAD
|
2021-09-12 20:21:15 +02:00
|
|
|
return (bool)CSharpLanguage::get_singleton()->is_assembly_reloading_needed();
|
2019-07-03 09:44:53 +02:00
|
|
|
#else
|
2021-09-12 20:21:15 +02:00
|
|
|
return (bool)false;
|
2019-07-03 09:44:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Internal_ReloadAssemblies(bool p_soft_reload) {
|
2019-07-03 09:44:53 +02:00
|
|
|
#ifdef GD_MONO_HOT_RELOAD
|
2021-08-13 16:46:14 +02:00
|
|
|
mono_bind::GodotSharp::get_singleton()->call_deferred(SNAME("_reload_assemblies"), (bool)p_soft_reload);
|
2019-07-03 09:44:53 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Internal_EditorDebuggerNodeReloadScripts() {
|
2020-02-07 02:52:05 +01:00
|
|
|
EditorDebuggerNode::get_singleton()->reload_scripts();
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
bool godot_icall_Internal_ScriptEditorEdit(Resource *p_resource, int32_t p_line, int32_t p_col, bool p_grab_focus) {
|
2021-09-12 20:21:15 +02:00
|
|
|
Ref<Resource> resource = p_resource;
|
|
|
|
return (bool)ScriptEditor::get_singleton()->edit(resource, p_line, p_col, (bool)p_grab_focus);
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Internal_EditorNodeShowScriptScreen() {
|
2020-12-06 16:09:18 +01:00
|
|
|
EditorNode::get_singleton()->editor_select(EditorNode::EDITOR_SCRIPT);
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Internal_EditorRunPlay() {
|
2023-04-12 21:02:28 +02:00
|
|
|
EditorRunBar::get_singleton()->play_main_scene();
|
2019-07-18 04:08:24 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Internal_EditorRunStop() {
|
2023-04-12 21:02:28 +02:00
|
|
|
EditorRunBar::get_singleton()->stop_playing();
|
2019-07-18 04:08:24 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Internal_ScriptEditorDebugger_ReloadScripts() {
|
2020-02-07 02:52:05 +01:00
|
|
|
EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton();
|
|
|
|
if (ed) {
|
|
|
|
ed->reload_scripts();
|
2019-07-18 04:08:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Internal_CodeCompletionRequest(int32_t p_kind, const godot_string *p_script_file, godot_packed_array *r_ret) {
|
2021-09-12 20:21:15 +02:00
|
|
|
String script_file = *reinterpret_cast<const String *>(p_script_file);
|
2020-05-09 20:45:43 +02:00
|
|
|
PackedStringArray suggestions = gdmono::get_code_completion((gdmono::CompletionKind)p_kind, script_file);
|
2021-09-12 20:21:15 +02:00
|
|
|
memnew_placement(r_ret, PackedStringArray(suggestions));
|
2020-05-09 20:45:43 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
float godot_icall_Globals_EditorScale() {
|
2019-10-11 01:23:35 +02:00
|
|
|
return EDSCALE;
|
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Globals_GlobalDef(const godot_string *p_setting, const godot_variant *p_default_value, bool p_restart_if_changed, godot_variant *r_result) {
|
2021-09-12 20:21:15 +02:00
|
|
|
String setting = *reinterpret_cast<const String *>(p_setting);
|
|
|
|
Variant default_value = *reinterpret_cast<const Variant *>(p_default_value);
|
2019-10-11 01:23:35 +02:00
|
|
|
Variant result = _GLOBAL_DEF(setting, default_value, (bool)p_restart_if_changed);
|
2021-09-12 20:21:15 +02:00
|
|
|
memnew_placement(r_result, Variant(result));
|
2019-10-11 01:23:35 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Globals_EditorDef(const godot_string *p_setting, const godot_variant *p_default_value, bool p_restart_if_changed, godot_variant *r_result) {
|
2021-09-12 20:21:15 +02:00
|
|
|
String setting = *reinterpret_cast<const String *>(p_setting);
|
|
|
|
Variant default_value = *reinterpret_cast<const Variant *>(p_default_value);
|
2019-10-11 01:23:35 +02:00
|
|
|
Variant result = _EDITOR_DEF(setting, default_value, (bool)p_restart_if_changed);
|
2021-09-12 20:21:15 +02:00
|
|
|
memnew_placement(r_result, Variant(result));
|
2019-10-11 01:23:35 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Globals_EditorShortcut(const godot_string *p_setting, godot_variant *r_result) {
|
2021-09-12 20:21:15 +02:00
|
|
|
String setting = *reinterpret_cast<const String *>(p_setting);
|
2021-09-13 15:33:56 +02:00
|
|
|
Ref<Shortcut> result = ED_GET_SHORTCUT(setting);
|
2021-09-12 20:21:15 +02:00
|
|
|
memnew_placement(r_result, Variant(result));
|
2021-09-13 15:33:56 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Globals_TTR(const godot_string *p_text, godot_string *r_dest) {
|
2021-09-12 20:21:15 +02:00
|
|
|
String text = *reinterpret_cast<const String *>(p_text);
|
|
|
|
memnew_placement(r_dest, String(TTR(text)));
|
2019-10-11 01:23:35 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
void godot_icall_Utils_OS_GetPlatformName(godot_string *r_dest) {
|
2019-07-03 09:44:53 +02:00
|
|
|
String os_name = OS::get_singleton()->get_name();
|
2021-09-12 20:21:15 +02:00
|
|
|
memnew_placement(r_dest, String(os_name));
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
bool godot_icall_Utils_OS_UnixFileHasExecutableAccess(const godot_string *p_file_path) {
|
2019-12-17 13:10:01 +01:00
|
|
|
#ifdef UNIX_ENABLED
|
2021-09-12 20:21:15 +02:00
|
|
|
String file_path = *reinterpret_cast<const String *>(p_file_path);
|
2019-12-17 13:10:01 +01:00
|
|
|
return access(file_path.utf8().get_data(), X_OK) == 0;
|
|
|
|
#else
|
|
|
|
ERR_FAIL_V(false);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-09-12 20:23:05 +02:00
|
|
|
#ifdef __cplusplus
|
2019-07-03 09:44:53 +02:00
|
|
|
}
|
2021-09-12 20:23:05 +02:00
|
|
|
#endif
|
|
|
|
|
2022-08-05 03:32:59 +02:00
|
|
|
// The order in this array must match the declaration order of
|
|
|
|
// the methods in 'GodotTools/Internals/Internal.cs'.
|
|
|
|
static const void *unmanaged_callbacks[]{
|
2021-09-12 20:23:05 +02:00
|
|
|
(void *)godot_icall_GodotSharpDirs_ResMetadataDir,
|
|
|
|
(void *)godot_icall_GodotSharpDirs_MonoUserDir,
|
|
|
|
(void *)godot_icall_GodotSharpDirs_BuildLogsDirs,
|
|
|
|
(void *)godot_icall_GodotSharpDirs_DataEditorToolsDir,
|
|
|
|
(void *)godot_icall_EditorProgress_Create,
|
|
|
|
(void *)godot_icall_EditorProgress_Dispose,
|
|
|
|
(void *)godot_icall_EditorProgress_Step,
|
|
|
|
(void *)godot_icall_Internal_FullExportTemplatesDir,
|
|
|
|
(void *)godot_icall_Internal_IsMacOSAppBundleInstalled,
|
|
|
|
(void *)godot_icall_Internal_GodotIs32Bits,
|
|
|
|
(void *)godot_icall_Internal_GodotIsRealTDouble,
|
|
|
|
(void *)godot_icall_Internal_GodotMainIteration,
|
|
|
|
(void *)godot_icall_Internal_IsAssembliesReloadingNeeded,
|
|
|
|
(void *)godot_icall_Internal_ReloadAssemblies,
|
|
|
|
(void *)godot_icall_Internal_EditorDebuggerNodeReloadScripts,
|
|
|
|
(void *)godot_icall_Internal_ScriptEditorEdit,
|
|
|
|
(void *)godot_icall_Internal_EditorNodeShowScriptScreen,
|
|
|
|
(void *)godot_icall_Internal_EditorRunPlay,
|
|
|
|
(void *)godot_icall_Internal_EditorRunStop,
|
|
|
|
(void *)godot_icall_Internal_ScriptEditorDebugger_ReloadScripts,
|
|
|
|
(void *)godot_icall_Internal_CodeCompletionRequest,
|
|
|
|
(void *)godot_icall_Globals_EditorScale,
|
|
|
|
(void *)godot_icall_Globals_GlobalDef,
|
|
|
|
(void *)godot_icall_Globals_EditorDef,
|
|
|
|
(void *)godot_icall_Globals_EditorShortcut,
|
|
|
|
(void *)godot_icall_Globals_TTR,
|
|
|
|
(void *)godot_icall_Utils_OS_GetPlatformName,
|
|
|
|
(void *)godot_icall_Utils_OS_UnixFileHasExecutableAccess,
|
|
|
|
};
|
2022-08-05 03:32:59 +02:00
|
|
|
|
|
|
|
const void **godotsharp::get_editor_interop_funcs(int32_t &r_size) {
|
|
|
|
r_size = sizeof(unmanaged_callbacks);
|
|
|
|
return unmanaged_callbacks;
|
|
|
|
}
|