Clean up & renames

This commit is contained in:
Serhii Snitsaruk 2024-05-15 20:43:24 +02:00
parent 3cf90f9387
commit 2718271bb1
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
6 changed files with 30 additions and 21 deletions

View File

@ -425,11 +425,10 @@ void BlackboardPlan::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_base_plan", "blackboard_plan"), &BlackboardPlan::set_base_plan); ClassDB::bind_method(D_METHOD("set_base_plan", "blackboard_plan"), &BlackboardPlan::set_base_plan);
ClassDB::bind_method(D_METHOD("get_base_plan"), &BlackboardPlan::get_base_plan); ClassDB::bind_method(D_METHOD("get_base_plan"), &BlackboardPlan::get_base_plan);
ClassDB::bind_method(D_METHOD("set_parent_scope_plan_provider", "callable"), &BlackboardPlan::set_parent_scope_plan_provider);
ClassDB::bind_method(D_METHOD("get_parent_scope_plan_provider"), &BlackboardPlan::get_parent_scope_plan_provider);
ClassDB::bind_method(D_METHOD("is_mapping_enabled"), &BlackboardPlan::is_mapping_enabled);
ClassDB::bind_method(D_METHOD("is_derived"), &BlackboardPlan::is_derived); ClassDB::bind_method(D_METHOD("is_derived"), &BlackboardPlan::is_derived);
ClassDB::bind_method(D_METHOD("sync_with_base_plan"), &BlackboardPlan::sync_with_base_plan); ClassDB::bind_method(D_METHOD("sync_with_base_plan"), &BlackboardPlan::sync_with_base_plan);
ClassDB::bind_method(D_METHOD("set_parent_scope_plan_provider", "callable"), &BlackboardPlan::set_parent_scope_plan_provider);
ClassDB::bind_method(D_METHOD("get_parent_scope_plan_provider"), &BlackboardPlan::get_parent_scope_plan_provider);
ClassDB::bind_method(D_METHOD("create_blackboard", "node"), &BlackboardPlan::create_blackboard); ClassDB::bind_method(D_METHOD("create_blackboard", "node"), &BlackboardPlan::create_blackboard);
ClassDB::bind_method(D_METHOD("populate_blackboard", "blackboard", "overwrite", "node"), &BlackboardPlan::populate_blackboard); ClassDB::bind_method(D_METHOD("populate_blackboard", "blackboard", "overwrite", "node"), &BlackboardPlan::populate_blackboard);

View File

@ -55,6 +55,9 @@ void BlackboardPlanEditor::_add_var() {
} }
BBVariable var(default_type, default_hint, default_hint_string); BBVariable var(default_type, default_hint, default_hint_string);
if (default_value.get_type() == default_type) {
var.set_value(default_value);
}
plan->add_var(var_name, var); plan->add_var(var_name, var);
reset_defaults(); reset_defaults();
_refresh(); _refresh();
@ -128,11 +131,12 @@ void BlackboardPlanEditor::edit_plan(const Ref<BlackboardPlan> &p_plan) {
_refresh(); _refresh();
} }
void BlackboardPlanEditor::set_defaults(const StringName &p_var_name, Variant::Type p_type, PropertyHint p_hint, String p_hint_string) { void BlackboardPlanEditor::set_defaults(const StringName &p_var_name, Variant::Type p_type, PropertyHint p_hint, String p_hint_string, Variant p_value) {
default_var_name = p_var_name; default_var_name = p_var_name;
default_type = p_type; default_type = p_type;
default_hint = p_hint; default_hint = p_hint;
default_hint_string = p_hint_string; default_hint_string = p_hint_string;
default_value = p_value;
} }
void BlackboardPlanEditor::reset_defaults() { void BlackboardPlanEditor::reset_defaults() {

View File

@ -62,6 +62,7 @@ private:
Variant::Type default_type = Variant::NIL; Variant::Type default_type = Variant::NIL;
PropertyHint default_hint = PROPERTY_HINT_NONE; PropertyHint default_hint = PROPERTY_HINT_NONE;
String default_hint_string; String default_hint_string;
Variant default_value;
VBoxContainer *rows_vbox; VBoxContainer *rows_vbox;
Button *add_var_tool; Button *add_var_tool;
@ -102,7 +103,7 @@ public:
_FORCE_INLINE_ static BlackboardPlanEditor *get_singleton() { return singleton; } _FORCE_INLINE_ static BlackboardPlanEditor *get_singleton() { return singleton; }
void edit_plan(const Ref<BlackboardPlan> &p_plan); void edit_plan(const Ref<BlackboardPlan> &p_plan);
void set_defaults(const StringName &p_name, Variant::Type p_type = Variant::FLOAT, PropertyHint p_hint = PROPERTY_HINT_NONE, String p_hint_string = ""); void set_defaults(const StringName &p_name, Variant::Type p_type = Variant::FLOAT, PropertyHint p_hint = PROPERTY_HINT_NONE, String p_hint_string = "", Variant p_value = Variant());
void reset_defaults(); void reset_defaults();
BlackboardPlanEditor(); BlackboardPlanEditor();

View File

@ -105,7 +105,8 @@ void EditorPropertyVariableName::_update_status() {
void EditorPropertyVariableName::_status_pressed() { void EditorPropertyVariableName::_status_pressed() {
ERR_FAIL_NULL(plan); ERR_FAIL_NULL(plan);
if (!plan->has_var(name_edit->get_text())) { if (!plan->has_var(name_edit->get_text())) {
BlackboardPlanEditor::get_singleton()->set_defaults(name_edit->get_text(), expected_type, expected_hint, expected_hint_string); BlackboardPlanEditor::get_singleton()->set_defaults(name_edit->get_text(),
expected_type, default_hint, default_hint_string, default_value);
} }
BlackboardPlanEditor::get_singleton()->edit_plan(plan); BlackboardPlanEditor::get_singleton()->edit_plan(plan);
BlackboardPlanEditor::get_singleton()->popup_centered(); BlackboardPlanEditor::get_singleton()->popup_centered();
@ -138,12 +139,13 @@ void EditorPropertyVariableName::_update_property() {
_update_status(); _update_status();
} }
void EditorPropertyVariableName::setup(const Ref<BlackboardPlan> &p_plan, bool p_allow_empty, Variant::Type p_type, PropertyHint p_hint, String p_hint_string) { void EditorPropertyVariableName::setup(const Ref<BlackboardPlan> &p_plan, bool p_allow_empty, Variant::Type p_type, PropertyHint p_hint, String p_hint_string, Variant p_default_value) {
plan = p_plan; plan = p_plan;
allow_empty = p_allow_empty; allow_empty = p_allow_empty;
expected_type = p_type; expected_type = p_type;
expected_hint = p_hint; default_hint = p_hint;
expected_hint_string = p_hint_string; default_hint_string = p_hint_string;
default_value = p_default_value;
_update_status(); _update_status();
} }
@ -238,8 +240,9 @@ bool EditorInspectorPluginVariableName::_parse_property(Object *p_object, const
Ref<BlackboardPlan> plan; Ref<BlackboardPlan> plan;
Variant::Type expected_type = Variant::NIL; Variant::Type expected_type = Variant::NIL;
PropertyHint expected_hint = PROPERTY_HINT_NONE; PropertyHint default_hint = PROPERTY_HINT_NONE;
String expected_hint_string; String default_hint_string;
Variant default_value;
if (is_mapping) { if (is_mapping) {
plan.reference_ptr(Object::cast_to<BlackboardPlan>(p_object)); plan.reference_ptr(Object::cast_to<BlackboardPlan>(p_object));
ERR_FAIL_NULL_V(plan, false); ERR_FAIL_NULL_V(plan, false);
@ -247,8 +250,9 @@ bool EditorInspectorPluginVariableName::_parse_property(Object *p_object, const
if (plan->has_var(var_name)) { if (plan->has_var(var_name)) {
BBVariable variable = plan->get_var(var_name); BBVariable variable = plan->get_var(var_name);
expected_type = variable.get_type(); expected_type = variable.get_type();
expected_hint = variable.get_hint(); default_hint = variable.get_hint();
expected_hint_string = variable.get_hint_string(); default_hint_string = variable.get_hint_string();
default_value = variable.get_value();
} }
if (plan->get_parent_scope_plan_provider().is_valid()) { if (plan->get_parent_scope_plan_provider().is_valid()) {
Ref<BlackboardPlan> parent_plan = plan->get_parent_scope_plan_provider().call(); Ref<BlackboardPlan> parent_plan = plan->get_parent_scope_plan_provider().call();
@ -258,11 +262,11 @@ bool EditorInspectorPluginVariableName::_parse_property(Object *p_object, const
} }
ERR_FAIL_NULL_V(plan, false); ERR_FAIL_NULL_V(plan, false);
} else { } else {
plan = plan_getter.call(); plan = editor_plan_provider.call();
} }
EditorPropertyVariableName *ed = memnew(EditorPropertyVariableName); EditorPropertyVariableName *ed = memnew(EditorPropertyVariableName);
ed->setup(plan, is_mapping, expected_type, expected_hint, expected_hint_string); ed->setup(plan, is_mapping, expected_type, default_hint, default_hint_string, default_value);
add_property_editor(p_path, ed, expected_type); add_property_editor(p_path, ed, expected_type);
return true; return true;

View File

@ -46,8 +46,9 @@ private:
bool allow_empty = false; bool allow_empty = false;
Variant::Type expected_type = Variant::NIL; Variant::Type expected_type = Variant::NIL;
PropertyHint expected_hint = PROPERTY_HINT_NONE; PropertyHint default_hint = PROPERTY_HINT_NONE;
String expected_hint_string; String default_hint_string;
Variant default_value;
LineEdit *name_edit; LineEdit *name_edit;
Button *drop_btn; Button *drop_btn;
@ -76,7 +77,7 @@ public:
virtual void _update_property() override; virtual void _update_property() override;
#endif #endif
void setup(const Ref<BlackboardPlan> &p_plan, bool p_allow_empty, Variant::Type p_type = Variant::FLOAT, PropertyHint p_hint = PROPERTY_HINT_NONE, String p_hint_string = ""); void setup(const Ref<BlackboardPlan> &p_plan, bool p_allow_empty, Variant::Type p_type = Variant::FLOAT, PropertyHint p_hint = PROPERTY_HINT_NONE, String p_hint_string = "", Variant p_default_value = Variant());
EditorPropertyVariableName(); EditorPropertyVariableName();
}; };
@ -84,7 +85,7 @@ class EditorInspectorPluginVariableName : public EditorInspectorPlugin {
GDCLASS(EditorInspectorPluginVariableName, EditorInspectorPlugin); GDCLASS(EditorInspectorPluginVariableName, EditorInspectorPlugin);
private: private:
Callable plan_getter; Callable editor_plan_provider;
protected: protected:
static void _bind_methods() {} static void _bind_methods() {}
@ -98,7 +99,7 @@ public:
virtual bool _parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override; virtual bool _parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide = false) override;
#endif #endif
void set_plan_getter(const Callable &p_getter) { plan_getter = p_getter; } void set_editor_plan_provider(const Callable &p_getter) { editor_plan_provider = p_getter; }
EditorInspectorPluginVariableName() = default; EditorInspectorPluginVariableName() = default;
}; };

View File

@ -1486,7 +1486,7 @@ void LimboAIEditorPlugin::_notification(int p_notification) {
add_debugger_plugin(memnew(LimboDebuggerPlugin)); add_debugger_plugin(memnew(LimboDebuggerPlugin));
add_inspector_plugin(memnew(EditorInspectorPluginBBPlan)); add_inspector_plugin(memnew(EditorInspectorPluginBBPlan));
EditorInspectorPluginVariableName *var_plugin = memnew(EditorInspectorPluginVariableName); EditorInspectorPluginVariableName *var_plugin = memnew(EditorInspectorPluginVariableName);
var_plugin->set_plan_getter(Callable(limbo_ai_editor, "get_edited_blackboard_plan")); var_plugin->set_editor_plan_provider(Callable(limbo_ai_editor, "get_edited_blackboard_plan"));
add_inspector_plugin(var_plugin); add_inspector_plugin(var_plugin);
#ifdef LIMBOAI_MODULE #ifdef LIMBOAI_MODULE
// ! Only used in the module version. // ! Only used in the module version.