Merge pull request #110 from limbonaut/type-validation

Editor: Check if variable is of correct type for BBParam subtypes
This commit is contained in:
Serhii Snitsaruk 2024-05-18 15:33:39 +02:00 committed by GitHub
commit 2f326e5b6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 9 additions and 7 deletions

View File

@ -17,10 +17,8 @@
class BBNode : public BBParam { class BBNode : public BBParam {
GDCLASS(BBNode, BBParam); GDCLASS(BBNode, BBParam);
protected:
virtual Variant::Type get_type() const override { return Variant::NODE_PATH; }
public: public:
virtual Variant::Type get_type() const override { return Variant::NODE_PATH; }
virtual Variant get_value(Node *p_scene_root, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant()) override; virtual Variant get_value(Node *p_scene_root, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant()) override;
}; };

View File

@ -49,8 +49,6 @@ protected:
void _get_property_list(List<PropertyInfo> *p_list) const; void _get_property_list(List<PropertyInfo> *p_list) const;
public: public:
virtual Variant::Type get_type() const { return Variant::NIL; }
void set_value_source(ValueSource p_value); void set_value_source(ValueSource p_value);
ValueSource get_value_source() const { return value_source; } ValueSource get_value_source() const { return value_source; }
@ -66,6 +64,8 @@ public:
virtual String _to_string(); virtual String _to_string();
#endif #endif
virtual Variant::Type get_type() const { return Variant::NIL; }
virtual Variant::Type get_variable_expected_type() const { return get_type(); }
virtual Variant get_value(Node *p_scene_root, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant()); virtual Variant get_value(Node *p_scene_root, const Ref<Blackboard> &p_blackboard, const Variant &p_default = Variant());
BBParam(); BBParam();

View File

@ -27,6 +27,8 @@ public:
virtual Variant::Type get_type() const override; virtual Variant::Type get_type() const override;
void set_type(Variant::Type p_type); void set_type(Variant::Type p_type);
virtual Variant::Type get_variable_expected_type() const override { return Variant::NIL; }
BBVariant(const Variant &p_value); BBVariant(const Variant &p_value);
BBVariant(); BBVariant();
}; };

View File

@ -283,6 +283,7 @@ void EditorPropertyBBParam::update_property() {
if (param->get_value_source() == BBParam::BLACKBOARD_VAR) { if (param->get_value_source() == BBParam::BLACKBOARD_VAR) {
_remove_value_editor(); _remove_value_editor();
variable_editor->set_object_and_property(param.ptr(), SNAME("variable")); variable_editor->set_object_and_property(param.ptr(), SNAME("variable"));
variable_editor->setup(plan, false, param->get_variable_expected_type());
variable_editor->update_property(); variable_editor->update_property();
variable_editor->show(); variable_editor->show();
bottom_container->hide(); bottom_container->hide();
@ -300,7 +301,7 @@ void EditorPropertyBBParam::update_property() {
void EditorPropertyBBParam::setup(PropertyHint p_hint, const String &p_hint_text, const Ref<BlackboardPlan> &p_plan) { void EditorPropertyBBParam::setup(PropertyHint p_hint, const String &p_hint_text, const Ref<BlackboardPlan> &p_plan) {
param_type = p_hint_text; param_type = p_hint_text;
property_hint = p_hint; property_hint = p_hint;
variable_editor->setup(p_plan, false); plan = p_plan;
variable_editor->set_name_split_ratio(0.0); variable_editor->set_name_split_ratio(0.0);
} }

View File

@ -36,6 +36,7 @@ private:
bool initialized = false; bool initialized = false;
Ref<BlackboardPlan> plan;
StringName param_type; StringName param_type;
PropertyHint property_hint = PROPERTY_HINT_NONE; PropertyHint property_hint = PROPERTY_HINT_NONE;

View File

@ -96,7 +96,7 @@ void EditorPropertyVariableName::_update_status() {
} else { } else {
BUTTON_SET_ICON(status_btn, theme_cache.var_error_icon); BUTTON_SET_ICON(status_btn, theme_cache.var_error_icon);
status_btn->set_tooltip_text(TTR(vformat( status_btn->set_tooltip_text(TTR(vformat(
"The %s variable in the blackboard plan is not of the same type as this variable (expected %s).\nClick to open the blackboard plan and fix the variable type.", "The %s variable in the blackboard plan should be of type %s.\nClick to open the blackboard plan.",
LimboUtility::get_singleton()->decorate_var(var_name), LimboUtility::get_singleton()->decorate_var(var_name),
Variant::get_type_name(expected_type)))); Variant::get_type_name(expected_type))));
} }