Path: blob/master/modules/mono/editor/editor_internal_calls.cpp
10278 views
/**************************************************************************/1/* editor_internal_calls.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "editor_internal_calls.h"3132#include "../csharp_script.h"33#include "../godotsharp_dirs.h"34#include "../interop_types.h"35#include "../utils/macos_utils.h"36#include "../utils/path_utils.h"37#include "code_completion.h"3839#include "core/config/project_settings.h"40#include "core/os/os.h"41#include "core/version.h"42#include "editor/debugger/editor_debugger_node.h"43#include "editor/editor_main_screen.h"44#include "editor/editor_node.h"45#include "editor/export/lipo.h"46#include "editor/file_system/editor_paths.h"47#include "editor/run/editor_run_bar.h"48#include "editor/script/script_editor_plugin.h"49#include "editor/settings/editor_settings.h"50#include "editor/themes/editor_scale.h"51#include "main/main.h"5253#ifdef UNIX_ENABLED54#include <unistd.h> // access55#endif5657#ifdef __cplusplus58extern "C" {59#endif6061void godot_icall_GodotSharpDirs_ResMetadataDir(godot_string *r_dest) {62memnew_placement(r_dest, String(GodotSharpDirs::get_res_metadata_dir()));63}6465void godot_icall_GodotSharpDirs_MonoUserDir(godot_string *r_dest) {66memnew_placement(r_dest, String(GodotSharpDirs::get_mono_user_dir()));67}6869void godot_icall_GodotSharpDirs_BuildLogsDirs(godot_string *r_dest) {70memnew_placement(r_dest, String(GodotSharpDirs::get_build_logs_dir()));71}7273void godot_icall_GodotSharpDirs_DataEditorToolsDir(godot_string *r_dest) {74memnew_placement(r_dest, String(GodotSharpDirs::get_data_editor_tools_dir()));75}7677void godot_icall_GodotSharpDirs_CSharpProjectName(godot_string *r_dest) {78memnew_placement(r_dest, String(Path::get_csharp_project_name()));79}8081void godot_icall_EditorProgress_Create(const godot_string *p_task, const godot_string *p_label, int32_t p_amount, bool p_can_cancel) {82String task = *reinterpret_cast<const String *>(p_task);83String label = *reinterpret_cast<const String *>(p_label);84EditorNode::progress_add_task(task, label, p_amount, (bool)p_can_cancel);85}8687void godot_icall_EditorProgress_Dispose(const godot_string *p_task) {88String task = *reinterpret_cast<const String *>(p_task);89EditorNode::progress_end_task(task);90}9192bool godot_icall_EditorProgress_Step(const godot_string *p_task, const godot_string *p_state, int32_t p_step, bool p_force_refresh) {93String task = *reinterpret_cast<const String *>(p_task);94String state = *reinterpret_cast<const String *>(p_state);95return EditorNode::progress_task_step(task, state, p_step, (bool)p_force_refresh);96}9798void godot_icall_Internal_FullExportTemplatesDir(godot_string *r_dest) {99String full_templates_dir = EditorPaths::get_singleton()->get_export_templates_dir().path_join(GODOT_VERSION_FULL_CONFIG);100memnew_placement(r_dest, String(full_templates_dir));101}102103bool godot_icall_Internal_IsMacOSAppBundleInstalled(const godot_string *p_bundle_id) {104#ifdef MACOS_ENABLED105String bundle_id = *reinterpret_cast<const String *>(p_bundle_id);106return (bool)macos_is_app_bundle_installed(bundle_id);107#else108(void)p_bundle_id; // UNUSED109return (bool)false;110#endif111}112113bool godot_icall_Internal_LipOCreateFile(const godot_string *p_output_path, const godot_packed_array *p_files) {114String output_path = *reinterpret_cast<const String *>(p_output_path);115PackedStringArray files = *reinterpret_cast<const PackedStringArray *>(p_files);116LipO lip;117return lip.create_file(output_path, files);118}119120bool godot_icall_Internal_GodotIs32Bits() {121return sizeof(void *) == 4;122}123124bool godot_icall_Internal_GodotIsRealTDouble() {125#ifdef REAL_T_IS_DOUBLE126return (bool)true;127#else128return (bool)false;129#endif130}131132void godot_icall_Internal_GodotMainIteration() {133Main::iteration();134}135136bool godot_icall_Internal_IsAssembliesReloadingNeeded() {137#ifdef GD_MONO_HOT_RELOAD138return (bool)CSharpLanguage::get_singleton()->is_assembly_reloading_needed();139#else140return (bool)false;141#endif142}143144void godot_icall_Internal_ReloadAssemblies(bool p_soft_reload) {145#ifdef GD_MONO_HOT_RELOAD146callable_mp(MonoBind::GodotSharp::get_singleton(), &MonoBind::GodotSharp::reload_assemblies).call_deferred(p_soft_reload);147#endif148}149150void godot_icall_Internal_EditorDebuggerNodeReloadScripts() {151EditorDebuggerNode::get_singleton()->reload_all_scripts();152}153154bool godot_icall_Internal_ScriptEditorEdit(Resource *p_resource, int32_t p_line, int32_t p_col, bool p_grab_focus) {155Ref<Resource> resource = p_resource;156return (bool)ScriptEditor::get_singleton()->edit(resource, p_line, p_col, (bool)p_grab_focus);157}158159void godot_icall_Internal_EditorNodeShowScriptScreen() {160EditorNode::get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);161}162163void godot_icall_Internal_EditorRunPlay() {164EditorRunBar::get_singleton()->play_main_scene();165}166167void godot_icall_Internal_EditorRunStop() {168EditorRunBar::get_singleton()->stop_playing();169}170171void godot_icall_Internal_EditorPlugin_AddControlToEditorRunBar(Control *p_control) {172EditorRunBar::get_singleton()->get_buttons_container()->add_child(p_control);173}174175void godot_icall_Internal_ScriptEditorDebugger_ReloadScripts() {176EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton();177if (ed) {178ed->reload_all_scripts();179}180}181182void godot_icall_Internal_CodeCompletionRequest(int32_t p_kind, const godot_string *p_script_file, godot_packed_array *r_ret) {183String script_file = *reinterpret_cast<const String *>(p_script_file);184PackedStringArray suggestions = gdmono::get_code_completion((gdmono::CompletionKind)p_kind, script_file);185memnew_placement(r_ret, PackedStringArray(suggestions));186}187188float godot_icall_Globals_EditorScale() {189return EDSCALE;190}191192void godot_icall_Globals_GlobalDef(const godot_string *p_setting, const godot_variant *p_default_value, bool p_restart_if_changed, godot_variant *r_result) {193String setting = *reinterpret_cast<const String *>(p_setting);194Variant default_value = *reinterpret_cast<const Variant *>(p_default_value);195Variant result = _GLOBAL_DEF(setting, default_value, (bool)p_restart_if_changed);196memnew_placement(r_result, Variant(result));197}198199void godot_icall_Globals_EditorDef(const godot_string *p_setting, const godot_variant *p_default_value, bool p_restart_if_changed, godot_variant *r_result) {200String setting = *reinterpret_cast<const String *>(p_setting);201Variant default_value = *reinterpret_cast<const Variant *>(p_default_value);202Variant result = _EDITOR_DEF(setting, default_value, (bool)p_restart_if_changed);203memnew_placement(r_result, Variant(result));204}205206void godot_icall_Globals_EditorDefShortcut(const godot_string *p_setting, const godot_string *p_name, Key p_keycode, bool p_physical, godot_variant *r_result) {207String setting = *reinterpret_cast<const String *>(p_setting);208String name = *reinterpret_cast<const String *>(p_name);209Ref<Shortcut> result = ED_SHORTCUT(setting, name, p_keycode, p_physical);210memnew_placement(r_result, Variant(result));211}212213void godot_icall_Globals_EditorGetShortcut(const godot_string *p_setting, Ref<Shortcut> *r_result) {214String setting = *reinterpret_cast<const String *>(p_setting);215Ref<Shortcut> result = ED_GET_SHORTCUT(setting);216memnew_placement(r_result, Variant(result));217}218219void godot_icall_Globals_EditorShortcutOverride(const godot_string *p_setting, const godot_string *p_feature, Key p_keycode, bool p_physical) {220String setting = *reinterpret_cast<const String *>(p_setting);221String feature = *reinterpret_cast<const String *>(p_feature);222ED_SHORTCUT_OVERRIDE(setting, feature, p_keycode, p_physical);223}224225void godot_icall_Globals_TTR(const godot_string *p_text, godot_string *r_dest) {226String text = *reinterpret_cast<const String *>(p_text);227memnew_placement(r_dest, String(TTR(text)));228}229230void godot_icall_Utils_OS_GetPlatformName(godot_string *r_dest) {231String os_name = OS::get_singleton()->get_name();232memnew_placement(r_dest, String(os_name));233}234235bool godot_icall_Utils_OS_UnixFileHasExecutableAccess(const godot_string *p_file_path) {236#ifdef UNIX_ENABLED237String file_path = *reinterpret_cast<const String *>(p_file_path);238return access(file_path.utf8().get_data(), X_OK) == 0;239#else240ERR_FAIL_V(false);241#endif242}243244#ifdef __cplusplus245}246#endif247248// The order in this array must match the declaration order of249// the methods in 'GodotTools/Internals/Internal.cs'.250static const void *unmanaged_callbacks[]{251(void *)godot_icall_GodotSharpDirs_ResMetadataDir,252(void *)godot_icall_GodotSharpDirs_MonoUserDir,253(void *)godot_icall_GodotSharpDirs_BuildLogsDirs,254(void *)godot_icall_GodotSharpDirs_DataEditorToolsDir,255(void *)godot_icall_GodotSharpDirs_CSharpProjectName,256(void *)godot_icall_EditorProgress_Create,257(void *)godot_icall_EditorProgress_Dispose,258(void *)godot_icall_EditorProgress_Step,259(void *)godot_icall_Internal_FullExportTemplatesDir,260(void *)godot_icall_Internal_IsMacOSAppBundleInstalled,261(void *)godot_icall_Internal_LipOCreateFile,262(void *)godot_icall_Internal_GodotIs32Bits,263(void *)godot_icall_Internal_GodotIsRealTDouble,264(void *)godot_icall_Internal_GodotMainIteration,265(void *)godot_icall_Internal_IsAssembliesReloadingNeeded,266(void *)godot_icall_Internal_ReloadAssemblies,267(void *)godot_icall_Internal_EditorDebuggerNodeReloadScripts,268(void *)godot_icall_Internal_ScriptEditorEdit,269(void *)godot_icall_Internal_EditorNodeShowScriptScreen,270(void *)godot_icall_Internal_EditorRunPlay,271(void *)godot_icall_Internal_EditorRunStop,272(void *)godot_icall_Internal_EditorPlugin_AddControlToEditorRunBar,273(void *)godot_icall_Internal_ScriptEditorDebugger_ReloadScripts,274(void *)godot_icall_Internal_CodeCompletionRequest,275(void *)godot_icall_Globals_EditorScale,276(void *)godot_icall_Globals_GlobalDef,277(void *)godot_icall_Globals_EditorDef,278(void *)godot_icall_Globals_EditorDefShortcut,279(void *)godot_icall_Globals_EditorGetShortcut,280(void *)godot_icall_Globals_EditorShortcutOverride,281(void *)godot_icall_Globals_TTR,282(void *)godot_icall_Utils_OS_GetPlatformName,283(void *)godot_icall_Utils_OS_UnixFileHasExecutableAccess,284};285286const void **godotsharp::get_editor_interop_funcs(int32_t &r_size) {287r_size = sizeof(unmanaged_callbacks);288return unmanaged_callbacks;289}290291292