Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/mono/editor/editor_internal_calls.cpp
10278 views
1
/**************************************************************************/
2
/* editor_internal_calls.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "editor_internal_calls.h"
32
33
#include "../csharp_script.h"
34
#include "../godotsharp_dirs.h"
35
#include "../interop_types.h"
36
#include "../utils/macos_utils.h"
37
#include "../utils/path_utils.h"
38
#include "code_completion.h"
39
40
#include "core/config/project_settings.h"
41
#include "core/os/os.h"
42
#include "core/version.h"
43
#include "editor/debugger/editor_debugger_node.h"
44
#include "editor/editor_main_screen.h"
45
#include "editor/editor_node.h"
46
#include "editor/export/lipo.h"
47
#include "editor/file_system/editor_paths.h"
48
#include "editor/run/editor_run_bar.h"
49
#include "editor/script/script_editor_plugin.h"
50
#include "editor/settings/editor_settings.h"
51
#include "editor/themes/editor_scale.h"
52
#include "main/main.h"
53
54
#ifdef UNIX_ENABLED
55
#include <unistd.h> // access
56
#endif
57
58
#ifdef __cplusplus
59
extern "C" {
60
#endif
61
62
void godot_icall_GodotSharpDirs_ResMetadataDir(godot_string *r_dest) {
63
memnew_placement(r_dest, String(GodotSharpDirs::get_res_metadata_dir()));
64
}
65
66
void godot_icall_GodotSharpDirs_MonoUserDir(godot_string *r_dest) {
67
memnew_placement(r_dest, String(GodotSharpDirs::get_mono_user_dir()));
68
}
69
70
void godot_icall_GodotSharpDirs_BuildLogsDirs(godot_string *r_dest) {
71
memnew_placement(r_dest, String(GodotSharpDirs::get_build_logs_dir()));
72
}
73
74
void godot_icall_GodotSharpDirs_DataEditorToolsDir(godot_string *r_dest) {
75
memnew_placement(r_dest, String(GodotSharpDirs::get_data_editor_tools_dir()));
76
}
77
78
void godot_icall_GodotSharpDirs_CSharpProjectName(godot_string *r_dest) {
79
memnew_placement(r_dest, String(Path::get_csharp_project_name()));
80
}
81
82
void godot_icall_EditorProgress_Create(const godot_string *p_task, const godot_string *p_label, int32_t p_amount, bool p_can_cancel) {
83
String task = *reinterpret_cast<const String *>(p_task);
84
String label = *reinterpret_cast<const String *>(p_label);
85
EditorNode::progress_add_task(task, label, p_amount, (bool)p_can_cancel);
86
}
87
88
void godot_icall_EditorProgress_Dispose(const godot_string *p_task) {
89
String task = *reinterpret_cast<const String *>(p_task);
90
EditorNode::progress_end_task(task);
91
}
92
93
bool godot_icall_EditorProgress_Step(const godot_string *p_task, const godot_string *p_state, int32_t p_step, bool p_force_refresh) {
94
String task = *reinterpret_cast<const String *>(p_task);
95
String state = *reinterpret_cast<const String *>(p_state);
96
return EditorNode::progress_task_step(task, state, p_step, (bool)p_force_refresh);
97
}
98
99
void godot_icall_Internal_FullExportTemplatesDir(godot_string *r_dest) {
100
String full_templates_dir = EditorPaths::get_singleton()->get_export_templates_dir().path_join(GODOT_VERSION_FULL_CONFIG);
101
memnew_placement(r_dest, String(full_templates_dir));
102
}
103
104
bool godot_icall_Internal_IsMacOSAppBundleInstalled(const godot_string *p_bundle_id) {
105
#ifdef MACOS_ENABLED
106
String bundle_id = *reinterpret_cast<const String *>(p_bundle_id);
107
return (bool)macos_is_app_bundle_installed(bundle_id);
108
#else
109
(void)p_bundle_id; // UNUSED
110
return (bool)false;
111
#endif
112
}
113
114
bool godot_icall_Internal_LipOCreateFile(const godot_string *p_output_path, const godot_packed_array *p_files) {
115
String output_path = *reinterpret_cast<const String *>(p_output_path);
116
PackedStringArray files = *reinterpret_cast<const PackedStringArray *>(p_files);
117
LipO lip;
118
return lip.create_file(output_path, files);
119
}
120
121
bool godot_icall_Internal_GodotIs32Bits() {
122
return sizeof(void *) == 4;
123
}
124
125
bool godot_icall_Internal_GodotIsRealTDouble() {
126
#ifdef REAL_T_IS_DOUBLE
127
return (bool)true;
128
#else
129
return (bool)false;
130
#endif
131
}
132
133
void godot_icall_Internal_GodotMainIteration() {
134
Main::iteration();
135
}
136
137
bool godot_icall_Internal_IsAssembliesReloadingNeeded() {
138
#ifdef GD_MONO_HOT_RELOAD
139
return (bool)CSharpLanguage::get_singleton()->is_assembly_reloading_needed();
140
#else
141
return (bool)false;
142
#endif
143
}
144
145
void godot_icall_Internal_ReloadAssemblies(bool p_soft_reload) {
146
#ifdef GD_MONO_HOT_RELOAD
147
callable_mp(MonoBind::GodotSharp::get_singleton(), &MonoBind::GodotSharp::reload_assemblies).call_deferred(p_soft_reload);
148
#endif
149
}
150
151
void godot_icall_Internal_EditorDebuggerNodeReloadScripts() {
152
EditorDebuggerNode::get_singleton()->reload_all_scripts();
153
}
154
155
bool godot_icall_Internal_ScriptEditorEdit(Resource *p_resource, int32_t p_line, int32_t p_col, bool p_grab_focus) {
156
Ref<Resource> resource = p_resource;
157
return (bool)ScriptEditor::get_singleton()->edit(resource, p_line, p_col, (bool)p_grab_focus);
158
}
159
160
void godot_icall_Internal_EditorNodeShowScriptScreen() {
161
EditorNode::get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
162
}
163
164
void godot_icall_Internal_EditorRunPlay() {
165
EditorRunBar::get_singleton()->play_main_scene();
166
}
167
168
void godot_icall_Internal_EditorRunStop() {
169
EditorRunBar::get_singleton()->stop_playing();
170
}
171
172
void godot_icall_Internal_EditorPlugin_AddControlToEditorRunBar(Control *p_control) {
173
EditorRunBar::get_singleton()->get_buttons_container()->add_child(p_control);
174
}
175
176
void godot_icall_Internal_ScriptEditorDebugger_ReloadScripts() {
177
EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton();
178
if (ed) {
179
ed->reload_all_scripts();
180
}
181
}
182
183
void godot_icall_Internal_CodeCompletionRequest(int32_t p_kind, const godot_string *p_script_file, godot_packed_array *r_ret) {
184
String script_file = *reinterpret_cast<const String *>(p_script_file);
185
PackedStringArray suggestions = gdmono::get_code_completion((gdmono::CompletionKind)p_kind, script_file);
186
memnew_placement(r_ret, PackedStringArray(suggestions));
187
}
188
189
float godot_icall_Globals_EditorScale() {
190
return EDSCALE;
191
}
192
193
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) {
194
String setting = *reinterpret_cast<const String *>(p_setting);
195
Variant default_value = *reinterpret_cast<const Variant *>(p_default_value);
196
Variant result = _GLOBAL_DEF(setting, default_value, (bool)p_restart_if_changed);
197
memnew_placement(r_result, Variant(result));
198
}
199
200
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) {
201
String setting = *reinterpret_cast<const String *>(p_setting);
202
Variant default_value = *reinterpret_cast<const Variant *>(p_default_value);
203
Variant result = _EDITOR_DEF(setting, default_value, (bool)p_restart_if_changed);
204
memnew_placement(r_result, Variant(result));
205
}
206
207
void godot_icall_Globals_EditorDefShortcut(const godot_string *p_setting, const godot_string *p_name, Key p_keycode, bool p_physical, godot_variant *r_result) {
208
String setting = *reinterpret_cast<const String *>(p_setting);
209
String name = *reinterpret_cast<const String *>(p_name);
210
Ref<Shortcut> result = ED_SHORTCUT(setting, name, p_keycode, p_physical);
211
memnew_placement(r_result, Variant(result));
212
}
213
214
void godot_icall_Globals_EditorGetShortcut(const godot_string *p_setting, Ref<Shortcut> *r_result) {
215
String setting = *reinterpret_cast<const String *>(p_setting);
216
Ref<Shortcut> result = ED_GET_SHORTCUT(setting);
217
memnew_placement(r_result, Variant(result));
218
}
219
220
void godot_icall_Globals_EditorShortcutOverride(const godot_string *p_setting, const godot_string *p_feature, Key p_keycode, bool p_physical) {
221
String setting = *reinterpret_cast<const String *>(p_setting);
222
String feature = *reinterpret_cast<const String *>(p_feature);
223
ED_SHORTCUT_OVERRIDE(setting, feature, p_keycode, p_physical);
224
}
225
226
void godot_icall_Globals_TTR(const godot_string *p_text, godot_string *r_dest) {
227
String text = *reinterpret_cast<const String *>(p_text);
228
memnew_placement(r_dest, String(TTR(text)));
229
}
230
231
void godot_icall_Utils_OS_GetPlatformName(godot_string *r_dest) {
232
String os_name = OS::get_singleton()->get_name();
233
memnew_placement(r_dest, String(os_name));
234
}
235
236
bool godot_icall_Utils_OS_UnixFileHasExecutableAccess(const godot_string *p_file_path) {
237
#ifdef UNIX_ENABLED
238
String file_path = *reinterpret_cast<const String *>(p_file_path);
239
return access(file_path.utf8().get_data(), X_OK) == 0;
240
#else
241
ERR_FAIL_V(false);
242
#endif
243
}
244
245
#ifdef __cplusplus
246
}
247
#endif
248
249
// The order in this array must match the declaration order of
250
// the methods in 'GodotTools/Internals/Internal.cs'.
251
static const void *unmanaged_callbacks[]{
252
(void *)godot_icall_GodotSharpDirs_ResMetadataDir,
253
(void *)godot_icall_GodotSharpDirs_MonoUserDir,
254
(void *)godot_icall_GodotSharpDirs_BuildLogsDirs,
255
(void *)godot_icall_GodotSharpDirs_DataEditorToolsDir,
256
(void *)godot_icall_GodotSharpDirs_CSharpProjectName,
257
(void *)godot_icall_EditorProgress_Create,
258
(void *)godot_icall_EditorProgress_Dispose,
259
(void *)godot_icall_EditorProgress_Step,
260
(void *)godot_icall_Internal_FullExportTemplatesDir,
261
(void *)godot_icall_Internal_IsMacOSAppBundleInstalled,
262
(void *)godot_icall_Internal_LipOCreateFile,
263
(void *)godot_icall_Internal_GodotIs32Bits,
264
(void *)godot_icall_Internal_GodotIsRealTDouble,
265
(void *)godot_icall_Internal_GodotMainIteration,
266
(void *)godot_icall_Internal_IsAssembliesReloadingNeeded,
267
(void *)godot_icall_Internal_ReloadAssemblies,
268
(void *)godot_icall_Internal_EditorDebuggerNodeReloadScripts,
269
(void *)godot_icall_Internal_ScriptEditorEdit,
270
(void *)godot_icall_Internal_EditorNodeShowScriptScreen,
271
(void *)godot_icall_Internal_EditorRunPlay,
272
(void *)godot_icall_Internal_EditorRunStop,
273
(void *)godot_icall_Internal_EditorPlugin_AddControlToEditorRunBar,
274
(void *)godot_icall_Internal_ScriptEditorDebugger_ReloadScripts,
275
(void *)godot_icall_Internal_CodeCompletionRequest,
276
(void *)godot_icall_Globals_EditorScale,
277
(void *)godot_icall_Globals_GlobalDef,
278
(void *)godot_icall_Globals_EditorDef,
279
(void *)godot_icall_Globals_EditorDefShortcut,
280
(void *)godot_icall_Globals_EditorGetShortcut,
281
(void *)godot_icall_Globals_EditorShortcutOverride,
282
(void *)godot_icall_Globals_TTR,
283
(void *)godot_icall_Utils_OS_GetPlatformName,
284
(void *)godot_icall_Utils_OS_UnixFileHasExecutableAccess,
285
};
286
287
const void **godotsharp::get_editor_interop_funcs(int32_t &r_size) {
288
r_size = sizeof(unmanaged_callbacks);
289
return unmanaged_callbacks;
290
}
291
292