From 46c23dbc84c6f5a2cc8ec6af1c8dd49e7d6f0485 Mon Sep 17 00:00:00 2001 From: Marcel Admiraal Date: Sun, 14 Mar 2021 11:43:51 +0000 Subject: [PATCH] Rename Array, Dictionary and Variant.duplicate() to copy() Does the same internally for Vector<>, which includes all PackedArray types. --- core/io/resource.cpp | 2 +- core/object/object.cpp | 2 +- core/templates/vector.h | 2 +- core/variant/array.cpp | 8 +++---- core/variant/array.h | 2 +- core/variant/dictionary.cpp | 4 ++-- core/variant/dictionary.h | 2 +- core/variant/variant.h | 2 +- core/variant/variant_call.cpp | 22 ++++++++--------- core/variant/variant_setget.cpp | 24 +++++++++---------- doc/classes/Array.xml | 20 ++++++++-------- doc/classes/Dictionary.xml | 4 ++-- doc/classes/PackedByteArray.xml | 14 +++++------ doc/classes/PackedColorArray.xml | 2 +- doc/classes/PackedFloat32Array.xml | 2 +- doc/classes/PackedFloat64Array.xml | 2 +- doc/classes/PackedInt32Array.xml | 2 +- doc/classes/PackedInt64Array.xml | 2 +- doc/classes/PackedStringArray.xml | 2 +- doc/classes/PackedVector2Array.xml | 2 +- doc/classes/PackedVector3Array.xml | 2 +- editor/action_map_editor.cpp | 4 ++-- editor/animation_track_editor.cpp | 8 +++---- editor/editor_inspector.cpp | 2 +- editor/editor_properties_array_dict.cpp | 20 ++++++++-------- editor/import/resource_importer_scene.cpp | 2 +- .../animation_player_editor_plugin.cpp | 6 ++--- editor/plugins/canvas_item_editor_plugin.cpp | 8 +++---- editor/plugins/polygon_2d_editor_plugin.cpp | 4 ++-- editor/plugins/tile_set_editor_plugin.cpp | 6 ++--- modules/gdnative/gdnative/variant.cpp | 4 ++-- modules/gdnative/gdnative_api.json | 2 +- .../gdnative_library_singleton_editor.cpp | 4 ++-- modules/gdnative/include/gdnative/variant.h | 2 +- .../gdscript_text_document.cpp | 2 +- modules/mono/glue/collections_glue.cpp | 14 +++++------ .../visual_script/visual_script_editor.cpp | 6 ++--- scene/main/node.cpp | 2 +- scene/resources/packed_scene.cpp | 2 +- 39 files changed, 111 insertions(+), 111 deletions(-) diff --git a/core/io/resource.cpp b/core/io/resource.cpp index d46e9edafa1b..05b7c2fa5a9b 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -234,7 +234,7 @@ Ref Resource::duplicate(bool p_subresources) const { Variant p = get(E->get().name); if ((p.get_type() == Variant::DICTIONARY || p.get_type() == Variant::ARRAY)) { - r->set(E->get().name, p.duplicate(p_subresources)); + r->set(E->get().name, p.copy(p_subresources)); } else if (p.get_type() == Variant::OBJECT && (p_subresources || (E->get().usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE))) { RES sr = p; if (sr.is_valid()) { diff --git a/core/object/object.cpp b/core/object/object.cpp index 413f917518ff..557a8b4ed5c9 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -405,7 +405,7 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid } else if (p_name == CoreStringNames::get_singleton()->_meta) { //set_meta(p_name,p_value); - metadata = p_value.duplicate(); + metadata = p_value.copy(); if (r_valid) { *r_valid = true; } diff --git a/core/templates/vector.h b/core/templates/vector.h index dae8874a87bb..11039e1ae0d0 100644 --- a/core/templates/vector.h +++ b/core/templates/vector.h @@ -112,7 +112,7 @@ class Vector { sort_custom<_DefaultComparator>(); } - Vector duplicate() { + Vector copy() { return *this; } diff --git a/core/variant/array.cpp b/core/variant/array.cpp index 2fb2dd4a3020..3d2ad97e7b6c 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -298,13 +298,13 @@ const Variant &Array::get(int p_idx) const { return operator[](p_idx); } -Array Array::duplicate(bool p_deep) const { +Array Array::copy(bool p_deep) const { Array new_arr; int element_count = size(); new_arr.resize(element_count); new_arr._p->typed = _p->typed; for (int i = 0; i < element_count; i++) { - new_arr[i] = p_deep ? get(i).duplicate(p_deep) : get(i); + new_arr[i] = p_deep ? get(i).copy(p_deep) : get(i); } return new_arr; @@ -348,13 +348,13 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // l int dest_idx = 0; for (int idx = begin; idx <= end; idx += p_step) { ERR_FAIL_COND_V_MSG(dest_idx < 0 || dest_idx >= new_arr_size, Array(), "Bug in Array slice()"); - new_arr[dest_idx++] = p_deep ? get(idx).duplicate(p_deep) : get(idx); + new_arr[dest_idx++] = p_deep ? get(idx).copy(p_deep) : get(idx); } } else { // p_step < 0 int dest_idx = 0; for (int idx = begin; idx >= end; idx += p_step) { ERR_FAIL_COND_V_MSG(dest_idx < 0 || dest_idx >= new_arr_size, Array(), "Bug in Array slice()"); - new_arr[dest_idx++] = p_deep ? get(idx).duplicate(p_deep) : get(idx); + new_arr[dest_idx++] = p_deep ? get(idx).copy(p_deep) : get(idx); } } diff --git a/core/variant/array.h b/core/variant/array.h index 5ce977ee4b27..870326e21db4 100644 --- a/core/variant/array.h +++ b/core/variant/array.h @@ -98,7 +98,7 @@ class Array { Variant pop_back(); Variant pop_front(); - Array duplicate(bool p_deep = false) const; + Array copy(bool p_deep = false) const; Array slice(int p_begin, int p_end, int p_step = 1, bool p_deep = false) const; diff --git a/core/variant/dictionary.cpp b/core/variant/dictionary.cpp index b2f7c6aa0a23..9d1d3a183159 100644 --- a/core/variant/dictionary.cpp +++ b/core/variant/dictionary.cpp @@ -240,11 +240,11 @@ const Variant *Dictionary::next(const Variant *p_key) const { return nullptr; } -Dictionary Dictionary::duplicate(bool p_deep) const { +Dictionary Dictionary::copy(bool p_deep) const { Dictionary n; for (OrderedHashMap::Element E = _p->variant_map.front(); E; E = E.next()) { - n[E.key()] = p_deep ? E.value().duplicate(true) : E.value(); + n[E.key()] = p_deep ? E.value().copy(true) : E.value(); } return n; diff --git a/core/variant/dictionary.h b/core/variant/dictionary.h index 4067ff9fd938..0d462db1d58e 100644 --- a/core/variant/dictionary.h +++ b/core/variant/dictionary.h @@ -79,7 +79,7 @@ class Dictionary { Array keys() const; Array values() const; - Dictionary duplicate(bool p_deep = false) const; + Dictionary copy(bool p_deep = false) const; const void *id() const; diff --git a/core/variant/variant.h b/core/variant/variant.h index 0acafc64fa02..279e6d25920f 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -474,7 +474,7 @@ class Variant { static PTROperatorEvaluator get_ptr_operator_evaluator(Operator p_operator, Type p_type_a, Type p_type_b); void zero(); - Variant duplicate(bool deep = false) const; + Variant copy(bool deep = false) const; static void blend(const Variant &a, const Variant &b, float c, Variant &r_dst); static void interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst); diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index deaccc6304c7..086c5e49f857 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1631,7 +1631,7 @@ static void _register_variant_builtin_methods() { bind_method(Dictionary, hash, sarray(), varray()); bind_method(Dictionary, keys, sarray(), varray()); bind_method(Dictionary, values, sarray(), varray()); - bind_method(Dictionary, duplicate, sarray("deep"), varray(false)); + bind_method(Dictionary, copy, sarray("deep"), varray(false)); bind_method(Dictionary, get, sarray("key", "default"), varray(Variant())); /* Array */ @@ -1664,7 +1664,7 @@ static void _register_variant_builtin_methods() { bind_method(Array, bsearch, sarray("value", "before"), varray(true)); bind_method(Array, bsearch_custom, sarray("value", "func", "before"), varray(true)); bind_method(Array, reverse, sarray(), varray()); - bind_method(Array, duplicate, sarray("deep"), varray(false)); + bind_method(Array, copy, sarray("deep"), varray(false)); bind_method(Array, slice, sarray("begin", "end", "step", "deep"), varray(1, false)); bind_method(Array, max, sarray(), varray()); bind_method(Array, min, sarray(), varray()); @@ -1684,7 +1684,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedByteArray, reverse, sarray(), varray()); bind_method(PackedByteArray, subarray, sarray("from", "to"), varray()); bind_method(PackedByteArray, sort, sarray(), varray()); - bind_method(PackedByteArray, duplicate, sarray(), varray()); + bind_method(PackedByteArray, copy, sarray(), varray()); bind_function(PackedByteArray, get_string_from_ascii, _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray()); bind_function(PackedByteArray, get_string_from_utf8, _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray()); @@ -1740,7 +1740,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedInt32Array, subarray, sarray("from", "to"), varray()); bind_method(PackedInt32Array, to_byte_array, sarray(), varray()); bind_method(PackedInt32Array, sort, sarray(), varray()); - bind_method(PackedInt32Array, duplicate, sarray(), varray()); + bind_method(PackedInt32Array, copy, sarray(), varray()); /* Int64 Array */ @@ -1759,7 +1759,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedInt64Array, subarray, sarray("from", "to"), varray()); bind_method(PackedInt64Array, to_byte_array, sarray(), varray()); bind_method(PackedInt64Array, sort, sarray(), varray()); - bind_method(PackedInt64Array, duplicate, sarray(), varray()); + bind_method(PackedInt64Array, copy, sarray(), varray()); /* Float32 Array */ @@ -1778,7 +1778,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedFloat32Array, subarray, sarray("from", "to"), varray()); bind_method(PackedFloat32Array, to_byte_array, sarray(), varray()); bind_method(PackedFloat32Array, sort, sarray(), varray()); - bind_method(PackedFloat32Array, duplicate, sarray(), varray()); + bind_method(PackedFloat32Array, copy, sarray(), varray()); /* Float64 Array */ @@ -1797,7 +1797,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedFloat64Array, subarray, sarray("from", "to"), varray()); bind_method(PackedFloat64Array, to_byte_array, sarray(), varray()); bind_method(PackedFloat64Array, sort, sarray(), varray()); - bind_method(PackedFloat64Array, duplicate, sarray(), varray()); + bind_method(PackedFloat64Array, copy, sarray(), varray()); /* String Array */ @@ -1816,7 +1816,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedStringArray, subarray, sarray("from", "to"), varray()); bind_method(PackedStringArray, to_byte_array, sarray(), varray()); bind_method(PackedStringArray, sort, sarray(), varray()); - bind_method(PackedStringArray, duplicate, sarray(), varray()); + bind_method(PackedStringArray, copy, sarray(), varray()); /* Vector2 Array */ @@ -1835,7 +1835,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedVector2Array, subarray, sarray("from", "to"), varray()); bind_method(PackedVector2Array, to_byte_array, sarray(), varray()); bind_method(PackedVector2Array, sort, sarray(), varray()); - bind_method(PackedVector2Array, duplicate, sarray(), varray()); + bind_method(PackedVector2Array, copy, sarray(), varray()); /* Vector3 Array */ @@ -1854,7 +1854,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedVector3Array, subarray, sarray("from", "to"), varray()); bind_method(PackedVector3Array, to_byte_array, sarray(), varray()); bind_method(PackedVector3Array, sort, sarray(), varray()); - bind_method(PackedVector3Array, duplicate, sarray(), varray()); + bind_method(PackedVector3Array, copy, sarray(), varray()); /* Color Array */ @@ -1873,7 +1873,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedColorArray, subarray, sarray("from", "to"), varray()); bind_method(PackedColorArray, to_byte_array, sarray(), varray()); bind_method(PackedColorArray, sort, sarray(), varray()); - bind_method(PackedColorArray, duplicate, sarray(), varray()); + bind_method(PackedColorArray, copy, sarray(), varray()); /* Register constants */ diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index 9ab860278252..2db824ed00bd 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -2012,7 +2012,7 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { return Variant(); } -Variant Variant::duplicate(bool deep) const { +Variant Variant::copy(bool deep) const { switch (type) { case OBJECT: { /* breaks stuff :( @@ -2026,27 +2026,27 @@ Variant Variant::duplicate(bool deep) const { return *this; } break; case DICTIONARY: - return operator Dictionary().duplicate(deep); + return operator Dictionary().copy(deep); case ARRAY: - return operator Array().duplicate(deep); + return operator Array().copy(deep); case PACKED_BYTE_ARRAY: - return operator Vector().duplicate(); + return operator Vector().copy(); case PACKED_INT32_ARRAY: - return operator Vector().duplicate(); + return operator Vector().copy(); case PACKED_INT64_ARRAY: - return operator Vector().duplicate(); + return operator Vector().copy(); case PACKED_FLOAT32_ARRAY: - return operator Vector().duplicate(); + return operator Vector().copy(); case PACKED_FLOAT64_ARRAY: - return operator Vector().duplicate(); + return operator Vector().copy(); case PACKED_STRING_ARRAY: - return operator Vector().duplicate(); + return operator Vector().copy(); case PACKED_VECTOR2_ARRAY: - return operator Vector().duplicate(); + return operator Vector().copy(); case PACKED_VECTOR3_ARRAY: - return operator Vector().duplicate(); + return operator Vector().copy(); case PACKED_COLOR_ARRAY: - return operator Vector().duplicate(); + return operator Vector().copy(); default: return *this; } diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index 38b74cb43633..cefee0208459 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -39,7 +39,7 @@ [/csharp] [/codeblocks] [b]Note:[/b] Concatenating with the [code]+=[/code] operator will create a new array, which has a cost. If you want to append another array to an existing array, [method append_array] is more efficient. - [b]Note:[/b] Arrays are always passed by reference. To get a copy of an array which can be modified independently of the original array, use [method duplicate]. + [b]Note:[/b] Arrays are always passed by reference. To get a copy of an array which can be modified independently of the original array, use [method copy]. [b]Note:[/b] When declaring an array with [code]const[/code], the array itself can still be mutated by defining the values at individual indices or pushing/removing elements. Using [code]const[/code] will only prevent assigning the constant with another value after it was initialized. @@ -207,23 +207,23 @@ Clears the array. This is equivalent to using [method resize] with a size of [code]0[/code]. - - + + - + - Returns the number of times an element is in the array. + Returns a copy of the array. + If [code]deep[/code] is [code]true[/code], a deep copy is performed: all nested arrays and dictionaries are copied and will not be shared with the original array. If [code]false[/code], a shallow copy is made and references to the original nested arrays and dictionaries are kept, so that modifying a sub-array or dictionary in the copy will also impact those referenced in the source array. - - + + - + - Returns a copy of the array. - If [code]deep[/code] is [code]true[/code], a deep copy is performed: all nested arrays and dictionaries are duplicated and will not be shared with the original array. If [code]false[/code], a shallow copy is made and references to the original nested arrays and dictionaries are kept, so that modifying a sub-array or dictionary in the copy will also impact those referenced in the source array. + Returns the number of times an element is in the array. diff --git a/doc/classes/Dictionary.xml b/doc/classes/Dictionary.xml index 16c4348994b1..86dfafd128cd 100644 --- a/doc/classes/Dictionary.xml +++ b/doc/classes/Dictionary.xml @@ -7,7 +7,7 @@ Dictionary type. Associative container which contains values referenced by unique keys. Dictionaries are composed of pairs of keys (which must be unique) and values. Dictionaries will preserve the insertion order when adding elements, even though this may not be reflected when printing the dictionary. In other programming languages, this data structure is sometimes referred to as a hash map or associative array. You can define a dictionary by placing a comma-separated list of [code]key: value[/code] pairs in curly braces [code]{}[/code]. Erasing elements while iterating over them [b]is not supported[/b] and will result in undefined behavior. - [b]Note:[/b] Dictionaries are always passed by reference. To get a copy of a dictionary which can be modified independently of the original dictionary, use [method duplicate]. + [b]Note:[/b] Dictionaries are always passed by reference. To get a copy of a dictionary which can be modified independently of the original dictionary, use [method copy]. Creating a dictionary: [codeblocks] [gdscript] @@ -206,7 +206,7 @@ Clear the dictionary, removing all key/value pairs. - + diff --git a/doc/classes/PackedByteArray.xml b/doc/classes/PackedByteArray.xml index 0652cf0aa1ed..70dbadabe45a 100644 --- a/doc/classes/PackedByteArray.xml +++ b/doc/classes/PackedByteArray.xml @@ -61,6 +61,13 @@ Returns a new [PackedByteArray] with the data compressed. Set the compression mode using one of [enum File.CompressionMode]'s constants. + + + + + Creates a copy of the array, and returns it. + + @@ -193,13 +200,6 @@ GZIP has a maximal compression ratio of 1032:1, meaning it's very possible for a small compressed payload to decompress to a potentially very large output. To guard against this, you may provide a maximum size this function is allowed to allocate in bytes via [code]max_output_size[/code]. Passing -1 will allow for unbounded output. If any positive value is passed, and the decompression exceeds that amount in bytes, then an error will be returned. - - - - - Creates a copy of the array, and returns it. - - diff --git a/doc/classes/PackedColorArray.xml b/doc/classes/PackedColorArray.xml index 19cfcd7c8780..871ac39e3e4f 100644 --- a/doc/classes/PackedColorArray.xml +++ b/doc/classes/PackedColorArray.xml @@ -52,7 +52,7 @@ Appends a [PackedColorArray] at the end of this array. - + diff --git a/doc/classes/PackedFloat32Array.xml b/doc/classes/PackedFloat32Array.xml index ab97c9a6956c..aa4b176e9e37 100644 --- a/doc/classes/PackedFloat32Array.xml +++ b/doc/classes/PackedFloat32Array.xml @@ -53,7 +53,7 @@ Appends a [PackedFloat32Array] at the end of this array. - + diff --git a/doc/classes/PackedFloat64Array.xml b/doc/classes/PackedFloat64Array.xml index ad20801b01e0..3d282be28c24 100644 --- a/doc/classes/PackedFloat64Array.xml +++ b/doc/classes/PackedFloat64Array.xml @@ -53,7 +53,7 @@ Appends a [PackedFloat64Array] at the end of this array. - + diff --git a/doc/classes/PackedInt32Array.xml b/doc/classes/PackedInt32Array.xml index ff4729082e86..76eebe2b1ea6 100644 --- a/doc/classes/PackedInt32Array.xml +++ b/doc/classes/PackedInt32Array.xml @@ -53,7 +53,7 @@ Appends a [PackedInt32Array] at the end of this array. - + diff --git a/doc/classes/PackedInt64Array.xml b/doc/classes/PackedInt64Array.xml index 195b12b129d4..d80c6b47aa2e 100644 --- a/doc/classes/PackedInt64Array.xml +++ b/doc/classes/PackedInt64Array.xml @@ -53,7 +53,7 @@ Appends a [PackedInt64Array] at the end of this array. - + diff --git a/doc/classes/PackedStringArray.xml b/doc/classes/PackedStringArray.xml index 22458832dad2..0f588ae6c7db 100644 --- a/doc/classes/PackedStringArray.xml +++ b/doc/classes/PackedStringArray.xml @@ -53,7 +53,7 @@ Appends a [PackedStringArray] at the end of this array. - + diff --git a/doc/classes/PackedVector2Array.xml b/doc/classes/PackedVector2Array.xml index 6c8791f98845..d8d0129d8434 100644 --- a/doc/classes/PackedVector2Array.xml +++ b/doc/classes/PackedVector2Array.xml @@ -53,7 +53,7 @@ Appends a [PackedVector2Array] at the end of this array. - + diff --git a/doc/classes/PackedVector3Array.xml b/doc/classes/PackedVector3Array.xml index 85d41d7519be..02b8d47707e1 100644 --- a/doc/classes/PackedVector3Array.xml +++ b/doc/classes/PackedVector3Array.xml @@ -52,7 +52,7 @@ Appends a [PackedVector3Array] at the end of this array. - + diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp index 9949fd819968..a92c2d48299d 100644 --- a/editor/action_map_editor.cpp +++ b/editor/action_map_editor.cpp @@ -710,7 +710,7 @@ static bool _is_action_name_valid(const String &p_name) { void ActionMapEditor::_event_config_confirmed() { Ref ev = event_config_dialog->get_event(); - Dictionary new_action = current_action.duplicate(); + Dictionary new_action = current_action.copy(); Array events = new_action["events"]; if (current_action_event_index == -1) { @@ -773,7 +773,7 @@ void ActionMapEditor::_action_edited() { // Deadzone Edited String name = ti->get_meta("__name"); Dictionary old_action = ti->get_meta("__action"); - Dictionary new_action = old_action.duplicate(); + Dictionary new_action = old_action.copy(); new_action["deadzone"] = ti->get_range(1); // Call deferred so that input can finish propagating through tree, allowing re-making of tree to occur. diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 9db2f0a2879b..5ab3a61367c5 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -167,7 +167,7 @@ class AnimationTrackKeyEdit : public Object { switch (animation->track_get_type(track)) { case Animation::TYPE_TRANSFORM: { Dictionary d_old = animation->track_get_key_value(track, key); - Dictionary d_new = d_old.duplicate(); + Dictionary d_new = d_old.copy(); d_new[p_name] = p_value; setting = true; undo_redo->create_action(TTR("Anim Change Transform")); @@ -203,7 +203,7 @@ class AnimationTrackKeyEdit : public Object { } break; case Animation::TYPE_METHOD: { Dictionary d_old = animation->track_get_key_value(track, key); - Dictionary d_new = d_old.duplicate(); + Dictionary d_new = d_old.copy(); bool change_notify_deserved = false; bool mergeable = false; @@ -783,7 +783,7 @@ class AnimationMultiTrackKeyEdit : public Object { switch (animation->track_get_type(track)) { case Animation::TYPE_TRANSFORM: { Dictionary d_old = animation->track_get_key_value(track, key); - Dictionary d_new = d_old.duplicate(); + Dictionary d_new = d_old.copy(); d_new[p_name] = p_value; if (!setting) { @@ -814,7 +814,7 @@ class AnimationMultiTrackKeyEdit : public Object { } break; case Animation::TYPE_METHOD: { Dictionary d_old = animation->track_get_key_value(track, key); - Dictionary d_new = d_old.duplicate(); + Dictionary d_new = d_old.copy(); bool mergeable = false; diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 738b2f9f826f..ef3da6f35d7d 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -765,7 +765,7 @@ void EditorProperty::_gui_input(const Ref &p_event) { Node *node = Object::cast_to(object); if (node && EditorPropertyRevert::may_node_be_in_instance(node) && EditorPropertyRevert::get_instanced_node_original_property(node, property, vorig)) { - emit_changed(property, vorig.duplicate(true)); + emit_changed(property, vorig.copy(true)); update_property(); return; } diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index de688f270923..9c2afcfd5338 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -163,7 +163,7 @@ void EditorPropertyArray::_property_changed(const String &p_property, Variant p_ emit_changed(get_edited_property(), array, "", true); if (array.get_type() == Variant::ARRAY) { - array = array.call("duplicate"); //dupe, so undo/redo works better + array = array.call("copy"); // Copy, so undo/redo works better } object->set_array(array); } @@ -193,7 +193,7 @@ void EditorPropertyArray::_change_type_menu(int p_index) { emit_changed(get_edited_property(), array, "", true); if (array.get_type() == Variant::ARRAY) { - array = array.call("duplicate"); //dupe, so undo/redo works better + array = array.call("copy"); // Copy, so undo/redo works better } object->set_array(array); @@ -316,7 +316,7 @@ void EditorPropertyArray::update_property() { int amount = MIN(len - offset, page_len); if (array.get_type() == Variant::ARRAY) { - array = array.call("duplicate"); + array = array.call("copy"); } object->set_array(array); @@ -385,7 +385,7 @@ void EditorPropertyArray::_remove_pressed(int p_index) { array.call("remove", p_index); if (array.get_type() == Variant::ARRAY) { - array = array.call("duplicate"); + array = array.call("copy"); } emit_changed(get_edited_property(), array, "", false); @@ -459,7 +459,7 @@ void EditorPropertyArray::drop_data_fw(const Point2 &p_point, const Variant &p_d } if (array.get_type() == Variant::ARRAY) { - array = array.call("duplicate"); + array = array.call("copy"); } emit_changed(get_edited_property(), array, "", false); @@ -530,7 +530,7 @@ void EditorPropertyArray::_length_changed(double p_page) { } } } - array = array.call("duplicate"); //dupe, so undo/redo works better + array = array.call("copy"); // Copy, so undo/redo works better } else { int size = array.call("size"); // Pool*Array don't initialize their elements, have to do it manually @@ -622,7 +622,7 @@ void EditorPropertyDictionary::_property_changed(const String &p_property, Varia emit_changed(get_edited_property(), dict, "", true); - dict = dict.duplicate(); //dupe, so undo/redo works better + dict = dict.copy(); // Copy, so undo/redo works better object->set_dict(dict); } } @@ -651,7 +651,7 @@ void EditorPropertyDictionary::_add_key_value() { emit_changed(get_edited_property(), dict, "", false); - dict = dict.duplicate(); //dupe, so undo/redo works better + dict = dict.copy(); // Copy, so undo/redo works better object->set_dict(dict); update_property(); } @@ -685,7 +685,7 @@ void EditorPropertyDictionary::_change_type_menu(int p_index) { emit_changed(get_edited_property(), dict, "", false); - dict = dict.duplicate(); //dupe, so undo/redo works better + dict = dict.copy(); // Copy, so undo/redo works better object->set_dict(dict); update_property(); } @@ -751,7 +751,7 @@ void EditorPropertyDictionary::update_property() { int amount = MIN(len - offset, page_len); - dict = dict.duplicate(); + dict = dict.copy(); object->set_dict(dict); VBoxContainer *add_vbox = nullptr; diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 4bb56beaebbe..23be46ab5ce2 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -708,7 +708,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Map iopts; get_internal_import_options(INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE, &iopts); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 612a8f30a482..e683fb128cc5 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -1345,14 +1345,14 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { if (Node3DEditor::get_singleton()->is_visible()) { // 3D spatial_edit_state = Node3DEditor::get_singleton()->get_state(); - Dictionary new_state = spatial_edit_state.duplicate(); + Dictionary new_state = spatial_edit_state.copy(); new_state["show_grid"] = false; new_state["show_origin"] = false; Array orig_vp = spatial_edit_state["viewports"]; Array vp; vp.resize(4); for (int i = 0; i < vp.size(); i++) { - Dictionary d = ((Dictionary)orig_vp[i]).duplicate(); + Dictionary d = ((Dictionary)orig_vp[i]).copy(); d["use_environment"] = false; d["doppler"] = false; d["gizmos"] = onion.include_gizmos ? d["gizmos"] : Variant(false); @@ -1365,7 +1365,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { } else { // CanvasItemEditor // 2D canvas_edit_state = CanvasItemEditor::get_singleton()->get_state(); - Dictionary new_state = canvas_edit_state.duplicate(); + Dictionary new_state = canvas_edit_state.copy(); new_state["show_grid"] = false; new_state["show_rulers"] = false; new_state["show_guides"] = false; diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 6ac47595dc2b..725c2327f37c 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1176,7 +1176,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref &p_eve Point2 edited = snap_point(xform.affine_inverse().xform(b->get_position()), SNAP_GRID | SNAP_PIXEL | SNAP_OTHER_NODES); if (drag_type == DRAG_V_GUIDE) { - Array prev_vguides = vguides.duplicate(); + Array prev_vguides = vguides.copy(); if (b->get_position().x > RULER_WIDTH) { // Adds a new vertical guide if (dragged_guide_index >= 0) { @@ -1209,7 +1209,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref &p_eve } } } else if (drag_type == DRAG_H_GUIDE) { - Array prev_hguides = hguides.duplicate(); + Array prev_hguides = hguides.copy(); if (b->get_position().y > RULER_WIDTH) { // Adds a new horizontal guide if (dragged_guide_index >= 0) { @@ -1242,8 +1242,8 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref &p_eve } } } else if (drag_type == DRAG_DOUBLE_GUIDE) { - Array prev_hguides = hguides.duplicate(); - Array prev_vguides = vguides.duplicate(); + Array prev_hguides = hguides.copy(); + Array prev_vguides = vguides.copy(); if (b->get_position().x > RULER_WIDTH && b->get_position().y > RULER_WIDTH) { // Adds a new horizontal guide a new vertical guide vguides.push_back(edited.x); diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 470d897dccb9..779019b4e56b 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -658,7 +658,7 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { error->popup_centered(); } else { Array polygons = node->get_polygons(); - polygons = polygons.duplicate(); //copy because its a reference + polygons = polygons.copy(); //copy because its a reference //todo, could check whether it already exists? polygons.push_back(polygon_create); @@ -680,7 +680,7 @@ void Polygon2DEditor::_uv_input(const Ref &p_input) { if (uv_move_current == UV_MODE_REMOVE_POLYGON) { Array polygons = node->get_polygons(); - polygons = polygons.duplicate(); //copy because its a reference + polygons = polygons.copy(); //copy because its a reference int erase_index = -1; for (int i = polygons.size() - 1; i >= 0; i--) { diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index f683c4b10d6c..53beb9dc585d 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -1839,7 +1839,7 @@ void TileSetEditor::_on_tool_clicked(int p_tool) { } for (int i = 0; i < sd.size(); i++) { if (sd[i].get("shape") == previous_shape) { - undo_redo->add_undo_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd.duplicate()); + undo_redo->add_undo_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd.copy()); sd.remove(i); break; } @@ -1903,7 +1903,7 @@ void TileSetEditor::_on_tool_clicked(int p_tool) { for (int i = 0; i < sd.size(); i++) { if (sd[i].get("shape") == edited_collision_shape) { undo_redo->create_action(TTR("Remove Collision Polygon")); - undo_redo->add_undo_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd.duplicate()); + undo_redo->add_undo_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd.copy()); sd.remove(i); undo_redo->add_do_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd); undo_redo->add_do_method(this, "_select_edited_shape_coord"); @@ -2936,7 +2936,7 @@ void TileSetEditor::close_shape(const Vector2 &shape_anchor) { undo_redo->create_action(TTR("Create Collision Polygon")); // Necessary to get the version that returns a Array instead of a Vector. Array sd = tileset->call("tile_get_shapes", get_current_tile()); - undo_redo->add_undo_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd.duplicate()); + undo_redo->add_undo_method(tileset.ptr(), "tile_set_shapes", get_current_tile(), sd.copy()); for (int i = 0; i < sd.size(); i++) { if (sd[i].get("shape") == edited_collision_shape) { sd.remove(i); diff --git a/modules/gdnative/gdnative/variant.cpp b/modules/gdnative/gdnative/variant.cpp index 7801e21ab2ca..e6797343caa7 100644 --- a/modules/gdnative/gdnative/variant.cpp +++ b/modules/gdnative/gdnative/variant.cpp @@ -777,9 +777,9 @@ void GDAPI godot_variant_interpolate(const godot_variant *p_a, const godot_varia Variant::interpolate(*a, *b, p_c, *dst); } -godot_variant GDAPI godot_variant_duplicate(const godot_variant *p_self, godot_bool p_deep) { +godot_variant GDAPI godot_variant_copy(const godot_variant *p_self, godot_bool p_deep) { const Variant *self = (const Variant *)p_self; - Variant result = self->duplicate(p_deep); + Variant result = self->copy(p_deep); godot_variant ret; memnew_placement_custom(&ret, Variant, Variant(result)); return ret; diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 489083e79515..1c4e3b43421a 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -1529,7 +1529,7 @@ ] }, { - "name": "godot_variant_duplicate", + "name": "godot_variant_copy", "return_type": "godot_variant", "arguments": [ [ diff --git a/modules/gdnative/gdnative_library_singleton_editor.cpp b/modules/gdnative/gdnative_library_singleton_editor.cpp index f1b4a9a81b49..ccae74872b8f 100644 --- a/modules/gdnative/gdnative_library_singleton_editor.cpp +++ b/modules/gdnative/gdnative_library_singleton_editor.cpp @@ -160,9 +160,9 @@ void GDNativeLibrarySingletonEditor::_item_edited() { if (ProjectSettings::get_singleton()->has_setting("gdnative/singletons_disabled")) { disabled_paths = ProjectSettings::get_singleton()->get("gdnative/singletons_disabled"); // Duplicate so redo works (not a reference) - disabled_paths = disabled_paths.duplicate(); + disabled_paths = disabled_paths.copy(); // For undo, so we can reset the property. - undo_paths = disabled_paths.duplicate(); + undo_paths = disabled_paths.copy(); } if (enabled) { diff --git a/modules/gdnative/include/gdnative/variant.h b/modules/gdnative/include/gdnative/variant.h index 3e06ed9aa499..37f425b02110 100644 --- a/modules/gdnative/include/gdnative/variant.h +++ b/modules/gdnative/include/gdnative/variant.h @@ -295,7 +295,7 @@ godot_bool GDAPI godot_variant_hash_compare(const godot_variant *p_self, const g godot_bool GDAPI godot_variant_booleanize(const godot_variant *p_self); void GDAPI godot_variant_blend(const godot_variant *p_a, const godot_variant *p_b, float p_c, godot_variant *r_dst); void GDAPI godot_variant_interpolate(const godot_variant *p_a, const godot_variant *p_b, float p_c, godot_variant *r_dst); -godot_variant GDAPI godot_variant_duplicate(const godot_variant *p_self, godot_bool p_deep); +godot_variant GDAPI godot_variant_copy(const godot_variant *p_self, godot_bool p_deep); godot_string GDAPI godot_variant_stringify(const godot_variant *p_self); // Discovery API. diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index 030633274c25..1341959368b0 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -194,7 +194,7 @@ Array GDScriptTextDocument::completion(const Dictionary &p_params) { i++; } } else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) { - arr = native_member_completions.duplicate(); + arr = native_member_completions.copy(); for (Map::Element *E = GDScriptLanguageProtocol::get_singleton()->get_workspace()->scripts.front(); E; E = E->next()) { ExtendGDScriptParser *script = E->get(); diff --git a/modules/mono/glue/collections_glue.cpp b/modules/mono/glue/collections_glue.cpp index 191f8633507f..5689689715a1 100644 --- a/modules/mono/glue/collections_glue.cpp +++ b/modules/mono/glue/collections_glue.cpp @@ -115,13 +115,13 @@ Array *godot_icall_Array_Ctor_MonoArray(MonoArray *mono_array) { return godot_array; } -Array *godot_icall_Array_Duplicate(Array *ptr, MonoBoolean deep) { - return memnew(Array(ptr->duplicate(deep))); +Array *godot_icall_Array_Copy(Array *ptr, MonoBoolean deep) { + return memnew(Array(ptr->copy(deep))); } Array *godot_icall_Array_Concatenate(Array *left, Array *right) { int count = left->size() + right->size(); - Array *new_array = memnew(Array(left->duplicate(false))); + Array *new_array = memnew(Array(left->copy(false))); new_array->resize(count); for (unsigned int i = 0; i < (unsigned int)right->size(); i++) { new_array->operator[](i + left->size()) = right->operator[](i); @@ -254,8 +254,8 @@ MonoBoolean godot_icall_Dictionary_ContainsKey(Dictionary *ptr, MonoObject *key) return ptr->has(GDMonoMarshal::mono_object_to_variant(key)); } -Dictionary *godot_icall_Dictionary_Duplicate(Dictionary *ptr, MonoBoolean deep) { - return memnew(Dictionary(ptr->duplicate(deep))); +Dictionary *godot_icall_Dictionary_Copy(Dictionary *ptr, MonoBoolean deep) { + return memnew(Dictionary(ptr->copy(deep))); } MonoBoolean godot_icall_Dictionary_RemoveKey(Dictionary *ptr, MonoObject *key) { @@ -320,7 +320,7 @@ void godot_register_collections_icalls() { GDMonoUtils::add_internal_call("Godot.Collections.Array::godot_icall_Array_Concatenate", godot_icall_Array_Concatenate); GDMonoUtils::add_internal_call("Godot.Collections.Array::godot_icall_Array_Contains", godot_icall_Array_Contains); GDMonoUtils::add_internal_call("Godot.Collections.Array::godot_icall_Array_CopyTo", godot_icall_Array_CopyTo); - GDMonoUtils::add_internal_call("Godot.Collections.Array::godot_icall_Array_Duplicate", godot_icall_Array_Duplicate); + GDMonoUtils::add_internal_call("Godot.Collections.Array::godot_icall_Array_Copy", godot_icall_Array_Copy); GDMonoUtils::add_internal_call("Godot.Collections.Array::godot_icall_Array_IndexOf", godot_icall_Array_IndexOf); GDMonoUtils::add_internal_call("Godot.Collections.Array::godot_icall_Array_Insert", godot_icall_Array_Insert); GDMonoUtils::add_internal_call("Godot.Collections.Array::godot_icall_Array_Remove", godot_icall_Array_Remove); @@ -342,7 +342,7 @@ void godot_register_collections_icalls() { GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Clear", godot_icall_Dictionary_Clear); GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Contains", godot_icall_Dictionary_Contains); GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_ContainsKey", godot_icall_Dictionary_ContainsKey); - GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Duplicate", godot_icall_Dictionary_Duplicate); + GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Copy", godot_icall_Dictionary_Copy); GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_RemoveKey", godot_icall_Dictionary_RemoveKey); GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_Remove", godot_icall_Dictionary_Remove); GDMonoUtils::add_internal_call("Godot.Collections.Dictionary::godot_icall_Dictionary_TryGetValue", godot_icall_Dictionary_TryGetValue); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 02ec9ccd0651..1304008fe3a6 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -221,7 +221,7 @@ class VisualScriptEditorVariableEdit : public Object { Dictionary d = script->call("get_variable_info", var); if (String(p_name) == "type") { - Dictionary dc = d.duplicate(); + Dictionary dc = d.copy(); dc["type"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); @@ -246,7 +246,7 @@ class VisualScriptEditorVariableEdit : public Object { } if (String(p_name) == "hint") { - Dictionary dc = d.duplicate(); + Dictionary dc = d.copy(); dc["hint"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); @@ -258,7 +258,7 @@ class VisualScriptEditorVariableEdit : public Object { } if (String(p_name) == "hint_string") { - Dictionary dc = d.duplicate(); + Dictionary dc = d.copy(); dc["hint_string"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index b7313749d69a..21abefeae438 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2100,7 +2100,7 @@ Node *Node::_duplicate(int p_flags, Map *r_duplimap) const continue; } - Variant value = N->get()->get(name).duplicate(true); + Variant value = N->get()->get(name).copy(true); if (E->get().usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE) { Resource *res = Object::cast_to(value); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index ab8a4b793497..010459265431 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -242,7 +242,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { } } } else if (p_edit_state == GEN_EDIT_STATE_INSTANCE) { - value = value.duplicate(true); // Duplicate arrays and dictionaries for the editor + value = value.copy(true); // Copy arrays and dictionaries for the editor } node->set(snames[nprops[j].name], value, &valid); }