2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* register_types.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
2021-01-01 20:13:46 +01:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2016-06-18 14:46:12 +02:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-24 13:53:33 +01:00
|
|
|
#include "register_types.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-06-11 14:51:48 +02:00
|
|
|
#include "core/io/dir_access.h"
|
|
|
|
#include "core/io/file_access.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/io/file_access_encrypted.h"
|
|
|
|
#include "core/io/resource_loader.h"
|
2017-11-16 18:38:18 +01:00
|
|
|
#include "gdscript.h"
|
2020-08-01 21:00:26 +02:00
|
|
|
#include "gdscript_analyzer.h"
|
2020-06-10 23:15:09 +02:00
|
|
|
#include "gdscript_cache.h"
|
2017-12-14 19:33:54 +01:00
|
|
|
#include "gdscript_tokenizer.h"
|
2020-11-26 15:56:32 +01:00
|
|
|
#include "gdscript_utility_functions.h"
|
2014-02-25 13:31:47 +01:00
|
|
|
|
2020-08-18 16:24:45 +02:00
|
|
|
#ifdef TESTS_ENABLED
|
|
|
|
#include "tests/test_gdscript.h"
|
|
|
|
#include "tests/test_macros.h"
|
|
|
|
#endif
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
GDScriptLanguage *script_language_gd = nullptr;
|
2018-06-11 02:59:53 +02:00
|
|
|
Ref<ResourceFormatLoaderGDScript> resource_loader_gd;
|
|
|
|
Ref<ResourceFormatSaverGDScript> resource_saver_gd;
|
2020-06-10 23:15:09 +02:00
|
|
|
GDScriptCache *gdscript_cache = nullptr;
|
2014-02-25 13:31:47 +01:00
|
|
|
|
2017-12-14 19:33:54 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
|
|
|
#include "editor/editor_export.h"
|
|
|
|
#include "editor/editor_node.h"
|
|
|
|
#include "editor/editor_settings.h"
|
2020-06-23 13:48:59 +02:00
|
|
|
#include "editor/editor_translation_parser.h"
|
2019-08-28 13:10:32 +02:00
|
|
|
#include "editor/gdscript_highlighter.h"
|
2020-06-23 13:48:59 +02:00
|
|
|
#include "editor/gdscript_translation_parser_plugin.h"
|
2019-08-28 13:10:32 +02:00
|
|
|
|
|
|
|
#ifndef GDSCRIPT_NO_LSP
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/config/engine.h"
|
2019-08-28 13:10:32 +02:00
|
|
|
#include "language_server/gdscript_language_server.h"
|
|
|
|
#endif // !GDSCRIPT_NO_LSP
|
2017-12-14 19:33:54 +01:00
|
|
|
|
2020-07-29 23:17:58 +02:00
|
|
|
Ref<GDScriptEditorTranslationParserPlugin> gdscript_translation_parser_plugin;
|
|
|
|
|
2017-12-14 19:33:54 +01:00
|
|
|
class EditorExportGDScript : public EditorExportPlugin {
|
|
|
|
GDCLASS(EditorExportGDScript, EditorExportPlugin);
|
|
|
|
|
|
|
|
public:
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features) override {
|
2018-12-23 19:28:29 +01:00
|
|
|
int script_mode = EditorExportPreset::MODE_SCRIPT_COMPILED;
|
|
|
|
String script_key;
|
|
|
|
|
|
|
|
const Ref<EditorExportPreset> &preset = get_export_preset();
|
|
|
|
|
|
|
|
if (preset.is_valid()) {
|
|
|
|
script_mode = preset->get_script_export_mode();
|
|
|
|
script_key = preset->get_script_encryption_key().to_lower();
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!p_path.ends_with(".gd") || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) {
|
2017-12-14 19:33:54 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-12-14 19:33:54 +01:00
|
|
|
|
2021-03-12 14:35:16 +01:00
|
|
|
// TODO: Re-add compiled GDScript on export.
|
2020-05-02 00:14:56 +02:00
|
|
|
return;
|
2017-12-14 19:33:54 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void _editor_init() {
|
|
|
|
Ref<EditorExportGDScript> gd_export;
|
2021-06-18 00:03:09 +02:00
|
|
|
gd_export.instantiate();
|
2017-12-14 19:33:54 +01:00
|
|
|
EditorExport::get_singleton()->add_export_plugin(gd_export);
|
2019-06-26 14:21:42 +02:00
|
|
|
|
2020-03-07 15:29:44 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
Ref<GDScriptSyntaxHighlighter> gdscript_syntax_highlighter;
|
2021-06-18 00:03:09 +02:00
|
|
|
gdscript_syntax_highlighter.instantiate();
|
2020-03-07 15:29:44 +01:00
|
|
|
ScriptEditor::get_singleton()->register_syntax_highlighter(gdscript_syntax_highlighter);
|
|
|
|
#endif
|
|
|
|
|
2019-08-28 13:10:32 +02:00
|
|
|
#ifndef GDSCRIPT_NO_LSP
|
2019-06-14 16:38:54 +02:00
|
|
|
register_lsp_types();
|
2019-06-26 14:21:42 +02:00
|
|
|
GDScriptLanguageServer *lsp_plugin = memnew(GDScriptLanguageServer);
|
|
|
|
EditorNode::get_singleton()->add_editor_plugin(lsp_plugin);
|
|
|
|
Engine::get_singleton()->add_singleton(Engine::Singleton("GDScriptLanguageProtocol", GDScriptLanguageProtocol::get_singleton()));
|
2019-08-28 13:10:32 +02:00
|
|
|
#endif // !GDSCRIPT_NO_LSP
|
2017-12-14 19:33:54 +01:00
|
|
|
}
|
|
|
|
|
2019-08-28 13:10:32 +02:00
|
|
|
#endif // TOOLS_ENABLED
|
2017-12-14 19:33:54 +01:00
|
|
|
|
2014-02-24 13:53:33 +01:00
|
|
|
void register_gdscript_types() {
|
2021-07-12 00:30:33 +02:00
|
|
|
GDREGISTER_CLASS(GDScript);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
script_language_gd = memnew(GDScriptLanguage);
|
2014-02-10 02:10:30 +01:00
|
|
|
ScriptServer::register_language(script_language_gd);
|
2018-06-11 02:59:53 +02:00
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
resource_loader_gd.instantiate();
|
2014-02-10 02:10:30 +01:00
|
|
|
ResourceLoader::add_resource_format_loader(resource_loader_gd);
|
2018-06-11 02:59:53 +02:00
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
resource_saver_gd.instantiate();
|
2014-02-10 02:10:30 +01:00
|
|
|
ResourceSaver::add_resource_format_saver(resource_saver_gd);
|
2017-12-14 19:33:54 +01:00
|
|
|
|
2020-06-10 23:15:09 +02:00
|
|
|
gdscript_cache = memnew(GDScriptCache);
|
|
|
|
|
2017-12-14 19:33:54 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
EditorNode::add_init_callback(_editor_init);
|
2020-06-23 13:48:59 +02:00
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
gdscript_translation_parser_plugin.instantiate();
|
2020-06-23 13:48:59 +02:00
|
|
|
EditorTranslationParser::get_singleton()->add_parser(gdscript_translation_parser_plugin, EditorTranslationParser::STANDARD);
|
2019-08-28 13:10:32 +02:00
|
|
|
#endif // TOOLS_ENABLED
|
2020-11-26 15:56:32 +01:00
|
|
|
|
|
|
|
GDScriptUtilityFunctions::register_functions();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-08-27 21:07:15 +02:00
|
|
|
|
2014-02-24 13:53:33 +01:00
|
|
|
void unregister_gdscript_types() {
|
2016-06-26 15:53:34 +02:00
|
|
|
ScriptServer::unregister_language(script_language_gd);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-06-10 23:15:09 +02:00
|
|
|
if (gdscript_cache) {
|
|
|
|
memdelete(gdscript_cache);
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (script_language_gd) {
|
2017-03-05 16:44:50 +01:00
|
|
|
memdelete(script_language_gd);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-06-11 02:59:53 +02:00
|
|
|
|
2019-01-10 12:45:57 +01:00
|
|
|
ResourceLoader::remove_resource_format_loader(resource_loader_gd);
|
|
|
|
resource_loader_gd.unref();
|
2018-06-11 02:59:53 +02:00
|
|
|
|
2019-01-10 12:45:57 +01:00
|
|
|
ResourceSaver::remove_resource_format_saver(resource_saver_gd);
|
|
|
|
resource_saver_gd.unref();
|
2020-07-29 23:17:58 +02:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
EditorTranslationParser::get_singleton()->remove_parser(gdscript_translation_parser_plugin, EditorTranslationParser::STANDARD);
|
|
|
|
gdscript_translation_parser_plugin.unref();
|
|
|
|
#endif // TOOLS_ENABLED
|
2020-08-01 21:00:26 +02:00
|
|
|
|
|
|
|
GDScriptParser::cleanup();
|
2020-11-26 15:56:32 +01:00
|
|
|
GDScriptUtilityFunctions::unregister_functions();
|
2014-02-25 13:31:47 +01:00
|
|
|
}
|
2020-08-18 16:24:45 +02:00
|
|
|
|
|
|
|
#ifdef TESTS_ENABLED
|
|
|
|
void test_tokenizer() {
|
2021-04-07 15:12:51 +02:00
|
|
|
GDScriptTests::test(GDScriptTests::TestType::TEST_TOKENIZER);
|
2020-08-18 16:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_parser() {
|
2021-04-07 15:12:51 +02:00
|
|
|
GDScriptTests::test(GDScriptTests::TestType::TEST_PARSER);
|
2020-08-18 16:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_compiler() {
|
2021-04-07 15:12:51 +02:00
|
|
|
GDScriptTests::test(GDScriptTests::TestType::TEST_COMPILER);
|
2020-08-18 16:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_bytecode() {
|
2021-04-07 15:12:51 +02:00
|
|
|
GDScriptTests::test(GDScriptTests::TestType::TEST_BYTECODE);
|
2020-08-18 16:24:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_TEST_COMMAND("gdscript-tokenizer", &test_tokenizer);
|
|
|
|
REGISTER_TEST_COMMAND("gdscript-parser", &test_parser);
|
|
|
|
REGISTER_TEST_COMMAND("gdscript-compiler", &test_compiler);
|
|
|
|
REGISTER_TEST_COMMAND("gdscript-bytecode", &test_bytecode);
|
|
|
|
#endif
|