Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PropertyListHelper to Curves #92282

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions scene/property_list_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void PropertyListHelper::setup_for_instance(const PropertyListHelper &p_base, Ob

prefix = p_base.prefix;
array_length_getter = p_base.array_length_getter;
property_filter = p_base.property_filter;
property_list = p_base.property_list;
object = p_object;
}
Expand Down Expand Up @@ -127,6 +128,16 @@ void PropertyListHelper::get_property_list(List<PropertyInfo> *p_list) const {
for (int i = 0; i < property_count; i++) {
for (const KeyValue<String, Property> &E : property_list) {
const Property &property = E.value;
if (property_filter) {
Callable::CallError ce;
Variant args[] = { property.info.name, i };
const Variant *argptrs[] = { &args[0], &args[1] };

bool property_valid = property_filter->call(object, argptrs, 2, ce);
if (!property_valid) {
continue;
}
}

PropertyInfo info = property.info;
if (_call_getter(&property, i) == property.default_value) {
Expand Down Expand Up @@ -180,6 +191,9 @@ PropertyListHelper::~PropertyListHelper() {
// No object = it's the main helper. Do a cleanup.
if (!object && is_initialized()) {
memdelete(array_length_getter);
KoBeWi marked this conversation as resolved.
Show resolved Hide resolved
if (property_filter) {
memdelete(property_filter);
}

for (const KeyValue<String, Property> &E : property_list) {
if (E.value.setter) {
Expand Down
5 changes: 5 additions & 0 deletions scene/property_list_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class PropertyListHelper {

String prefix;
MethodBind *array_length_getter = nullptr;
MethodBind *property_filter = nullptr;
HashMap<String, Property> property_list;
Object *object = nullptr;

Expand All @@ -58,6 +59,10 @@ class PropertyListHelper {
void set_array_length_getter(G p_array_length_getter) {
array_length_getter = create_method_bind(p_array_length_getter);
}
template <typename F>
void set_property_filter(F p_property_filter) {
property_filter = create_method_bind(p_property_filter);
}

// Register property without setter/getter. Only use when you don't need PropertyListHelper for _set/_get logic.
void register_property(const PropertyInfo &p_info, const Variant &p_default);
Expand Down
Loading
Loading