-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
register_types.cpp
65 lines (52 loc) · 2.05 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
#include "register_types.h"
#include "weaver/jsb_script_language.h"
#include "weaver/jsb_script.h"
#include "weaver/jsb_resource_loader.h"
#include "weaver/jsb_resource_saver.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_node.h"
#include "editor/export/editor_export.h"
#include "weaver-editor/jsb_editor_plugin.h"
#include "weaver-editor/jsb_export_plugin.h"
#endif
Ref<ResourceFormatLoaderGodotJSScript> resource_loader_js;
Ref<ResourceFormatSaverGodotJSScript> resource_saver_js;
void jsb_initialize_module(ModuleInitializationLevel p_level)
{
if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS)
{
GDREGISTER_CLASS(GodotJSScript);
// register javascript language
GodotJSScriptLanguage* script_language_js = memnew(GodotJSScriptLanguage());
ScriptServer::register_language(script_language_js);
resource_loader_js.instantiate();
ResourceLoader::add_resource_format_loader(resource_loader_js);
resource_saver_js.instantiate();
ResourceSaver::add_resource_format_saver(resource_saver_js);
#ifdef TOOLS_ENABLED
EditorNode::add_init_callback([]
{
GodotJSEditorPlugin* plugin = memnew(GodotJSEditorPlugin);
EditorNode::add_editor_plugin(plugin);
Ref<GodotJSExportPlugin> exporter;
exporter.instantiate();
EditorExport::get_singleton()->add_export_plugin(exporter);
plugin->set_name(jsb_typename(GodotJSEditorPlugin));
});
#endif
}
}
void jsb_uninitialize_module(ModuleInitializationLevel p_level)
{
if (p_level == MODULE_INITIALIZATION_LEVEL_CORE)
{
ResourceLoader::remove_resource_format_loader(resource_loader_js);
resource_loader_js.unref();
ResourceSaver::remove_resource_format_saver(resource_saver_js);
resource_saver_js.unref();
GodotJSScriptLanguage *script_language_js = GodotJSScriptLanguage::get_singleton();
jsb_check(script_language_js);
ScriptServer::unregister_language(script_language_js);
memdelete(script_language_js);
}
}