| 1058 | } |
| 1059 | |
| 1060 | void Object::set_meta(const StringName &p_name, const Variant &p_value) { |
| 1061 | if (p_value.get_type() == Variant::NIL) { |
| 1062 | if (metadata.has(p_name)) { |
| 1063 | metadata.erase(p_name); |
| 1064 | |
| 1065 | const String &sname = p_name; |
| 1066 | metadata_properties.erase("metadata/" + sname); |
| 1067 | if (!sname.begins_with("_")) { |
| 1068 | // Metadata starting with _ don't show up in the inspector, so no need to update. |
| 1069 | notify_property_list_changed(); |
| 1070 | } |
| 1071 | } |
| 1072 | return; |
| 1073 | } |
| 1074 | |
| 1075 | HashMap<StringName, Variant>::Iterator E = metadata.find(p_name); |
| 1076 | if (E) { |
| 1077 | E->value = p_value; |
| 1078 | } else { |
| 1079 | ERR_FAIL_COND_MSG(!p_name.operator String().is_valid_ascii_identifier(), vformat("Invalid metadata identifier: '%s'.", p_name)); |
| 1080 | Variant *V = &metadata.insert(p_name, p_value)->value; |
| 1081 | |
| 1082 | const String &sname = p_name; |
| 1083 | metadata_properties["metadata/" + sname] = V; |
| 1084 | if (!sname.begins_with("_")) { |
| 1085 | notify_property_list_changed(); |
| 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | Variant Object::get_meta(const StringName &p_name, const Variant &p_default) const { |
| 1091 | if (!metadata.has(p_name)) { |
no test coverage detected