summaryrefslogtreecommitdiff
path: root/scene/resources/resource_format_text.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-05-14 16:41:43 +0200
committerRémi Verschelde <rverschelde@gmail.com>2020-05-14 21:57:34 +0200
commit0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (patch)
tree198d4ff7665d89307f6ca2469fa38620a9eb1672 /scene/resources/resource_format_text.cpp
parent07bc4e2f96f8f47991339654ff4ab16acc19d44f (diff)
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
Diffstat (limited to 'scene/resources/resource_format_text.cpp')
-rw-r--r--scene/resources/resource_format_text.cpp78
1 files changed, 51 insertions, 27 deletions
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index f758427bd6..93db8b725f 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -253,8 +253,9 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
if (next_tag.fields.has("owner")) {
owner = packed_scene->get_state()->add_node_path(next_tag.fields["owner"]);
} else {
- if (parent != -1 && !(type == SceneState::TYPE_INSTANCED && instance == -1))
+ if (parent != -1 && !(type == SceneState::TYPE_INSTANCED && instance == -1)) {
owner = 0; //if no owner, owner is root
+ }
}
if (next_tag.fields.has("index")) {
@@ -391,8 +392,9 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars
}
Error ResourceLoaderText::load() {
- if (error != OK)
+ if (error != OK) {
return error;
+ }
while (true) {
if (next_tag.name != "ext_resource") {
@@ -659,8 +661,9 @@ Error ResourceLoaderText::load() {
Ref<PackedScene> packed_scene = _parse_node_tag(rp);
- if (!packed_scene.is_valid())
+ if (!packed_scene.is_valid()) {
return error;
+ }
error = OK;
//get it here
@@ -784,8 +787,9 @@ Error ResourceLoaderText::rename_dependencies(FileAccess *p_f, const String &p_p
if (next_tag.name != "ext_resource") {
//nothing was done
- if (!fw)
+ if (!fw) {
return OK;
+ }
break;
@@ -939,8 +943,9 @@ static void bs_save_unicode_string(FileAccess *f, const String &p_string, bool p
}
Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) {
- if (error)
+ if (error) {
return error;
+ }
FileAccessRef wf = FileAccess::open(p_path, FileAccess::WRITE);
if (!wf) {
@@ -960,8 +965,9 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
bs_save_unicode_string(wf.f, is_scene ? "PackedScene" : resource_type);
wf->store_64(0); //offset to import metadata, this is no longer used
- for (int i = 0; i < 14; i++)
+ for (int i = 0; i < 14; i++) {
wf->store_32(0); // reserved
+ }
wf->store_32(0); //string table size, will not be in use
size_t ext_res_count_pos = wf->get_position();
@@ -1130,8 +1136,9 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
Ref<PackedScene> packed_scene = _parse_node_tag(rp);
- if (!packed_scene.is_valid())
+ if (!packed_scene.is_valid()) {
return error;
+ }
error = OK;
//get it here
@@ -1150,8 +1157,9 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path)
int prop_count = 0;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
- if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
+ if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
+ }
String name = E->get().name;
Variant value = packed_scene->get(name);
@@ -1221,11 +1229,13 @@ String ResourceLoaderText::recognize(FileAccess *p_f) {
}
}
- if (tag.name == "gd_scene")
+ if (tag.name == "gd_scene") {
return "PackedScene";
+ }
- if (tag.name != "gd_resource")
+ if (tag.name != "gd_resource") {
return "";
+ }
if (!tag.fields.has("type")) {
error_text = "Missing 'type' field in 'gd_resource' tag";
@@ -1239,8 +1249,9 @@ String ResourceLoaderText::recognize(FileAccess *p_f) {
/////////////////////
RES ResourceFormatLoaderText::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
- if (r_error)
+ if (r_error) {
*r_error = ERR_CANT_OPEN;
+ }
Error err;
@@ -1274,10 +1285,11 @@ void ResourceFormatLoaderText::get_recognized_extensions_for_type(const String &
return;
}
- if (p_type == "PackedScene")
+ if (p_type == "PackedScene") {
p_extensions->push_back("tscn");
- else
+ } else {
p_extensions->push_back("tres");
+ }
}
void ResourceFormatLoaderText::get_recognized_extensions(List<String> *p_extensions) const {
@@ -1291,10 +1303,11 @@ bool ResourceFormatLoaderText::handles_type(const String &p_type) const {
String ResourceFormatLoaderText::get_resource_type(const String &p_path) const {
String ext = p_path.get_extension().to_lower();
- if (ext == "tscn")
+ if (ext == "tscn") {
return "PackedScene";
- else if (ext != "tres")
+ } else if (ext != "tres") {
return String();
+ }
//for anyhting else must test..
@@ -1395,8 +1408,9 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant,
case Variant::OBJECT: {
RES res = p_variant;
- if (res.is_null() || external_resources.has(res))
+ if (res.is_null() || external_resources.has(res)) {
return;
+ }
if (!p_main && (!bundle_resources) && res->get_path().length() && res->get_path().find("::") == -1) {
if (res->get_path() == local_path) {
@@ -1408,8 +1422,9 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant,
return;
}
- if (resource_set.has(res))
+ if (resource_set.has(res)) {
return;
+ }
List<PropertyInfo> property_list;
@@ -1495,8 +1510,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
if (packed_scene.is_valid()) {
//add instances to external resources if saving a packed scene
for (int i = 0; i < packed_scene->get_state()->get_node_count(); i++) {
- if (packed_scene->get_state()->is_node_instance_placeholder(i))
+ if (packed_scene->get_state()->is_node_instance_placeholder(i)) {
continue;
+ }
Ref<PackedScene> instance = packed_scene->get_state()->get_node_instance(i);
if (instance.is_valid() && !external_resources.has(instance)) {
@@ -1508,8 +1524,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
{
String title = packed_scene.is_valid() ? "[gd_scene " : "[gd_resource ";
- if (packed_scene.is_null())
+ if (packed_scene.is_null()) {
title += "type=\"" + p_resource->get_class() + "\" ";
+ }
int load_steps = saved_resources.size() + external_resources.size();
/*
if (packed_scene.is_valid()) {
@@ -1580,8 +1597,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
f->store_string("[ext_resource path=\"" + p + "\" type=\"" + sorted_er[i].resource->get_save_class() + "\" id=" + itos(sorted_er[i].index) + "]\n"); //bundled
}
- if (external_resources.size())
+ if (external_resources.size()) {
f->store_line(String()); //separate
+ }
Set<int> used_indices;
@@ -1603,8 +1621,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
ERR_CONTINUE(!resource_set.has(res));
bool main = (E->next() == nullptr);
- if (main && packed_scene.is_valid())
+ if (main && packed_scene.is_valid()) {
break; //save as a scene
+ }
if (main) {
f->store_line("[resource]");
@@ -1637,8 +1656,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
res->get_property_list(&property_list);
//property_list.sort();
for (List<PropertyInfo>::Element *PE = property_list.front(); PE; PE = PE->next()) {
- if (skip_editor && PE->get().name.begins_with("__editor"))
+ if (skip_editor && PE->get().name.begins_with("__editor")) {
continue;
+ }
if (PE->get().usage & PROPERTY_USAGE_STORAGE) {
String name = PE->get().name;
@@ -1659,8 +1679,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
continue;
}
- if (PE->get().type == Variant::OBJECT && value.is_zero() && !(PE->get().usage & PROPERTY_USAGE_STORE_IF_NULL))
+ if (PE->get().type == Variant::OBJECT && value.is_zero() && !(PE->get().usage & PROPERTY_USAGE_STORE_IF_NULL)) {
continue;
+ }
String vars;
VariantWriter::write_to_string(value, vars, _write_resources, this);
@@ -1668,8 +1689,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
}
}
- if (E->next())
+ if (E->next()) {
f->store_line(String());
+ }
}
if (packed_scene.is_valid()) {
@@ -1735,8 +1757,9 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
f->store_string(String(state->get_node_property_name(i, j)).property_name_encode() + " = " + vars + "\n");
}
- if (i < state->get_node_count() - 1)
+ if (i < state->get_node_count() - 1) {
f->store_line(String());
+ }
}
for (int i = 0; i < state->get_connection_count(); i++) {
@@ -1792,10 +1815,11 @@ bool ResourceFormatSaverText::recognize(const RES &p_resource) const {
}
void ResourceFormatSaverText::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
- if (p_resource->get_class() == "PackedScene")
+ if (p_resource->get_class() == "PackedScene") {
p_extensions->push_back("tscn"); //text scene
- else
+ } else {
p_extensions->push_back("tres"); //text resource
+ }
}
ResourceFormatSaverText *ResourceFormatSaverText::singleton = nullptr;