Use OrderedHashMap for autoloads to preserve order
This commit is contained in:
parent
6e87d62873
commit
31f790299c
|
@ -1006,7 +1006,7 @@ bool ProjectSettings::has_custom_feature(const String &p_feature) const {
|
||||||
return custom_features.has(p_feature);
|
return custom_features.has(p_feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<StringName, ProjectSettings::AutoloadInfo> ProjectSettings::get_autoload_list() const {
|
OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> ProjectSettings::get_autoload_list() const {
|
||||||
return autoloads;
|
return autoloads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include "core/object/class_db.h"
|
#include "core/object/class_db.h"
|
||||||
#include "core/os/thread_safe.h"
|
#include "core/os/thread_safe.h"
|
||||||
|
#include "core/templates/ordered_hash_map.h"
|
||||||
#include "core/templates/set.h"
|
#include "core/templates/set.h"
|
||||||
|
|
||||||
class ProjectSettings : public Object {
|
class ProjectSettings : public Object {
|
||||||
|
@ -91,7 +92,7 @@ protected:
|
||||||
Set<String> custom_features;
|
Set<String> custom_features;
|
||||||
Map<StringName, StringName> feature_overrides;
|
Map<StringName, StringName> feature_overrides;
|
||||||
|
|
||||||
Map<StringName, AutoloadInfo> autoloads;
|
OrderedHashMap<StringName, AutoloadInfo> autoloads;
|
||||||
|
|
||||||
bool _set(const StringName &p_name, const Variant &p_value);
|
bool _set(const StringName &p_name, const Variant &p_value);
|
||||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||||
|
@ -168,7 +169,7 @@ public:
|
||||||
|
|
||||||
bool has_custom_feature(const String &p_feature) const;
|
bool has_custom_feature(const String &p_feature) const;
|
||||||
|
|
||||||
Map<StringName, AutoloadInfo> get_autoload_list() const;
|
OrderedHashMap<StringName, AutoloadInfo> get_autoload_list() const;
|
||||||
void add_autoload(const AutoloadInfo &p_autoload);
|
void add_autoload(const AutoloadInfo &p_autoload);
|
||||||
void remove_autoload(const StringName &p_autoload);
|
void remove_autoload(const StringName &p_autoload);
|
||||||
bool has_autoload(const StringName &p_autoload) const;
|
bool has_autoload(const StringName &p_autoload) const;
|
||||||
|
|
|
@ -115,9 +115,9 @@ void EditorStandardSyntaxHighlighter::_update_cache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Autoloads. */
|
/* Autoloads. */
|
||||||
Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
||||||
for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) {
|
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
|
||||||
const ProjectSettings::AutoloadInfo &info = E->value();
|
const ProjectSettings::AutoloadInfo &info = E.value();
|
||||||
if (info.is_singleton) {
|
if (info.is_singleton) {
|
||||||
highlighter->add_keyword_color(info.name, usertype_color);
|
highlighter->add_keyword_color(info.name, usertype_color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2125,11 +2125,11 @@ bool Main::start() {
|
||||||
if (!project_manager && !editor) { // game
|
if (!project_manager && !editor) { // game
|
||||||
if (game_path != "" || script != "") {
|
if (game_path != "" || script != "") {
|
||||||
//autoload
|
//autoload
|
||||||
Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
||||||
|
|
||||||
//first pass, add the constants so they exist before any script is loaded
|
//first pass, add the constants so they exist before any script is loaded
|
||||||
for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) {
|
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
|
||||||
const ProjectSettings::AutoloadInfo &info = E->get();
|
const ProjectSettings::AutoloadInfo &info = E.get();
|
||||||
|
|
||||||
if (info.is_singleton) {
|
if (info.is_singleton) {
|
||||||
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
||||||
|
@ -2140,8 +2140,8 @@ bool Main::start() {
|
||||||
|
|
||||||
//second pass, load into global constants
|
//second pass, load into global constants
|
||||||
List<Node *> to_add;
|
List<Node *> to_add;
|
||||||
for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) {
|
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
|
||||||
const ProjectSettings::AutoloadInfo &info = E->get();
|
const ProjectSettings::AutoloadInfo &info = E.get();
|
||||||
|
|
||||||
RES res = ResourceLoader::load(info.path);
|
RES res = ResourceLoader::load(info.path);
|
||||||
ERR_CONTINUE_MSG(res.is_null(), "Can't autoload: " + info.path);
|
ERR_CONTINUE_MSG(res.is_null(), "Can't autoload: " + info.path);
|
||||||
|
|
|
@ -471,9 +471,9 @@ void GDScriptSyntaxHighlighter::_update_cache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Autoloads. */
|
/* Autoloads. */
|
||||||
Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
||||||
for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) {
|
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
|
||||||
const ProjectSettings::AutoloadInfo &info = E->value();
|
const ProjectSettings::AutoloadInfo &info = E.value();
|
||||||
if (info.is_singleton) {
|
if (info.is_singleton) {
|
||||||
keywords[info.name] = usertype_color;
|
keywords[info.name] = usertype_color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -731,9 +731,9 @@ static void _list_available_types(bool p_inherit_only, GDScriptParser::Completio
|
||||||
}
|
}
|
||||||
|
|
||||||
// Autoload singletons
|
// Autoload singletons
|
||||||
Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
||||||
for (const Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E != nullptr; E = E->next()) {
|
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
|
||||||
const ProjectSettings::AutoloadInfo &info = E->get();
|
const ProjectSettings::AutoloadInfo &info = E.get();
|
||||||
if (!info.is_singleton || info.path.get_extension().to_lower() != "gd") {
|
if (!info.is_singleton || info.path.get_extension().to_lower() != "gd") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1086,12 +1086,12 @@ static void _find_identifiers(GDScriptParser::CompletionContext &p_context, bool
|
||||||
kwa++;
|
kwa++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
||||||
for (const Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E != nullptr; E = E->next()) {
|
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
|
||||||
if (!E->value().is_singleton) {
|
if (!E.value().is_singleton) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ScriptCodeCompletionOption option(E->key(), ScriptCodeCompletionOption::KIND_CONSTANT);
|
ScriptCodeCompletionOption option(E.key(), ScriptCodeCompletionOption::KIND_CONSTANT);
|
||||||
r_result.insert(option.display, option);
|
r_result.insert(option.display, option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1359,12 +1359,12 @@ static bool _guess_expression_type(GDScriptParser::CompletionContext &p_context,
|
||||||
r_type = _type_from_variant(GDScriptLanguage::get_singleton()->get_named_globals_map()[which]);
|
r_type = _type_from_variant(GDScriptLanguage::get_singleton()->get_named_globals_map()[which]);
|
||||||
found = true;
|
found = true;
|
||||||
} else {
|
} else {
|
||||||
Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
||||||
|
|
||||||
for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) {
|
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
|
||||||
String name = E->key();
|
String name = E.key();
|
||||||
if (name == which) {
|
if (name == which) {
|
||||||
String script = E->value().path;
|
String script = E.value().path;
|
||||||
|
|
||||||
if (!script.begins_with("res://")) {
|
if (!script.begins_with("res://")) {
|
||||||
script = "res://" + script;
|
script = "res://" + script;
|
||||||
|
@ -2660,10 +2660,10 @@ static void _find_call_arguments(GDScriptParser::CompletionContext &p_context, c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get autoloads.
|
// Get autoloads.
|
||||||
Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
||||||
|
|
||||||
for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) {
|
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
|
||||||
String path = "/root/" + E->key();
|
String path = "/root/" + E.key();
|
||||||
ScriptCodeCompletionOption option(path.quote(quote_style), ScriptCodeCompletionOption::KIND_NODE_PATH);
|
ScriptCodeCompletionOption option(path.quote(quote_style), ScriptCodeCompletionOption::KIND_NODE_PATH);
|
||||||
options.insert(option.display, option);
|
options.insert(option.display, option);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,11 +48,11 @@
|
||||||
namespace GDScriptTests {
|
namespace GDScriptTests {
|
||||||
|
|
||||||
void init_autoloads() {
|
void init_autoloads() {
|
||||||
Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
||||||
|
|
||||||
// First pass, add the constants so they exist before any script is loaded.
|
// First pass, add the constants so they exist before any script is loaded.
|
||||||
for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) {
|
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
|
||||||
const ProjectSettings::AutoloadInfo &info = E->get();
|
const ProjectSettings::AutoloadInfo &info = E.get();
|
||||||
|
|
||||||
if (info.is_singleton) {
|
if (info.is_singleton) {
|
||||||
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
||||||
|
@ -62,8 +62,8 @@ void init_autoloads() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second pass, load into global constants.
|
// Second pass, load into global constants.
|
||||||
for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) {
|
for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) {
|
||||||
const ProjectSettings::AutoloadInfo &info = E->get();
|
const ProjectSettings::AutoloadInfo &info = E.get();
|
||||||
|
|
||||||
if (!info.is_singleton) {
|
if (!info.is_singleton) {
|
||||||
// Skip non-singletons since we don't have a scene tree here anyway.
|
// Skip non-singletons since we don't have a scene tree here anyway.
|
||||||
|
|
|
@ -121,7 +121,7 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr
|
||||||
case CompletionKind::NODE_PATHS: {
|
case CompletionKind::NODE_PATHS: {
|
||||||
{
|
{
|
||||||
// AutoLoads
|
// AutoLoads
|
||||||
Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
|
||||||
|
|
||||||
for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : autoloads) {
|
for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : autoloads) {
|
||||||
const ProjectSettings::AutoloadInfo &info = E.value;
|
const ProjectSettings::AutoloadInfo &info = E.value;
|
||||||
|
|
Loading…
Reference in a new issue