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