Skip to content

Commit

Permalink
Write node groups one a single line when saving a .tscn file
Browse files Browse the repository at this point in the history
This makes `.tscn` files more readable by ensuring sections are always
written on a single line.
  • Loading branch information
Calinou committed Aug 31, 2021
1 parent a9fcbb1 commit d33a736
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions scene/resources/resource_format_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1849,10 +1849,16 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
}

if (groups.size()) {
// Write all groups on the same line as they're part of a section header.
// This improves readability while not impacting VCS friendliness too much,
// since it's rare to have more than 5 groups assigned to a single node.
groups.sort_custom<StringName::AlphCompare>();
String sgroups = " groups=[\n";
String sgroups = " groups=[";
for (int j = 0; j < groups.size(); j++) {
sgroups += "\"" + String(groups[j]).c_escape() + "\",\n";
sgroups += "\"" + String(groups[j]).c_escape() + "\"";
if (j < groups.size() - 1) {
sgroups += ", ";
}
}
sgroups += "]";
header += sgroups;
Expand Down

0 comments on commit d33a736

Please sign in to comment.