|
@@ -33,6 +33,7 @@
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
|
|
|
+#include "core/config/project_settings.h"
|
|
#include "core/io/config_file.h"
|
|
#include "core/io/config_file.h"
|
|
#include "core/io/dir_access.h"
|
|
#include "core/io/dir_access.h"
|
|
#include "core/io/file_access.h"
|
|
#include "core/io/file_access.h"
|
|
@@ -111,7 +112,10 @@ static void test_directory(const String &p_dir) {
|
|
// For ease of reading ➡ (0x27A1) acts as sentinel char instead of 0xFFFF in the files.
|
|
// For ease of reading ➡ (0x27A1) acts as sentinel char instead of 0xFFFF in the files.
|
|
code = code.replace_first(String::chr(0x27A1), String::chr(0xFFFF));
|
|
code = code.replace_first(String::chr(0x27A1), String::chr(0xFFFF));
|
|
// Require pointer sentinel char in scripts.
|
|
// Require pointer sentinel char in scripts.
|
|
- CHECK(code.find_char(0xFFFF) != -1);
|
|
|
|
|
|
+ int location = code.find_char(0xFFFF);
|
|
|
|
+ CHECK(location != -1);
|
|
|
|
+
|
|
|
|
+ String res_path = ProjectSettings::get_singleton()->localize_path(path.path_join(next));
|
|
|
|
|
|
ConfigFile conf;
|
|
ConfigFile conf;
|
|
if (conf.load(path.path_join(next.get_basename() + ".cfg")) != OK) {
|
|
if (conf.load(path.path_join(next.get_basename() + ".cfg")) != OK) {
|
|
@@ -137,20 +141,46 @@ static void test_directory(const String &p_dir) {
|
|
String call_hint;
|
|
String call_hint;
|
|
bool forced;
|
|
bool forced;
|
|
|
|
|
|
- Node *owner = nullptr;
|
|
|
|
|
|
+ Node *scene = nullptr;
|
|
if (conf.has_section_key("input", "scene")) {
|
|
if (conf.has_section_key("input", "scene")) {
|
|
- Ref<PackedScene> scene = ResourceLoader::load(conf.get_value("input", "scene"), "PackedScene", ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP);
|
|
|
|
- if (scene.is_valid()) {
|
|
|
|
- owner = scene->instantiate();
|
|
|
|
|
|
+ Ref<PackedScene> packed_scene = ResourceLoader::load(conf.get_value("input", "scene"), "PackedScene", ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP);
|
|
|
|
+ if (packed_scene.is_valid()) {
|
|
|
|
+ scene = packed_scene->instantiate();
|
|
}
|
|
}
|
|
} else if (dir->file_exists(next.get_basename() + ".tscn")) {
|
|
} else if (dir->file_exists(next.get_basename() + ".tscn")) {
|
|
- Ref<PackedScene> scene = ResourceLoader::load(path.path_join(next.get_basename() + ".tscn"), "PackedScene");
|
|
|
|
- if (scene.is_valid()) {
|
|
|
|
- owner = scene->instantiate();
|
|
|
|
|
|
+ Ref<PackedScene> packed_scene = ResourceLoader::load(path.path_join(next.get_basename() + ".tscn"), "PackedScene");
|
|
|
|
+ if (packed_scene.is_valid()) {
|
|
|
|
+ scene = packed_scene->instantiate();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Node *owner = nullptr;
|
|
|
|
+ if (scene != nullptr) {
|
|
|
|
+ owner = scene->get_node(conf.get_value("input", "node_path", "."));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (owner != nullptr) {
|
|
|
|
+ // Remove the line which contains the sentinel char, to get a valid script.
|
|
|
|
+ Ref<GDScript> scr;
|
|
|
|
+ scr.instantiate();
|
|
|
|
+ int start = location;
|
|
|
|
+ int end = location;
|
|
|
|
+ for (; start >= 0; --start) {
|
|
|
|
+ if (code.get(start) == '\n') {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (; end < code.size(); ++end) {
|
|
|
|
+ if (code.get(end) == '\n') {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ scr->set_source_code(code.erase(start, end - start));
|
|
|
|
+ scr->reload();
|
|
|
|
+ scr->set_path(res_path);
|
|
|
|
+ owner->set_script(scr);
|
|
}
|
|
}
|
|
|
|
|
|
- GDScriptLanguage::get_singleton()->complete_code(code, path.path_join(next), owner, &options, forced, call_hint);
|
|
|
|
|
|
+ GDScriptLanguage::get_singleton()->complete_code(code, res_path, owner, &options, forced, call_hint);
|
|
String contains_excluded;
|
|
String contains_excluded;
|
|
for (ScriptLanguage::CodeCompletionOption &option : options) {
|
|
for (ScriptLanguage::CodeCompletionOption &option : options) {
|
|
for (const Dictionary &E : exclude) {
|
|
for (const Dictionary &E : exclude) {
|
|
@@ -179,8 +209,8 @@ static void test_directory(const String &p_dir) {
|
|
CHECK(expected_call_hint == call_hint);
|
|
CHECK(expected_call_hint == call_hint);
|
|
CHECK(expected_forced == forced);
|
|
CHECK(expected_forced == forced);
|
|
|
|
|
|
- if (owner) {
|
|
|
|
- memdelete(owner);
|
|
|
|
|
|
+ if (scene) {
|
|
|
|
+ memdelete(scene);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
next = dir->get_next();
|
|
next = dir->get_next();
|