Use Dictionary.get_key_list where appropriate

This commit is contained in:
A Thousand Ships 2024-09-27 16:49:53 +02:00
parent b3bcb2dc14
commit 9ab9954fe7
No known key found for this signature in database
GPG Key ID: 2033189A662F8BD7
12 changed files with 51 additions and 44 deletions

View File

@ -467,9 +467,10 @@ void DependencyRemoveDialog::_find_localization_remaps_of_removed_files(Vector<R
p_removed.push_back(dep);
}
Array remap_keys = remaps.keys();
for (int j = 0; j < remap_keys.size(); j++) {
PackedStringArray remapped_files = remaps[remap_keys[j]];
List<Variant> remap_keys;
remaps.get_key_list(&remap_keys);
for (const Variant &remap_key : remap_keys) {
PackedStringArray remapped_files = remaps[remap_key];
for (int k = 0; k < remapped_files.size(); k++) {
int splitter_pos = remapped_files[k].rfind(":");
String res_path = remapped_files[k].substr(0, splitter_pos);
@ -477,7 +478,7 @@ void DependencyRemoveDialog::_find_localization_remaps_of_removed_files(Vector<R
String locale_name = remapped_files[k].substr(splitter_pos + 1);
RemovedDependency dep;
dep.file = vformat(TTR("Localization remap for path '%s' and locale '%s'."), remap_keys[j], locale_name);
dep.file = vformat(TTR("Localization remap for path '%s' and locale '%s'."), remap_key, locale_name);
dep.file_type = "";
dep.dependency = path;
dep.dependency_folder = files.value;

View File

@ -293,9 +293,9 @@ void EditorCommandPalette::register_shortcuts_as_command() {
// Load command use history.
Dictionary command_history = EditorSettings::get_singleton()->get_project_metadata("command_palette", "command_history", Dictionary());
Array history_entries = command_history.keys();
for (int i = 0; i < history_entries.size(); i++) {
const String &history_key = history_entries[i];
List<Variant> history_entries;
command_history.get_key_list(&history_entries);
for (const String history_key : history_entries) {
if (commands.has(history_key)) {
commands[history_key].last_used = command_history[history_key];
}

View File

@ -208,9 +208,9 @@ void EditorExportPreset::update_value_overrides() {
Dictionary plugin_overrides = export_plugins[i]->_get_export_options_overrides(platform);
if (!plugin_overrides.is_empty()) {
Array keys = plugin_overrides.keys();
for (int x = 0; x < keys.size(); x++) {
StringName key = keys[x];
List<Variant> keys;
plugin_overrides.get_key_list(&keys);
for (const StringName key : keys) {
Variant value = plugin_overrides[key];
if (new_value_overrides.has(key) && new_value_overrides[key] != value) {
WARN_PRINT_ED(vformat("Editor export plugin '%s' overrides pre-existing export option override '%s' with new value.", export_plugins[i]->get_name(), key));

View File

@ -2869,9 +2869,10 @@ Node *ResourceImporterScene::pre_import(const String &p_source_file, const HashM
}
Error ResourceImporterScene::_check_resource_save_paths(const Dictionary &p_data) {
Array keys = p_data.keys();
for (int i = 0; i < keys.size(); i++) {
const Dictionary &settings = p_data[keys[i]];
List<Variant> keys;
p_data.get_key_list(&keys);
for (const Variant &key : keys) {
const Dictionary &settings = p_data[key];
if (bool(settings.get("save_to_file/enabled", false)) && settings.has("save_to_file/path")) {
const String &save_path = settings["save_to_file/path"];

View File

@ -435,9 +435,10 @@ void LocalizationEditor::_filesystem_files_moved(const String &p_old_file, const
}
// Check for the Array elements of the values.
Array remap_keys = remaps.keys();
for (int i = 0; i < remap_keys.size(); i++) {
PackedStringArray remapped_files = remaps[remap_keys[i]];
List<Variant> remap_keys;
remaps.get_key_list(&remap_keys);
for (const Variant &remap_key : remap_keys) {
PackedStringArray remapped_files = remaps[remap_key];
bool remapped_files_updated = false;
for (int j = 0; j < remapped_files.size(); j++) {
@ -451,12 +452,12 @@ void LocalizationEditor::_filesystem_files_moved(const String &p_old_file, const
remapped_files.remove_at(j + 1);
remaps_changed = true;
remapped_files_updated = true;
print_verbose(vformat("Changed remap value \"%s\" to \"%s\" of key \"%s\" due to a moved file.", res_path + ":" + locale_name, remapped_files[j], remap_keys[i]));
print_verbose(vformat("Changed remap value \"%s\" to \"%s\" of key \"%s\" due to a moved file.", res_path + ":" + locale_name, remapped_files[j], remap_key));
}
}
if (remapped_files_updated) {
remaps[remap_keys[i]] = remapped_files;
remaps[remap_key] = remapped_files;
}
}

View File

@ -7869,7 +7869,8 @@ void Node3DEditor::_snap_selected_nodes_to_floor() {
PhysicsDirectSpaceState3D *ss = get_tree()->get_root()->get_world_3d()->get_direct_space_state();
PhysicsDirectSpaceState3D::RayResult result;
Array keys = snap_data.keys();
List<Variant> keys;
snap_data.get_key_list(&keys);
// The maximum height an object can travel to be snapped
const float max_snap_height = 500.0;
@ -7880,8 +7881,8 @@ void Node3DEditor::_snap_selected_nodes_to_floor() {
if (keys.size()) {
// For snapping to be performed, there must be solid geometry under at least one of the selected nodes.
// We need to check this before snapping to register the undo/redo action only if needed.
for (int i = 0; i < keys.size(); i++) {
Node *node = Object::cast_to<Node>(keys[i]);
for (const Variant &key : keys) {
Node *node = Object::cast_to<Node>(key);
Node3D *sp = Object::cast_to<Node3D>(node);
Dictionary d = snap_data[node];
Vector3 from = d["from"];
@ -7903,8 +7904,8 @@ void Node3DEditor::_snap_selected_nodes_to_floor() {
undo_redo->create_action(TTR("Snap Nodes to Floor"));
// Perform snapping if at least one node can be snapped
for (int i = 0; i < keys.size(); i++) {
Node *node = Object::cast_to<Node>(keys[i]);
for (const Variant &key : keys) {
Node *node = Object::cast_to<Node>(key);
Node3D *sp = Object::cast_to<Node3D>(node);
Dictionary d = snap_data[node];
Vector3 from = d["from"];

View File

@ -94,9 +94,9 @@ bpy.ops.export_scene.gltf(**opts['gltf_options'])
String dict_to_python(const Dictionary &p_dict) {
String entries;
Array dict_keys = p_dict.keys();
for (int i = 0; i < dict_keys.size(); i++) {
const String key = dict_keys[i];
List<Variant> dict_keys;
p_dict.get_key_list(&dict_keys);
for (const String key : dict_keys) {
String value;
Variant raw_value = p_dict[key];
@ -127,9 +127,9 @@ String dict_to_python(const Dictionary &p_dict) {
String dict_to_xmlrpc(const Dictionary &p_dict) {
String members;
Array dict_keys = p_dict.keys();
for (int i = 0; i < dict_keys.size(); i++) {
const String key = dict_keys[i];
List<Variant> dict_keys;
p_dict.get_key_list(&dict_keys);
for (const String key : dict_keys) {
String value;
Variant raw_value = p_dict[key];

View File

@ -85,9 +85,10 @@ static Dictionary to_dictionary(const HashMap<K, V> &p_inp) {
template <typename K, typename V>
static void set_from_dictionary(HashMap<K, V> &r_out, const Dictionary &p_inp) {
r_out.clear();
Array keys = p_inp.keys();
for (int i = 0; i < keys.size(); i++) {
r_out[keys[i]] = p_inp[keys[i]];
List<Variant> keys;
p_inp.get_key_list(&keys);
for (const Variant &key : keys) {
r_out[key] = p_inp[key];
}
}
} //namespace GLTFTemplateConvert

View File

@ -145,9 +145,10 @@ Dictionary GLTFSkin::get_joint_i_to_name() {
void GLTFSkin::set_joint_i_to_name(Dictionary p_joint_i_to_name) {
joint_i_to_name = HashMap<int, StringName>();
Array keys = p_joint_i_to_name.keys();
for (int i = 0; i < keys.size(); i++) {
joint_i_to_name[keys[i]] = p_joint_i_to_name[keys[i]];
List<Variant> keys;
p_joint_i_to_name.get_key_list(&keys);
for (const Variant &key : keys) {
joint_i_to_name[key] = p_joint_i_to_name[key];
}
}

View File

@ -55,9 +55,9 @@ void OpenXRSelectRuntime::_update_items() {
set_item_metadata(index, "");
index++;
Array keys = runtimes.keys();
for (int i = 0; i < keys.size(); i++) {
String key = keys[i];
List<Variant> keys;
runtimes.get_key_list(&keys);
for (const String key : keys) {
String path = runtimes[key];
String adj_path = path.replace("~", home_folder);

View File

@ -76,9 +76,9 @@ HashMap<String, bool *> OpenXRExtensionWrapperExtension::get_requested_extension
if (GDVIRTUAL_CALL(_get_requested_extensions, request_extension)) {
HashMap<String, bool *> result;
Array keys = request_extension.keys();
for (int i = 0; i < keys.size(); i++) {
String key = keys.get(i);
List<Variant> keys;
request_extension.get_key_list(&keys);
for (const String key : keys) {
GDExtensionPtr<bool> value = VariantCaster<GDExtensionPtr<bool>>::cast(request_extension.get(key, GDExtensionPtr<bool>(nullptr)));
result.insert(key, value);
}

View File

@ -1227,9 +1227,10 @@ void CodeEdit::add_auto_brace_completion_pair(const String &p_open_key, const St
void CodeEdit::set_auto_brace_completion_pairs(const Dictionary &p_auto_brace_completion_pairs) {
auto_brace_completion_pairs.clear();
Array keys = p_auto_brace_completion_pairs.keys();
for (int i = 0; i < keys.size(); i++) {
add_auto_brace_completion_pair(keys[i], p_auto_brace_completion_pairs[keys[i]]);
List<Variant> keys;
p_auto_brace_completion_pairs.get_key_list(&keys);
for (const Variant &key : keys) {
add_auto_brace_completion_pair(key, p_auto_brace_completion_pairs[key]);
}
}