1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-05 12:10:55 +00:00

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
2020-05-14 16:41:43 +02:00
parent 07bc4e2f96
commit 0ee0fa42e6
683 changed files with 22803 additions and 12225 deletions

View File

@@ -153,8 +153,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();
@@ -292,8 +293,9 @@ void SpriteFramesEditor::_load_pressed() {
file->clear_filters();
List<String> extensions;
ResourceLoader::get_recognized_extensions_for_type("Texture2D", &extensions);
for (int i = 0; i < extensions.size(); i++)
for (int i = 0; i < extensions.size(); i++) {
file->add_filter("*." + extensions[i]);
}
file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES);
@@ -324,8 +326,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<Texture2D> r = frames->get_frame(edited_anim, tree->get_current());
if (!r.is_valid()) {
return;
@@ -383,12 +386,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;
@@ -406,12 +411,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;
@@ -429,8 +436,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)) {
@@ -446,13 +454,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();
@@ -463,10 +473,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;
}
{
AnimatedSprite2D *as = Object::cast_to<AnimatedSprite2D>(p_node);
@@ -488,20 +500,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(",", " ");
@@ -563,11 +579,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();
@@ -593,8 +611,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());
@@ -605,8 +624,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);
@@ -654,10 +674,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;
@@ -672,10 +693,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));
@@ -686,8 +709,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;
@@ -710,18 +734,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'
@@ -731,12 +758,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"];
@@ -751,8 +780,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];
@@ -769,13 +799,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);
@@ -786,13 +818,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);
@@ -1060,8 +1094,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();
}
}
}