Add Script::inherits_script()
Partial cherry-pick of 5d4dc2d45c
.
Co-authored-by: Juan Linietsky <reduzio@gmail.com>
This commit is contained in:
parent
504f47eaec
commit
7426b3fa91
11 changed files with 54 additions and 0 deletions
|
@ -119,6 +119,8 @@ public:
|
|||
|
||||
virtual Ref<Script> get_base_script() const = 0; //for script inheritance
|
||||
|
||||
virtual bool inherits_script(const Ref<Script> &p_script) const = 0;
|
||||
|
||||
virtual StringName get_instance_base_type() const = 0; // this may not work in all scripts, will return empty if so
|
||||
virtual ScriptInstance *instance_create(Object *p_this) = 0;
|
||||
virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) { return nullptr; }
|
||||
|
|
|
@ -111,6 +111,11 @@ void NativeScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder)
|
|||
|
||||
#endif
|
||||
|
||||
bool NativeScript::inherits_script(const Ref<Script> &p_script) const {
|
||||
WARN_PRINT_ONCE("Inheritance needs to be implemented in NativeScript.");
|
||||
return false;
|
||||
}
|
||||
|
||||
void NativeScript::set_class_name(String p_class_name) {
|
||||
class_name = p_class_name;
|
||||
}
|
||||
|
|
|
@ -130,6 +130,8 @@ protected:
|
|||
public:
|
||||
inline NativeScriptDesc *get_script_desc() const;
|
||||
|
||||
bool inherits_script(const Ref<Script> &p_script) const;
|
||||
|
||||
void set_class_name(String p_class_name);
|
||||
String get_class_name() const;
|
||||
|
||||
|
|
|
@ -136,6 +136,11 @@ bool PluginScript::can_instance() const {
|
|||
return can;
|
||||
}
|
||||
|
||||
bool PluginScript::inherits_script(const Ref<Script> &p_script) const {
|
||||
WARN_PRINT_ONCE("Inheritance needs to be implemented in PluginScript.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Ref<Script> PluginScript::get_base_script() const {
|
||||
if (_ref_base_parent.is_valid()) {
|
||||
return Ref<PluginScript>(_ref_base_parent);
|
||||
|
|
|
@ -71,6 +71,8 @@ private:
|
|||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
bool inherits_script(const Ref<Script> &p_script) const;
|
||||
|
||||
PluginScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, Variant::CallError &r_error);
|
||||
Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
|
||||
|
||||
|
|
|
@ -815,6 +815,24 @@ Ref<GDScript> GDScript::get_base() const {
|
|||
return base;
|
||||
}
|
||||
|
||||
bool GDScript::inherits_script(const Ref<Script> &p_script) const {
|
||||
Ref<GDScript> gd = p_script;
|
||||
if (gd.is_null()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const GDScript *s = this;
|
||||
|
||||
while (s) {
|
||||
if (s == p_script.ptr()) {
|
||||
return true;
|
||||
}
|
||||
s = s->_base;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GDScript::has_script_signal(const StringName &p_signal) const {
|
||||
if (_signals.has(p_signal)) {
|
||||
return true;
|
||||
|
|
|
@ -146,6 +146,8 @@ protected:
|
|||
public:
|
||||
virtual bool is_valid() const { return valid; }
|
||||
|
||||
bool inherits_script(const Ref<Script> &p_script) const;
|
||||
|
||||
const Map<StringName, Ref<GDScript>> &get_subclasses() const { return subclasses; }
|
||||
const Map<StringName, Variant> &get_constants() const { return constants; }
|
||||
const Set<StringName> &get_members() const { return members; }
|
||||
|
|
|
@ -3205,6 +3205,16 @@ void CSharpScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
|
|||
}
|
||||
}
|
||||
|
||||
bool CSharpScript::inherits_script(const Ref<Script> &p_script) const {
|
||||
Ref<CSharpScript> cs = p_script;
|
||||
if (cs.is_null()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
WARN_PRINT_ONCE("Implement CSharpScript::inherits_script and other relevant changes after GH-38063.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Ref<Script> CSharpScript::get_base_script() const {
|
||||
// TODO search in metadata file once we have it, not important any way?
|
||||
return Ref<Script>();
|
||||
|
|
|
@ -184,6 +184,8 @@ public:
|
|||
virtual bool is_tool() const { return tool; }
|
||||
virtual bool is_valid() const { return valid; }
|
||||
|
||||
bool inherits_script(const Ref<Script> &p_script) const;
|
||||
|
||||
virtual Ref<Script> get_base_script() const;
|
||||
virtual ScriptLanguage *get_language() const;
|
||||
|
||||
|
|
|
@ -1265,6 +1265,10 @@ VisualScript::VisualScript() {
|
|||
is_tool_script = false;
|
||||
}
|
||||
|
||||
bool VisualScript::inherits_script(const Ref<Script> &p_script) const {
|
||||
return this == p_script.ptr(); //there is no inheritance in visual scripts, so this is enough
|
||||
}
|
||||
|
||||
StringName VisualScript::get_default_func() const {
|
||||
return StringName("f_312843592");
|
||||
}
|
||||
|
|
|
@ -260,6 +260,8 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
bool inherits_script(const Ref<Script> &p_script) const;
|
||||
|
||||
// TODO: Remove it in future when breaking changes are acceptable
|
||||
StringName get_default_func() const;
|
||||
void add_function(const StringName &p_name);
|
||||
|
|
Loading…
Reference in a new issue