Merge pull request #26665 from bojidar-bg/19704-singleton-constants

Fix enums coming from other classes without preload
This commit is contained in:
Rémi Verschelde 2019-03-06 18:20:48 +01:00 committed by GitHub
commit c67e9a4dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View File

@ -409,6 +409,11 @@ bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) co
return true;
}
if (constants.has(p_name)) {
r_ret = constants[p_name];
return true;
}
if (!script->is_placeholder_fallback_enabled()) {
Variant defval;
if (script->get_property_default_value(p_name, defval)) {
@ -444,6 +449,13 @@ Variant::Type PlaceHolderScriptInstance::get_property_type(const StringName &p_n
*r_is_valid = true;
return values[p_name].get_type();
}
if (constants.has(p_name)) {
if (r_is_valid)
*r_is_valid = true;
return constants[p_name].get_type();
}
if (r_is_valid)
*r_is_valid = false;
@ -513,6 +525,9 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
owner->_change_notify();
}
//change notify
constants.clear();
script->get_constants(&constants);
}
void PlaceHolderScriptInstance::property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid) {
@ -552,6 +567,13 @@ Variant PlaceHolderScriptInstance::property_get_fallback(const StringName &p_nam
*r_valid = true;
return E->value();
}
E = constants.find(p_name);
if (E) {
if (r_valid)
*r_valid = true;
return E->value();
}
}
if (r_valid)

View File

@ -336,6 +336,7 @@ class PlaceHolderScriptInstance : public ScriptInstance {
Object *owner;
List<PropertyInfo> properties;
Map<StringName, Variant> values;
Map<StringName, Variant> constants;
ScriptLanguage *language;
Ref<Script> script;

View File

@ -815,6 +815,16 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
}
if (!dependencies_only) {
if (!bfn && ScriptServer::is_global_class(identifier)) {
Ref<Script> scr = ResourceLoader::load(ScriptServer::get_global_class_path(identifier));
if (scr.is_valid() && scr->is_valid()) {
ConstantNode *constant = alloc_node<ConstantNode>();
constant->value = scr;
expr = constant;
bfn = true;
}
}
// Check parents for the constant
if (!bfn && cln->extends_file != StringName()) {
Ref<GDScript> parent = ResourceLoader::load(cln->extends_file);
@ -7247,6 +7257,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_identifier_type(const DataType
DataType result;
result.has_type = true;
result.script_type = scr;
result.is_constant = true;
result.is_meta_type = true;
Ref<GDScript> gds = scr;
if (gds.is_valid()) {
@ -7297,6 +7308,7 @@ GDScriptParser::DataType GDScriptParser::_reduce_identifier_type(const DataType
if (singleton.is_valid()) {
DataType result;
result.has_type = true;
result.is_constant = true;
result.script_type = singleton;
Ref<GDScript> gds = singleton;