Style: Enforce braces around if blocks and loops

Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
This commit is contained in:
Rémi Verschelde 2021-05-05 12:44:11 +02:00
parent b8d198eeed
commit 140350d767
No known key found for this signature in database
GPG key ID: C3336907360768E1
694 changed files with 23283 additions and 12499 deletions

View file

@ -154,8 +154,9 @@ void SpriteFramesEditor::_sheet_add_frames() {
Rect2 region_rect = Rect2();
if (atlas_source && atlas_source->get_atlas().is_valid())
if (atlas_source && atlas_source->get_atlas().is_valid()) {
region_rect = atlas_source->get_region();
}
for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) {
int idx = E->get();
@ -293,8 +294,9 @@ void SpriteFramesEditor::_load_pressed() {
file->clear_filters();
List<String> extensions;
ResourceLoader::get_recognized_extensions_for_type("Texture", &extensions);
for (int i = 0; i < extensions.size(); i++)
for (int i = 0; i < extensions.size(); i++) {
file->add_filter("*." + extensions[i]);
}
file->set_mode(EditorFileDialog::MODE_OPEN_FILES);
@ -325,8 +327,9 @@ void SpriteFramesEditor::_paste_pressed() {
void SpriteFramesEditor::_copy_pressed() {
ERR_FAIL_COND(!frames->has_animation(edited_anim));
if (tree->get_current() < 0)
if (tree->get_current() < 0) {
return;
}
Ref<Texture> r = frames->get_frame(edited_anim, tree->get_current());
if (!r.is_valid()) {
return;
@ -384,12 +387,14 @@ void SpriteFramesEditor::_empty2_pressed() {
void SpriteFramesEditor::_up_pressed() {
ERR_FAIL_COND(!frames->has_animation(edited_anim));
if (tree->get_current() < 0)
if (tree->get_current() < 0) {
return;
}
int to_move = tree->get_current();
if (to_move < 1)
if (to_move < 1) {
return;
}
sel = to_move;
sel -= 1;
@ -407,12 +412,14 @@ void SpriteFramesEditor::_up_pressed() {
void SpriteFramesEditor::_down_pressed() {
ERR_FAIL_COND(!frames->has_animation(edited_anim));
if (tree->get_current() < 0)
if (tree->get_current() < 0) {
return;
}
int to_move = tree->get_current();
if (to_move < 0 || to_move >= frames->get_frame_count(edited_anim) - 1)
if (to_move < 0 || to_move >= frames->get_frame_count(edited_anim) - 1) {
return;
}
sel = to_move;
sel += 1;
@ -430,8 +437,9 @@ void SpriteFramesEditor::_down_pressed() {
void SpriteFramesEditor::_delete_pressed() {
ERR_FAIL_COND(!frames->has_animation(edited_anim));
if (tree->get_current() < 0)
if (tree->get_current() < 0) {
return;
}
int to_delete = tree->get_current();
if (to_delete < 0 || to_delete >= frames->get_frame_count(edited_anim)) {
@ -447,13 +455,15 @@ void SpriteFramesEditor::_delete_pressed() {
}
void SpriteFramesEditor::_animation_select() {
if (updating)
if (updating) {
return;
}
if (frames->has_animation(edited_anim)) {
double value = anim_speed->get_line_edit()->get_text().to_double();
if (!Math::is_equal_approx(value, frames->get_animation_speed(edited_anim)))
if (!Math::is_equal_approx(value, frames->get_animation_speed(edited_anim))) {
_animation_fps_changed(value);
}
}
TreeItem *selected = animations->get_selected();
@ -464,10 +474,12 @@ void SpriteFramesEditor::_animation_select() {
static void _find_anim_sprites(Node *p_node, List<Node *> *r_nodes, Ref<SpriteFrames> p_sfames) {
Node *edited = EditorNode::get_singleton()->get_edited_scene();
if (!edited)
if (!edited) {
return;
if (p_node != edited && p_node->get_owner() != edited)
}
if (p_node != edited && p_node->get_owner() != edited) {
return;
}
{
AnimatedSprite *as = Object::cast_to<AnimatedSprite>(p_node);
@ -489,20 +501,24 @@ static void _find_anim_sprites(Node *p_node, List<Node *> *r_nodes, Ref<SpriteFr
}
void SpriteFramesEditor::_animation_name_edited() {
if (updating)
if (updating) {
return;
}
if (!frames->has_animation(edited_anim))
if (!frames->has_animation(edited_anim)) {
return;
}
TreeItem *edited = animations->get_edited();
if (!edited)
if (!edited) {
return;
}
String new_name = edited->get_text(0);
if (new_name == String(edited_anim))
if (new_name == String(edited_anim)) {
return;
}
new_name = new_name.replace("/", "_").replace(",", " ");
@ -564,11 +580,13 @@ void SpriteFramesEditor::_animation_add() {
}
void SpriteFramesEditor::_animation_remove() {
if (updating)
if (updating) {
return;
}
if (!frames->has_animation(edited_anim))
if (!frames->has_animation(edited_anim)) {
return;
}
delete_dialog->set_text(TTR("Delete Animation?"));
delete_dialog->popup_centered_minsize();
@ -594,8 +612,9 @@ void SpriteFramesEditor::_animation_remove_confirmed() {
}
void SpriteFramesEditor::_animation_loop_changed() {
if (updating)
if (updating) {
return;
}
undo_redo->create_action(TTR("Change Animation Loop"));
undo_redo->add_do_method(frames, "set_animation_loop", edited_anim, anim_loop->is_pressed());
@ -606,8 +625,9 @@ void SpriteFramesEditor::_animation_loop_changed() {
}
void SpriteFramesEditor::_animation_fps_changed(double p_value) {
if (updating)
if (updating) {
return;
}
undo_redo->create_action(TTR("Change Animation FPS"), UndoRedo::MERGE_ENDS);
undo_redo->add_do_method(frames, "set_animation_speed", edited_anim, p_value);
@ -655,10 +675,11 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) {
return;
}
if (sel >= frames->get_frame_count(edited_anim))
if (sel >= frames->get_frame_count(edited_anim)) {
sel = frames->get_frame_count(edited_anim) - 1;
else if (sel < 0 && frames->get_frame_count(edited_anim))
} else if (sel < 0 && frames->get_frame_count(edited_anim)) {
sel = 0;
}
for (int i = 0; i < frames->get_frame_count(edited_anim); i++) {
String name;
@ -673,10 +694,12 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) {
}
tree->add_item(name, icon);
if (frames->get_frame(edited_anim, i).is_valid())
if (frames->get_frame(edited_anim, i).is_valid()) {
tree->set_item_tooltip(tree->get_item_count() - 1, frames->get_frame(edited_anim, i)->get_path());
if (sel == i)
}
if (sel == i) {
tree->select(tree->get_item_count() - 1);
}
}
anim_speed->set_value(frames->get_animation_speed(edited_anim));
@ -687,8 +710,9 @@ void SpriteFramesEditor::_update_library(bool p_skip_selector) {
}
void SpriteFramesEditor::edit(SpriteFrames *p_frames) {
if (frames == p_frames)
if (frames == p_frames) {
return;
}
frames = p_frames;
@ -711,18 +735,21 @@ void SpriteFramesEditor::edit(SpriteFrames *p_frames) {
}
Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
if (!frames->has_animation(edited_anim))
if (!frames->has_animation(edited_anim)) {
return false;
}
int idx = tree->get_item_at_position(p_point, true);
if (idx < 0 || idx >= frames->get_frame_count(edited_anim))
if (idx < 0 || idx >= frames->get_frame_count(edited_anim)) {
return Variant();
}
RES frame = frames->get_frame(edited_anim, idx);
if (frame.is_null())
if (frame.is_null()) {
return Variant();
}
Dictionary drag_data = EditorNode::get_singleton()->drag_resource(frame, p_from);
drag_data["frame"] = idx; // store the frame, in case we want to reorder frames inside 'drop_data_fw'
@ -732,12 +759,14 @@ Variant SpriteFramesEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f
bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
Dictionary d = p_data;
if (!d.has("type"))
if (!d.has("type")) {
return false;
}
// reordering frames
if (d.has("from") && (Object *)(d["from"]) == tree)
if (d.has("from") && (Object *)(d["from"]) == tree) {
return true;
}
if (String(d["type"]) == "resource" && d.has("resource")) {
RES r = d["resource"];
@ -752,8 +781,9 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
if (String(d["type"]) == "files") {
Vector<String> files = d["files"];
if (files.size() == 0)
if (files.size() == 0) {
return false;
}
for (int i = 0; i < files.size(); i++) {
String file = files[i];
@ -770,13 +800,15 @@ bool SpriteFramesEditor::can_drop_data_fw(const Point2 &p_point, const Variant &
}
void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
if (!can_drop_data_fw(p_point, p_data, p_from))
if (!can_drop_data_fw(p_point, p_data, p_from)) {
return;
}
Dictionary d = p_data;
if (!d.has("type"))
if (!d.has("type")) {
return;
}
int at_pos = tree->get_item_at_position(p_point, true);
@ -787,13 +819,15 @@ void SpriteFramesEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
if (texture.is_valid()) {
bool reorder = false;
if (d.has("from") && (Object *)(d["from"]) == tree)
if (d.has("from") && (Object *)(d["from"]) == tree) {
reorder = true;
}
if (reorder) { //drop is from reordering frames
int from_frame = -1;
if (d.has("frame"))
if (d.has("frame")) {
from_frame = d["frame"];
}
undo_redo->create_action(TTR("Move Frame"));
undo_redo->add_do_method(frames, "remove_frame", edited_anim, from_frame == -1 ? frames->get_frame_count(edited_anim) : from_frame);
@ -1085,8 +1119,9 @@ void SpriteFramesEditorPlugin::make_visible(bool p_visible) {
editor->make_bottom_panel_item_visible(frames_editor);
} else {
button->hide();
if (frames_editor->is_visible_in_tree())
if (frames_editor->is_visible_in_tree()) {
editor->hide_bottom_panel();
}
}
}