| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/object/method_bind.h" |
| 34 |
#include "core/object/object.h" |
| 35 |
|
| 36 |
class PropertyListHelper { |
| 37 |
struct Property { |
| 38 |
PropertyInfo info; |
| 39 |
Variant default_value; |
| 40 |
MethodBind *setter = nullptr; |
| 41 |
MethodBind *getter = nullptr; |
| 42 |
}; |
| 43 |
|
| 44 |
static Vector<PropertyListHelper *> base_helpers; |
| 45 |
|
| 46 |
String prefix; |
| 47 |
MethodBind *array_length_getter = nullptr; |
| 48 |
HashMap<String, Property> property_list; |
| 49 |
Object *object = nullptr; |
| 50 |
|
| 51 |
bool allow_oob_assign = false; |
| 52 |
|
| 53 |
const Property *_get_property(const String &p_property, int *r_index, bool p_allow_oob = false) const; |
| 54 |
void _call_setter(const MethodBind *p_setter, int p_index, const Variant &p_value) const; |
| 55 |
Variant _call_getter(const Property *p_property, int p_index) const; |
| 56 |
int _call_array_length_getter() const; |
| 57 |
|
| 58 |
public: |
| 59 |
static void clear_base_helpers(); |
| 60 |
static void register_base_helper(PropertyListHelper *p_helper); |
| 61 |
|
| 62 |
void set_prefix(const String &p_prefix); |
| 63 |
template <typename G> |
| 64 |
void set_array_length_getter(G p_array_length_getter) { |
| 65 |
array_length_getter = create_method_bind(p_array_length_getter); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
void register_property(const PropertyInfo &p_info, const Variant &p_default); |
| 70 |
|
| 71 |
template <typename S, typename G> |
| 72 |
void register_property(const PropertyInfo &p_info, const Variant &p_default, S p_setter, G p_getter) { |
| 73 |
Property property; |
| 74 |
property.info = p_info; |
| 75 |
property.default_value = p_default; |
| 76 |
property.setter = create_method_bind(p_setter); |
| 77 |
property.getter = create_method_bind(p_getter); |
| 78 |
|
| 79 |
property_list[p_info.name] = property; |
| 80 |
} |
| 81 |
|
| 82 |
bool is_initialized() const; |
| 83 |
void setup_for_instance(const PropertyListHelper &p_base, Object *p_object); |
| 84 |
bool is_property_valid(const String &p_property, int *r_index = nullptr) const; |
| 85 |
|
| 86 |
void get_property_list(List<PropertyInfo> *p_list) const; |
| 87 |
bool property_get_value(const String &p_property, Variant &r_ret) const; |
| 88 |
bool property_set_value(const String &p_property, const Variant &p_value) const; |
| 89 |
bool property_can_revert(const String &p_property) const; |
| 90 |
bool property_get_revert(const String &p_property, Variant &r_value) const; |
| 91 |
|
| 92 |
void enable_out_of_bounds_assign() { allow_oob_assign = true; } |
| 93 |
|
| 94 |
void clear(); |
| 95 |
}; |