-
Notifications
You must be signed in to change notification settings - Fork 82
/
register_types.cpp
85 lines (67 loc) · 2.96 KB
/
register_types.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "register_types.h"
#include "javascript.h"
#include "src/language/javascript_language.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_node.h"
#include "editor/editor_tools.h"
#include "editor/export/editor_export.h"
void editor_init_callback();
class EditorExportJavaScript : public EditorExportPlugin {
GDCLASS(EditorExportJavaScript, EditorExportPlugin);
public:
virtual void _export_file(const String &p_path, const String &p_type, const HashSet<String> &p_features) override {
String extension = p_path.get_extension();
if (extension != EXT_JSCLASS && extension != EXT_JSMODULE) {
return;
}
}
virtual String _get_name() const override { return EXT_NAME; }
};
#endif
Ref<ResourceFormatLoaderJavaScript> resource_loader_javascript;
Ref<ResourceFormatSaverJavaScript> resource_saver_javascript;
Ref<ResourceFormatLoaderJavaScriptModule> resource_loader_javascript_module;
Ref<ResourceFormatSaverJavaScriptModule> resource_saver_javascript_module;
static JavaScriptLanguage *script_language_js = nullptr;
void initialize_javascript_module(ModuleInitializationLevel p_level) {
if (p_level != ModuleInitializationLevel::MODULE_INITIALIZATION_LEVEL_CORE)
return;
ClassDB::register_class<JavaScript>();
ClassDB::register_class<JavaScriptModule>();
resource_loader_javascript.instantiate();
resource_saver_javascript.instantiate();
ResourceLoader::add_resource_format_loader(resource_loader_javascript, true);
ResourceSaver::add_resource_format_saver(resource_saver_javascript, true);
resource_loader_javascript_module.instantiate();
resource_saver_javascript_module.instantiate();
ResourceLoader::add_resource_format_loader(resource_loader_javascript_module, true);
ResourceSaver::add_resource_format_saver(resource_saver_javascript_module, true);
script_language_js = memnew(JavaScriptLanguage);
ScriptServer::register_language(script_language_js);
#ifdef TOOLS_ENABLED
EditorNode::add_init_callback(editor_init_callback);
#endif
}
void uninitialize_javascript_module(ModuleInitializationLevel p_level) {
if (p_level != ModuleInitializationLevel::MODULE_INITIALIZATION_LEVEL_CORE)
return;
ScriptServer::unregister_language(script_language_js);
memdelete(script_language_js);
ResourceLoader::remove_resource_format_loader(resource_loader_javascript);
ResourceSaver::remove_resource_format_saver(resource_saver_javascript);
resource_loader_javascript.unref();
resource_saver_javascript.unref();
ResourceLoader::remove_resource_format_loader(resource_loader_javascript_module);
ResourceSaver::remove_resource_format_saver(resource_saver_javascript_module);
resource_loader_javascript_module.unref();
resource_saver_javascript_module.unref();
}
#ifdef TOOLS_ENABLED
void editor_init_callback() {
JavaScriptPlugin *plugin = memnew(JavaScriptPlugin(EditorNode::get_singleton()));
EditorNode::get_singleton()->add_editor_plugin(plugin);
Ref<EditorExportJavaScript> js_export;
js_export.instantiate();
EditorExport::get_singleton()->add_export_plugin(js_export);
}
#endif