Fix name generation broken in module

This commit is contained in:
Serhii Snitsaruk 2024-01-13 13:35:16 +01:00
parent 947e253bf9
commit eec085278a
2 changed files with 25 additions and 19 deletions

View File

@ -51,27 +51,20 @@ void BT::_bind_methods() {
}
String BTTask::_generate_name() {
#ifdef LIMBOAI_MODULE
if (get_script_instance()) {
if (get_script_instance()->has_method(LimboStringNames::get_singleton()->_generate_name)) {
ERR_FAIL_COND_V_MSG(!get_script_instance()->get_script()->is_tool(), "ERROR: not a tool script", "Task script should be a \"tool\" script!");
return get_script_instance()->call(LimboStringNames::get_singleton()->_generate_name);
}
String script_path = get_script_instance()->get_script()->get_path();
if (!script_path.is_empty()) {
// Generate name based on script file
return script_path.get_basename().get_file().trim_prefix("BT").to_pascal_case();
}
}
return get_class().trim_prefix("BT");
#endif // LIMBOAI_MODULE
String ret;
#ifdef LIMBOAI_GDEXTENSION
if (IS_RESOURCE_FILE(get_path())) {
return get_path().get_basename().get_file().trim_prefix("BT").to_pascal_case();
// Generate name based on script path.
Ref<Script> sc = GET_SCRIPT(this);
if (sc.is_valid() && sc->get_path().is_absolute_path()) {
ret = sc->get_path().get_basename().get_file().to_pascal_case();
}
return get_class().trim_prefix("BT");
#endif // LIMBOAI_GDEXTENSION
// Generate name based on core class name.
if (ret.is_empty()) {
ret = get_class();
}
return ret.trim_prefix("BT");
}
Array BTTask::_get_children() const {
@ -100,7 +93,18 @@ void BTTask::_set_children(Array p_children) {
String BTTask::get_task_name() {
if (data.custom_name.is_empty()) {
#ifdef LIMBOAI_MODULE
if (get_script_instance() && get_script_instance()->has_method(LW_NAME(_generate_name))) {
if (unlikely(!get_script_instance()->get_script()->is_tool())) {
ERR_PRINT(vformat("BTTask: Task script should be a \"tool\" script!"));
} else {
return get_script_instance()->call(LimboStringNames::get_singleton()->_generate_name);
}
}
return _generate_name();
#else // LIMBOAI_GDEXTENSION
return call(LimboStringNames::get_singleton()->_generate_name);
#endif
}
return data.custom_name;
}

View File

@ -53,6 +53,7 @@
#define FILE_EXISTS(m_path) FileAccess::exists(m_path)
#define DIR_ACCESS_CREATE() DirAccess::create(DirAccess::ACCESS_RESOURCES)
#define PERFORMANCE_ADD_CUSTOM_MONITOR(m_id, m_callable) (Performance::get_singleton()->add_custom_monitor(m_id, m_callable, Variant()))
#define GET_SCRIPT(m_obj) (m_obj->get_script_instance() ? m_obj->get_script_instance()->get_script() : nullptr)
#define VARIANT_EVALUATE(m_op, m_lvalue, m_rvalue, r_ret) r_ret = Variant::evaluate(m_op, m_lvalue, m_rvalue)
@ -105,6 +106,7 @@ using namespace godot;
#define FILE_EXISTS(m_path) FileAccess::file_exists(m_path)
#define DIR_ACCESS_CREATE() DirAccess::open("res://")
#define PERFORMANCE_ADD_CUSTOM_MONITOR(m_id, m_callable) (Performance::get_singleton()->add_custom_monitor(m_id, m_callable))
#define GET_SCRIPT(m_obj) (m_obj->get_script())
#define VARIANT_EVALUATE(m_op, m_lvalue, m_rvalue, r_ret) \
{ \