summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-06-06 23:38:29 +0200
committerGitHub <noreply@github.com>2022-06-06 23:38:29 +0200
commit83421cd06f8aeacc69d666e0e695333fdaa80377 (patch)
tree58a9c005ef6f029f8884120a4f1b6dee5bb9b008 /core
parent8fb004efbc6161d2adec9501c08cfc9a910086f6 (diff)
parenta0915e6dee4e54563a98ca6adb8968dbdcea1af1 (diff)
Merge pull request #59883 from KoBeWi/merge_this
Diffstat (limited to 'core')
-rw-r--r--core/variant/dictionary.cpp8
-rw-r--r--core/variant/dictionary.h1
-rw-r--r--core/variant/variant_call.cpp1
3 files changed, 10 insertions, 0 deletions
diff --git a/core/variant/dictionary.cpp b/core/variant/dictionary.cpp
index bda8c93a79..822021f440 100644
--- a/core/variant/dictionary.cpp
+++ b/core/variant/dictionary.cpp
@@ -269,6 +269,14 @@ void Dictionary::clear() {
_p->variant_map.clear();
}
+void Dictionary::merge(const Dictionary &p_dictionary, bool p_overwrite) {
+ for (const KeyValue<Variant, Variant> &E : p_dictionary._p->variant_map) {
+ if (p_overwrite || !has(E.key)) {
+ this->operator[](E.key) = E.value;
+ }
+ }
+}
+
void Dictionary::_unref() const {
ERR_FAIL_COND(!_p);
if (_p->refcount.unref()) {
diff --git a/core/variant/dictionary.h b/core/variant/dictionary.h
index 1224a4ff6f..2632893e8d 100644
--- a/core/variant/dictionary.h
+++ b/core/variant/dictionary.h
@@ -62,6 +62,7 @@ public:
int size() const;
bool is_empty() const;
void clear();
+ void merge(const Dictionary &p_dictionary, bool p_overwrite = false);
bool has(const Variant &p_key) const;
bool has_all(const Array &p_keys) const;
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 6b1868df68..3fe5ead347 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -1813,6 +1813,7 @@ static void _register_variant_builtin_methods() {
bind_method(Dictionary, size, sarray(), varray());
bind_method(Dictionary, is_empty, sarray(), varray());
bind_method(Dictionary, clear, sarray(), varray());
+ bind_method(Dictionary, merge, sarray("dictionary", "overwrite"), varray(false));
bind_method(Dictionary, has, sarray("key"), varray());
bind_method(Dictionary, has_all, sarray("keys"), varray());
bind_method(Dictionary, erase, sarray("key"), varray());