From 12514cfebccff235f44f3bdbfc99441953202636 Mon Sep 17 00:00:00 2001 From: Karroffel Date: Thu, 6 Apr 2017 03:34:09 +0200 Subject: [DLScript] inheritance fixes This properly implements script inheritance for DLScripts. --- modules/dlscript/dl_script.cpp | 96 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 84 insertions(+), 12 deletions(-) (limited to 'modules/dlscript/dl_script.cpp') diff --git a/modules/dlscript/dl_script.cpp b/modules/dlscript/dl_script.cpp index 9917018891..449d7b4b17 100644 --- a/modules/dlscript/dl_script.cpp +++ b/modules/dlscript/dl_script.cpp @@ -176,36 +176,84 @@ Error DLScript::reload(bool p_keep_state) { bool DLScript::has_method(const StringName &p_method) const { if (!script_data) return false; - return script_data->methods.has(p_method); + DLScriptData *data = script_data; + + while (data) { + if (data->methods.has(p_method)) + return true; + + data = data->base_data; + } + + return false; } MethodInfo DLScript::get_method_info(const StringName &p_method) const { if (!script_data) return MethodInfo(); + DLScriptData *data = script_data; + + while (data) { + if (data->methods.has(p_method)) + return data->methods[p_method].info; + + data = data->base_data; + } + ERR_FAIL_COND_V(!script_data->methods.has(p_method), MethodInfo()); - return script_data->methods[p_method].info; + return MethodInfo(); } void DLScript::get_script_method_list(List *p_list) const { if (!script_data) return; - for (Map::Element *E = script_data->methods.front(); E; E = E->next()) { - p_list->push_back(E->get().info); + + Set methods; + DLScriptData *data = script_data; + + while (data) { + for (Map::Element *E = data->methods.front(); E; E = E->next()) { + methods.insert(E->get().info); + } + data = data->base_data; + } + + for (Set::Element *E = methods.front(); E; E = E->next()) { + p_list->push_back(E->get()); } } void DLScript::get_script_property_list(List *p_list) const { if (!script_data) return; - for (Map::Element *E = script_data->properties.front(); E; E = E->next()) { - p_list->push_back(E->get().info); + + Set properties; + DLScriptData *data = script_data; + + while (data) { + for (Map::Element *E = data->properties.front(); E; E = E->next()) { + properties.insert(E->get().info); + } + data = data->base_data; + } + + for (Set::Element *E = properties.front(); E; E = E->next()) { + p_list->push_back(E->get()); } } bool DLScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { if (!script_data) return false; - if (script_data->properties.has(p_property)) { - r_value = script_data->properties[p_property].default_value; - return true; + + DLScriptData *data = script_data; + + while (data) { + if (data->properties.has(p_property)) { + r_value = data->properties[p_property].default_value; + return true; + } + + data = data->base_data; } + return false; } @@ -225,14 +273,38 @@ ScriptLanguage *DLScript::get_language() const { bool DLScript::has_script_signal(const StringName &p_signal) const { if (!script_data) return false; - return script_data->signals_.has(p_signal); + + DLScriptData *data = script_data; + + while (data) { + if (data->signals_.has(p_signal)) { + return true; + } + + data = data->base_data; + } + + return false; } void DLScript::get_script_signal_list(List *r_signals) const { if (!script_data) return; - for (Map::Element *S = script_data->signals_.front(); S; S = S->next()) { - r_signals->push_back(S->get().signal); + + Set signals_; + DLScriptData *data = script_data; + + while (data) { + + for (Map::Element *S = data->signals_.front(); S; S = S->next()) { + signals_.insert(S->get().signal); + } + + data = data->base_data; + } + + for (Set::Element *E = signals_.front(); E; E = E->next()) { + r_signals->push_back(E->get()); } } -- cgit v1.2.3