summaryrefslogtreecommitdiff
path: root/modules/gdscript/gdscript_parser.cpp
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2019-01-17 19:17:06 -0200
committerGeorge Marques <george@gmarqu.es>2019-01-23 17:42:06 -0200
commitf439397126f13cd29373e9ae95b963ce92094e25 (patch)
treecabe0b4ca5f0d9aabf067ff720d734d1d1cb4d59 /modules/gdscript/gdscript_parser.cpp
parentf4546fc0cdd64776f5214c3bd9b084cfda39d3d2 (diff)
GDScript: read constants from parent scripts
This is needed to create export variables from enums defined in a parent class.
Diffstat (limited to 'modules/gdscript/gdscript_parser.cpp')
-rw-r--r--modules/gdscript/gdscript_parser.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index ebc83b45a9..2587943e76 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -811,6 +811,21 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s
expr = constant;
bfn = true;
}
+
+ // Check parents for the constant
+ if (!bfn && cln->extends_file != StringName()) {
+ Ref<GDScript> parent = ResourceLoader::load(cln->extends_file);
+ if (parent.is_valid() && parent->is_valid()) {
+ Map<StringName, Variant> parent_constants;
+ parent->get_constants(&parent_constants);
+ if (parent_constants.has(identifier)) {
+ ConstantNode *constant = alloc_node<ConstantNode>();
+ constant->value = parent_constants[identifier];
+ expr = constant;
+ bfn = true;
+ }
+ }
+ }
}
if (!bfn) {