Merge pull request #14754 from willnationsdev/dictionary-copy

Added 'duplicate' function for Dictionary in C++ and API.
This commit is contained in:
Rémi Verschelde 2017-12-17 23:58:59 +01:00 committed by GitHub
commit e83c502939
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 10 deletions

View file

@ -215,7 +215,7 @@ const Variant *Dictionary::next(const Variant *p_key) const {
return NULL; return NULL;
} }
Dictionary Dictionary::copy() const { Dictionary Dictionary::duplicate() const {
Dictionary n; Dictionary n;

View file

@ -74,7 +74,7 @@ public:
Array keys() const; Array keys() const;
Array values() const; Array values() const;
Dictionary copy() const; Dictionary duplicate() const;
Dictionary(const Dictionary &p_from); Dictionary(const Dictionary &p_from);
Dictionary(); Dictionary();

View file

@ -462,6 +462,7 @@ struct _VariantCall {
VCALL_LOCALMEM0R(Dictionary, hash); VCALL_LOCALMEM0R(Dictionary, hash);
VCALL_LOCALMEM0R(Dictionary, keys); VCALL_LOCALMEM0R(Dictionary, keys);
VCALL_LOCALMEM0R(Dictionary, values); VCALL_LOCALMEM0R(Dictionary, values);
VCALL_LOCALMEM0R(Dictionary, duplicate);
VCALL_LOCALMEM2(Array, set); VCALL_LOCALMEM2(Array, set);
VCALL_LOCALMEM1R(Array, get); VCALL_LOCALMEM1R(Array, get);
@ -1607,6 +1608,7 @@ void register_variant_methods() {
ADDFUNC0R(DICTIONARY, INT, Dictionary, hash, varray()); ADDFUNC0R(DICTIONARY, INT, Dictionary, hash, varray());
ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, keys, varray()); ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, keys, varray());
ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, values, varray()); ADDFUNC0R(DICTIONARY, ARRAY, Dictionary, values, varray());
ADDFUNC0R(DICTIONARY, DICTIONARY, Dictionary, duplicate, varray());
ADDFUNC0R(ARRAY, INT, Array, size, varray()); ADDFUNC0R(ARRAY, INT, Array, size, varray());
ADDFUNC0R(ARRAY, BOOL, Array, empty, varray()); ADDFUNC0R(ARRAY, BOOL, Array, empty, varray());

View file

@ -1348,14 +1348,14 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() {
if (SpatialEditor::get_singleton()->is_visible()) { if (SpatialEditor::get_singleton()->is_visible()) {
// 3D // 3D
spatial_edit_state = SpatialEditor::get_singleton()->get_state(); spatial_edit_state = SpatialEditor::get_singleton()->get_state();
Dictionary new_state = spatial_edit_state.copy(); Dictionary new_state = spatial_edit_state.duplicate();
new_state["show_grid"] = false; new_state["show_grid"] = false;
new_state["show_origin"] = false; new_state["show_origin"] = false;
Array orig_vp = spatial_edit_state["viewports"]; Array orig_vp = spatial_edit_state["viewports"];
Array vp; Array vp;
vp.resize(4); vp.resize(4);
for (int i = 0; i < vp.size(); i++) { for (int i = 0; i < vp.size(); i++) {
Dictionary d = ((Dictionary)orig_vp[i]).copy(); Dictionary d = ((Dictionary)orig_vp[i]).duplicate();
d["use_environment"] = false; d["use_environment"] = false;
d["doppler"] = false; d["doppler"] = false;
d["gizmos"] = onion.include_gizmos ? d["gizmos"] : Variant(false); d["gizmos"] = onion.include_gizmos ? d["gizmos"] : Variant(false);
@ -1368,7 +1368,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() {
} else { // CanvasItemEditor } else { // CanvasItemEditor
// 2D // 2D
canvas_edit_state = CanvasItemEditor::get_singleton()->get_state(); canvas_edit_state = CanvasItemEditor::get_singleton()->get_state();
Dictionary new_state = canvas_edit_state.copy(); Dictionary new_state = canvas_edit_state.duplicate();
new_state["show_grid"] = false; new_state["show_grid"] = false;
new_state["show_rulers"] = false; new_state["show_rulers"] = false;
new_state["show_guides"] = false; new_state["show_guides"] = false;

View file

@ -228,7 +228,7 @@ protected:
if (String(p_name) == "type") { if (String(p_name) == "type") {
Dictionary dc = d.copy(); Dictionary dc = d.duplicate();
dc["type"] = p_value; dc["type"] = p_value;
undo_redo->create_action(TTR("Set Variable Type")); undo_redo->create_action(TTR("Set Variable Type"));
undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc);
@ -241,7 +241,7 @@ protected:
if (String(p_name) == "hint") { if (String(p_name) == "hint") {
Dictionary dc = d.copy(); Dictionary dc = d.duplicate();
dc["hint"] = p_value; dc["hint"] = p_value;
undo_redo->create_action(TTR("Set Variable Type")); undo_redo->create_action(TTR("Set Variable Type"));
undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc);
@ -254,7 +254,7 @@ protected:
if (String(p_name) == "hint_string") { if (String(p_name) == "hint_string") {
Dictionary dc = d.copy(); Dictionary dc = d.duplicate();
dc["hint_string"] = p_value; dc["hint_string"] = p_value;
undo_redo->create_action(TTR("Set Variable Type")); undo_redo->create_action(TTR("Set Variable Type"));
undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc);

View file

@ -2162,7 +2162,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const
Variant value = N->get()->get(name); Variant value = N->get()->get(name);
// Duplicate dictionaries and arrays, mainly needed for __meta__ // Duplicate dictionaries and arrays, mainly needed for __meta__
if (value.get_type() == Variant::DICTIONARY) { if (value.get_type() == Variant::DICTIONARY) {
value = Dictionary(value).copy(); value = Dictionary(value).duplicate();
} else if (value.get_type() == Variant::ARRAY) { } else if (value.get_type() == Variant::ARRAY) {
value = Array(value).duplicate(); value = Array(value).duplicate();
} }
@ -2303,7 +2303,7 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p
Variant value = get(name); Variant value = get(name);
// Duplicate dictionaries and arrays, mainly needed for __meta__ // Duplicate dictionaries and arrays, mainly needed for __meta__
if (value.get_type() == Variant::DICTIONARY) { if (value.get_type() == Variant::DICTIONARY) {
value = Dictionary(value).copy(); value = Dictionary(value).duplicate();
} else if (value.get_type() == Variant::ARRAY) { } else if (value.get_type() == Variant::ARRAY) {
value = Array(value).duplicate(); value = Array(value).duplicate();
} }